@@ -11,6 +11,7 @@ import (
11
11
"github.com/0xJacky/Nginx-UI/internal/nginx"
12
12
"github.com/0xJacky/Nginx-UI/settings"
13
13
"github.com/uozi-tech/cosy"
14
+ "github.com/uozi-tech/cosy/logger"
14
15
cosysettings "github.com/uozi-tech/cosy/settings"
15
16
)
16
17
@@ -239,20 +240,24 @@ func extractZipFile(file *zip.File, destDir string) error {
239
240
return nil
240
241
}
241
242
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 )
246
249
return nil
247
250
}
248
251
249
252
// For relative symlinks, verify they don't escape the destination directory
250
253
absLinkTarget := filepath .Clean (filepath .Join (filepath .Dir (filePath ), cleanLinkTarget ))
251
254
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 )
256
261
return nil
257
262
}
258
263
0 commit comments