mirror of
https://github.com/gin-gonic/gin.git
synced 2026-09-04 22:53:34 +08:00
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:
parent
3015d947ac
commit
bb6335b24a
9
path.go
9
path.go
@ -25,12 +25,9 @@ func cleanPath(p string) string {
|
|||||||
if p == "" {
|
if p == "" {
|
||||||
return "/"
|
return "/"
|
||||||
}
|
}
|
||||||
// Prevent scheme-relative ("//...") or backslash-based absolute ("/\\...") paths.
|
// Prevent scheme-relative or backslash-based absolute redirects.
|
||||||
for len(p) > 1 && p[0] == '/' && p[1] == '/' {
|
if len(p) > 1 && p[0] == '/' && (p[1] == '/' || p[1] == '\\') {
|
||||||
p = p[1:]
|
return "/"
|
||||||
}
|
|
||||||
if len(p) > 1 && p[0] == '/' && p[1] == '\\' {
|
|
||||||
p = "/" + p[2:]
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reasonably sized buffer on stack to avoid allocations in the common case.
|
// Reasonably sized buffer on stack to avoid allocations in the common case.
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user