mirror of
https://github.com/go-gitea/gitea.git
synced 2026-05-20 09:23:57 +02:00
Fix redirect
This commit is contained in:
parent
318cb85037
commit
cb9a3c8aed
@ -24,6 +24,10 @@ func urlIsRelative(s string, u *url.URL) bool {
|
|||||||
if len(s) > 1 && (s[0] == '/' || s[0] == '\\') && (s[1] == '/' || s[1] == '\\') {
|
if len(s) > 1 && (s[0] == '/' || s[0] == '\\') && (s[1] == '/' || s[1] == '\\') {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
// Backslashes (including encoded) can be normalized by browsers into slashes and allow open redirects.
|
||||||
|
if strings.Contains(s, "\\") || strings.Contains(strings.ToLower(s), "%5c") {
|
||||||
|
return false
|
||||||
|
}
|
||||||
return u != nil && u.Scheme == "" && u.Host == ""
|
return u != nil && u.Scheme == "" && u.Host == ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -32,6 +32,9 @@ func TestIsRelativeURL(t *testing.T) {
|
|||||||
"\\\\",
|
"\\\\",
|
||||||
"/\\",
|
"/\\",
|
||||||
"\\/",
|
"\\/",
|
||||||
|
"/a/../\\example.com",
|
||||||
|
"/%5cexample.com",
|
||||||
|
"/a/../%5cexample.com",
|
||||||
"mailto:a@b.com",
|
"mailto:a@b.com",
|
||||||
"https://test.com",
|
"https://test.com",
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user