Use url.Parse to validate X-Forwarded-Prefix value

This commit is contained in:
Kevin Pollet
2026-02-10 14:48:06 +01:00
committed by GitHub
parent d337748873
commit 4b3c971ea3
+4 -1
View File
@@ -4,6 +4,7 @@ import (
"fmt"
"io/fs"
"net/http"
"net/url"
"strings"
"text/template"
@@ -80,7 +81,9 @@ func Append(router *mux.Router, basePath string, customAssets fs.FS) error {
Path(basePath).
HandlerFunc(func(resp http.ResponseWriter, req *http.Request) {
xfPrefix := req.Header.Get("X-Forwarded-Prefix")
if strings.Contains(xfPrefix, "//") {
// Validates that the X-Forwarded-Prefix value contains a relative URL.
if u, err := url.Parse(xfPrefix); err != nil || u.Host != "" || u.Scheme != "" {
log.Error().Msgf("X-Forwarded-Prefix contains an invalid value: %s, defaulting to empty prefix", xfPrefix)
xfPrefix = ""
}