fix: [security] Bad redirect check

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
This commit is contained in:
Nimer@Tornado 2026-07-05 05:41:00 +03:00 committed by Mohamad Nimer
parent 3015d947ac
commit bb6335b24a

View File

@ -25,12 +25,9 @@ func cleanPath(p string) string {
if p == "" {
return "/"
}
// Prevent scheme-relative ("//...") or backslash-based absolute ("/\\...") paths.
for len(p) > 1 && p[0] == '/' && p[1] == '/' {
p = p[1:]
}
if len(p) > 1 && p[0] == '/' && p[1] == '\\' {
p = "/" + p[2:]
// Prevent scheme-relative or backslash-based absolute redirects.
if len(p) > 1 && p[0] == '/' && (p[1] == '/' || p[1] == '\\') {
return "/"
}
// Reasonably sized buffer on stack to avoid allocations in the common case.