From 458de6d118a0559d0aacbf1faa0b74277c05ed75 Mon Sep 17 00:00:00 2001 From: Chris Capurso <1036769+ccapurso@users.noreply.github.com> Date: Thu, 10 Oct 2024 12:25:14 -0400 Subject: [PATCH] only strip v1 prefix from path if present (#28669) * only strip v1 prefix from path if present * add changelog entry * adjust changelog --- changelog/28669.txt | 3 +++ http/handler.go | 10 ++++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) create mode 100644 changelog/28669.txt diff --git a/changelog/28669.txt b/changelog/28669.txt new file mode 100644 index 0000000000..e2594052ed --- /dev/null +++ b/changelog/28669.txt @@ -0,0 +1,3 @@ +```release-note:bug +core: Fixed panic seen when performing help requests without /v1/ in the URL. +``` diff --git a/http/handler.go b/http/handler.go index ceaaf34b45..c74f392aee 100644 --- a/http/handler.go +++ b/http/handler.go @@ -1417,7 +1417,13 @@ func respondOIDCPermissionDenied(w http.ResponseWriter) { enc.Encode(oidcResponse) } -// trimPath removes the /v1/ prefix and the namespace from the path +// trimPath removes the /v1/ prefix (if present) and the namespace from the path func trimPath(ns *namespace.Namespace, path string) string { - return ns.TrimmedPath(path[len("/v1/"):]) + const v1Prefix = "/v1/" + + if strings.HasPrefix(path, v1Prefix) { + return ns.TrimmedPath(path[len(v1Prefix):]) + } + + return ns.TrimmedPath(path) }