diff --git a/pkg/handler/error/error.go b/pkg/handler/error/error.go index d258455..bf1f340 100644 --- a/pkg/handler/error/error.go +++ b/pkg/handler/error/error.go @@ -137,7 +137,7 @@ func (h Handler) defaultErrorResponse(w http.ResponseWriter, r *http.Request, st } func (h Handler) customErrorRedirect(w http.ResponseWriter, r *http.Request, statusCode int) error { - override, err := url.Parse(h.GetErrorPath()) + override, err := url.ParseRequestURI(h.GetErrorPath()) if err != nil { return err } diff --git a/pkg/handler/url/url.go b/pkg/handler/url/url.go index f90d02b..6fb0fa2 100644 --- a/pkg/handler/url/url.go +++ b/pkg/handler/url/url.go @@ -36,7 +36,7 @@ func CanonicalRedirect(r *http.Request) string { return ingressPath } - parsed, err := url.Parse(redirect) + parsed, err := url.ParseRequestURI(redirect) if err != nil { // Silently fall back to ingress path return ingressPath diff --git a/pkg/handler/url/url_test.go b/pkg/handler/url/url_test.go index 426aa99..43118f1 100644 --- a/pkg/handler/url/url_test.go +++ b/pkg/handler/url/url_test.go @@ -102,6 +102,16 @@ func TestCanonicalRedirect(t *testing.T) { value: "/path?gnu=notunix", expected: "/path?gnu=notunix", }, + { + name: "relative path", + value: "path", + expected: "/some-path", // should fall back to default path + }, + { + name: "relative path with query parameters", + value: "path?gnu=notunix", + expected: "/some-path", // should fall back to default path + }, { name: "url encoded path", value: "%2Fpath", diff --git a/pkg/ingress/ingress.go b/pkg/ingress/ingress.go index 89d1397..9b5ef96 100644 --- a/pkg/ingress/ingress.go +++ b/pkg/ingress/ingress.go @@ -119,7 +119,7 @@ func ParseIngress(ingress string) (*Ingress, error) { return nil, fmt.Errorf("ingress cannot be empty") } - u, err := url.Parse(ingress) + u, err := url.ParseRequestURI(ingress) if err != nil { return nil, err }