File tree Expand file tree Collapse file tree 1 file changed +10
-4
lines changed
modules/caddyhttp/fileserver Expand file tree Collapse file tree 1 file changed +10
-4
lines changed Original file line number Diff line number Diff line change @@ -639,12 +639,18 @@ func calculateEtag(d os.FileInfo) string {
639
639
return `"` + t + s + `"`
640
640
}
641
641
642
- func redirect (w http.ResponseWriter , r * http.Request , to string ) error {
643
- for strings .HasPrefix (to , "//" ) {
642
+ // redirect performs a redirect to a given path. The 'toPath' parameter
643
+ // MUST be solely a path, and MUST NOT include a query.
644
+ func redirect (w http.ResponseWriter , r * http.Request , toPath string ) error {
645
+ for strings .HasPrefix (toPath , "//" ) {
644
646
// prevent path-based open redirects
645
- to = strings .TrimPrefix (to , "/" )
647
+ toPath = strings .TrimPrefix (toPath , "/" )
646
648
}
647
- http .Redirect (w , r , to , http .StatusPermanentRedirect )
649
+ // preserve the query string if present
650
+ if r .URL .RawQuery != "" {
651
+ toPath += "?" + r .URL .RawQuery
652
+ }
653
+ http .Redirect (w , r , toPath , http .StatusPermanentRedirect )
648
654
return nil
649
655
}
650
656
You can’t perform that action at this time.
0 commit comments