@@ -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"
1415cosysettings "github.com/uozi-tech/cosy/settings"
1516)
1617
@@ -239,20 +240,24 @@ func extractZipFile(file *zip.File, destDir string) error {
239240return 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 )
246249return nil
247250}
248251
249252// For relative symlinks, verify they don't escape the destination directory
250253absLinkTarget := filepath .Clean (filepath .Join (filepath .Dir (filePath ), cleanLinkTarget ))
251254if ! 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 )
256261return nil
257262}
258263
0 commit comments