fix forwarding unescaped paths

This commit is contained in:
dasha_uwu 2025-08-07 09:45:57 +05:00
parent c9565782b4
commit cd95d80497

11
main.go
View file

@ -79,10 +79,12 @@ func proxy() http.Handler {
}
}
escapedPath := r.URL.EscapedPath()
var pathDef pathDef
matched := false
for _, hostPathDef := range hd {
if !strings.HasPrefix(r.URL.Path, hostPathDef.path) {
if !strings.HasPrefix(escapedPath, hostPathDef.path) {
continue
}
if !matched || len(hostPathDef.path) > len(pathDef.path) {
@ -96,7 +98,12 @@ func proxy() http.Handler {
return
}
r.URL.Path = r.URL.Path[len(pathDef.path):]
r.URL.RawPath = escapedPath[len(pathDef.path):]
unescapedPath, err := url.PathUnescape(r.URL.RawPath)
if err != nil {
panic("unreachable")
}
r.URL.Path = unescapedPath
if pathDef.credentials != nil {
match := false