mirror of
				https://github.com/caddyserver/caddy.git
				synced 2025-11-04 03:27:23 -05:00 
			
		
		
		
	fileserver: Preserve query during canonicalization redirect (#6109)
* fileserver: Preserve query during canonicalization redirect * Clarify that only a path should be passed
This commit is contained in:
		
							parent
							
								
									0d44e3ecba
								
							
						
					
					
						commit
						5a4374bea0
					
				@ -639,12 +639,18 @@ func calculateEtag(d os.FileInfo) string {
 | 
				
			|||||||
	return `"` + t + s + `"`
 | 
						return `"` + t + s + `"`
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func redirect(w http.ResponseWriter, r *http.Request, to string) error {
 | 
					// redirect performs a redirect to a given path. The 'toPath' parameter
 | 
				
			||||||
	for strings.HasPrefix(to, "//") {
 | 
					// MUST be solely a path, and MUST NOT include a query.
 | 
				
			||||||
 | 
					func redirect(w http.ResponseWriter, r *http.Request, toPath string) error {
 | 
				
			||||||
 | 
						for strings.HasPrefix(toPath, "//") {
 | 
				
			||||||
		// prevent path-based open redirects
 | 
							// prevent path-based open redirects
 | 
				
			||||||
		to = strings.TrimPrefix(to, "/")
 | 
							toPath = strings.TrimPrefix(toPath, "/")
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	http.Redirect(w, r, to, http.StatusPermanentRedirect)
 | 
						// preserve the query string if present
 | 
				
			||||||
 | 
						if r.URL.RawQuery != "" {
 | 
				
			||||||
 | 
							toPath += "?" + r.URL.RawQuery
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						http.Redirect(w, r, toPath, http.StatusPermanentRedirect)
 | 
				
			||||||
	return nil
 | 
						return nil
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user