@@ -37,6 +37,7 @@ var log = logger.New("fileutil:fileutil")
3737func ValidateAbsolutePath (path string ) (string , error ) {
3838 // Check for empty path
3939 if path == "" {
40+ log .Print ("ValidateAbsolutePath: rejected empty path" )
4041 return "" , errors .New ("path cannot be empty" )
4142 }
4243
@@ -45,9 +46,11 @@ func ValidateAbsolutePath(path string) (string, error) {
4546
4647 // Verify the path is absolute to prevent relative path traversal
4748 if ! filepath .IsAbs (cleanPath ) {
49+ log .Printf ("ValidateAbsolutePath: rejected relative path: %s" , path )
4850 return "" , fmt .Errorf ("path must be absolute, got: %s" , path )
4951 }
5052
53+ log .Printf ("ValidateAbsolutePath: validated path: %s" , cleanPath )
5154 return cleanPath , nil
5255}
5356
@@ -60,6 +63,7 @@ func ValidateAbsolutePath(path string) (string, error) {
6063// - Either path cannot be resolved to an absolute form.
6164// - The resolved candidate path starts outside the resolved base directory.
6265func MustBeWithin (base , candidate string ) error {
66+ log .Printf ("MustBeWithin: checking candidate=%q within base=%q" , candidate , base )
6367 // EvalSymlinks resolves both symlinks and ".." components.
6468 // Fall back to Abs when a path does not exist on disk yet.
6569 absBase , err := filepath .EvalSymlinks (base )
@@ -78,8 +82,10 @@ func MustBeWithin(base, candidate string) error {
7882 }
7983 rel , err := filepath .Rel (absBase , absCand )
8084 if err != nil || ! filepath .IsLocal (rel ) {
85+ log .Printf ("MustBeWithin: path escape detected: candidate=%q base=%q" , candidate , base )
8186 return fmt .Errorf ("path %q escapes base directory %q" , candidate , base )
8287 }
88+ log .Printf ("MustBeWithin: path is safe: candidate=%q (rel=%s) within base=%q" , candidate , rel , base )
8389 return nil
8490}
8591
0 commit comments