Skip to content

Commit 29b83da

Browse files
committed
fix(restore): skipping symlinks outside allowed paths during restore #1371
1 parent e71293c commit 29b83da

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed

app/components.d.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ declare module 'vue' {
3232
AInput: typeof import('ant-design-vue/es')['Input']
3333
AInputGroup: typeof import('ant-design-vue/es')['InputGroup']
3434
AInputNumber: typeof import('ant-design-vue/es')['InputNumber']
35+
AInputPassword: typeof import('ant-design-vue/es')['InputPassword']
3536
ALayout: typeof import('ant-design-vue/es')['Layout']
3637
ALayoutContent: typeof import('ant-design-vue/es')['LayoutContent']
3738
ALayoutFooter: typeof import('ant-design-vue/es')['LayoutFooter']
@@ -48,12 +49,16 @@ declare module 'vue' {
4849
APopover: typeof import('ant-design-vue/es')['Popover']
4950
AppProviderAppProvider: typeof import('./src/components/AppProvider/AppProvider.vue')['default']
5051
AProgress: typeof import('ant-design-vue/es')['Progress']
52+
AQrcode: typeof import('ant-design-vue/es')['QRCode']
53+
ARangePicker: typeof import('ant-design-vue/es')['RangePicker']
5154
AResult: typeof import('ant-design-vue/es')['Result']
5255
ARow: typeof import('ant-design-vue/es')['Row']
56+
ASegmented: typeof import('ant-design-vue/es')['Segmented']
5357
ASelect: typeof import('ant-design-vue/es')['Select']
5458
ASelectOption: typeof import('ant-design-vue/es')['SelectOption']
5559
ASpace: typeof import('ant-design-vue/es')['Space']
5660
ASpin: typeof import('ant-design-vue/es')['Spin']
61+
AStatistic: typeof import('ant-design-vue/es')['Statistic']
5762
AStep: typeof import('ant-design-vue/es')['Step']
5863
ASteps: typeof import('ant-design-vue/es')['Steps']
5964
ASubMenu: typeof import('ant-design-vue/es')['SubMenu']
@@ -64,6 +69,8 @@ declare module 'vue' {
6469
ATag: typeof import('ant-design-vue/es')['Tag']
6570
ATextarea: typeof import('ant-design-vue/es')['Textarea']
6671
ATooltip: typeof import('ant-design-vue/es')['Tooltip']
72+
ATypographyText: typeof import('ant-design-vue/es')['TypographyText']
73+
ATypographyTitle: typeof import('ant-design-vue/es')['TypographyTitle']
6774
AutoCertFormAutoCertForm: typeof import('./src/components/AutoCertForm/AutoCertForm.vue')['default']
6875
AutoCertFormDNSChallenge: typeof import('./src/components/AutoCertForm/DNSChallenge.vue')['default']
6976
BaseEditorBaseEditor: typeof import('./src/components/BaseEditor/BaseEditor.vue')['default']

internal/backup/restore.go

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"github.com/0xJacky/Nginx-UI/internal/nginx"
1212
"github.com/0xJacky/Nginx-UI/settings"
1313
"github.com/uozi-tech/cosy"
14+
"github.com/uozi-tech/cosy/logger"
1415
cosysettings "github.com/uozi-tech/cosy/settings"
1516
)
1617

@@ -239,20 +240,24 @@ func extractZipFile(file *zip.File, destDir string) error {
239240
return nil
240241
}
241242

242-
// Otherwise, fallback to creating a directory
243-
if err := os.MkdirAll(filePath, 0755); err != nil {
244-
return cosy.WrapErrorWithParams(ErrCreateDir, fmt.Sprintf("failed to create directory %s: %v", filePath, err))
245-
}
243+
// Skip symlinks that point to paths outside the allowed directories
244+
logger.Warn("Skipping symlink outside allowed paths during restore",
245+
"path", filePath,
246+
"target", cleanLinkTarget,
247+
"allowedConfPath", confPath,
248+
"allowedModulesPath", modulesPath)
246249
return nil
247250
}
248251

249252
// For relative symlinks, verify they don't escape the destination directory
250253
absLinkTarget := filepath.Clean(filepath.Join(filepath.Dir(filePath), cleanLinkTarget))
251254
if !strings.HasPrefix(absLinkTarget, destDirAbs+string(os.PathSeparator)) {
252-
// Create directory instead of symlink if the target is outside destination
253-
if err := os.MkdirAll(filePath, 0755); err != nil {
254-
return cosy.WrapErrorWithParams(ErrCreateDir, fmt.Sprintf("failed to create directory %s: %v", filePath, err))
255-
}
255+
// Skip relative symlinks that point outside the destination directory
256+
logger.Warn("Skipping relative symlink pointing outside destination directory during restore",
257+
"path", filePath,
258+
"target", cleanLinkTarget,
259+
"resolvedTarget", absLinkTarget,
260+
"destinationDir", destDirAbs)
256261
return nil
257262
}
258263

0 commit comments

Comments
 (0)