Fix open-redirect via next parameter, remove dead code

This commit is contained in:
2026-08-22 23:45:39 -05:00
parent b4b1ba8470
commit 89e46bf539
4 changed files with 13 additions and 16 deletions
+11
View File
@@ -36,6 +36,17 @@ func (h *Web) page(w http.ResponseWriter, r *http.Request, name, active, title s
})
}
// safeRedirectPath returns next if it's a same-site relative path, or
// "/" otherwise. Guards against open redirects: a bare "/foo" is fine,
// but "//evil.com" or "https://evil.com" are protocol-relative/absolute
// URLs a browser would follow off-site.
func safeRedirectPath(next string) string {
if next == "" || next[0] != '/' || len(next) > 1 && next[1] == '/' {
return "/"
}
return next
}
func (h *Web) flash(w http.ResponseWriter, r *http.Request, name, active, title, flash, kind string, data any) {
render(w, name, PageData{
Active: active,