@@ -436,19 +436,14 @@ func isAllowedDir(path string, allowedDirs []string) bool {
436436 slog .Debug ("File path detected, checking parent directory is allowed" , "path" , directoryPath )
437437 }
438438
439- fInfo , err := os .Stat (directoryPath )
440- if err != nil {
441- slog .Warn ("Path error" , "path" , path , "error" , err )
439+ fInfo , statErr := os .Stat (directoryPath )
440+ if statErr != nil {
441+ slog .Warn ("Stat: Path error" , "path" , path , "error" , statErr )
442442 }
443443
444444 if fInfo != nil {
445- //check if it contains a symlink
446- lInfo , err := os .Lstat (directoryPath )
447- if err != nil {
448- slog .Warn ("Lstat error" , "path" , path , "error" , err )
449- }
450- if lInfo != nil && lInfo .Mode ()& os .ModeSymlink != 0 {
451- slog .Warn ("Path is a symlink, not allowed" , "path" , path )
445+ if isSymlink (directoryPath ) {
446+ slog .Warn ("Path is a symlink, skipping allowed directory check" , "path" , directoryPath )
452447 return false
453448 }
454449 }
@@ -463,3 +458,17 @@ func isAllowedDir(path string, allowedDirs []string) bool {
463458
464459 return false
465460}
461+
462+ func isSymlink (path string ) bool {
463+ // check if it contains a symlink
464+ lInfo , err := os .Lstat (path )
465+ if err != nil {
466+ slog .Warn ("Lstat error" , "path" , path , "error" , err )
467+ return false
468+ }
469+ if lInfo != nil && lInfo .Mode ()& os .ModeSymlink != 0 {
470+ slog .Warn ("Path is a symlink" , "path" , path )
471+ return true
472+ }
473+ return false
474+ }
0 commit comments