@@ -2456,23 +2456,26 @@ func (ctx *Context) UploadFormFiles(destDirectory string, before ...func(*Contex
2456
2456
destPath := filepath .Join (destDirectory , filename )
2457
2457
2458
2458
// Get the canonical path of the destination
2459
- canonicalDestPath , err := filepath .EvalSymlinks (destPath )
2460
- if err != nil {
2461
- return nil , 0 , err
2462
- }
2459
+ // canonicalDestPath, err := filepath.EvalSymlinks(destPath)
2460
+ // if err != nil {
2461
+ // return nil, 0, fmt.Errorf("dest path: %s: eval symlinks: %w", destPath, err)
2462
+ // }
2463
+ // ^ No, it will try to find the file before uploaded.
2463
2464
2464
2465
// Get the canonical path of the destination directory.
2465
- canonicalDestDir , err := filepath .EvalSymlinks (destDirectory )
2466
+ canonicalDestDir , err := filepath .EvalSymlinks (destDirectory ) // the destDirectory should exists.
2466
2467
if err != nil {
2467
- return nil , 0 , err
2468
+ return nil , 0 , fmt . Errorf ( "dest directory: %s: eval symlinks: %w" , destDirectory , err )
2468
2469
}
2469
2470
2470
2471
// Check if the destination path is within the destination directory.
2471
- if ! strings .HasPrefix (canonicalDestPath , canonicalDestDir ) {
2472
+ if ! strings .HasPrefix (destPath , canonicalDestDir ) {
2472
2473
// Reject the input as it is a path traversal attempt.
2473
2474
continue innerLoop
2474
2475
}
2475
2476
2477
+ file .Filename = filename
2478
+
2476
2479
n0 , err0 := ctx .SaveFormFile (file , destPath )
2477
2480
if err0 != nil {
2478
2481
return nil , 0 , err0
0 commit comments