prevent route leak

This commit is contained in:
hcl 2021-01-25 23:37:54 +08:00 committed by nkanaev
parent 52073e7e81
commit 1a0db29aa6

View File

@ -69,6 +69,10 @@ func unsafeMethod(method string) bool {
func (h Handler) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
reqPath := req.URL.Path
if BasePath != "" {
if !strings.HasPrefix(reqPath, BasePath) {
rw.WriteHeader(http.StatusNotFound)
return
}
reqPath = strings.TrimPrefix(req.URL.Path, BasePath)
if reqPath == "" {
http.Redirect(rw, req, BasePath+"/", http.StatusFound)