diff --git a/.changelog/16469.txt b/.changelog/16469.txt new file mode 100644 index 000000000..e97e2f5dc --- /dev/null +++ b/.changelog/16469.txt @@ -0,0 +1,3 @@ +```release-note:improvement +agent: trim leading and trailing spaces when parsing `X-Nomad-Token` header +``` diff --git a/command/agent/http.go b/command/agent/http.go index 78876f890..aab5c0017 100644 --- a/command/agent/http.go +++ b/command/agent/http.go @@ -969,7 +969,7 @@ func parseInt(req *http.Request, field string) (*int, error) { // parseToken is used to parse the X-Nomad-Token param func (s *HTTPServer) parseToken(req *http.Request, token *string) { if other := req.Header.Get("X-Nomad-Token"); other != "" { - *token = other + *token = strings.TrimSpace(other) return } diff --git a/command/agent/http_test.go b/command/agent/http_test.go index 66d097e0d..9f31caf51 100644 --- a/command/agent/http_test.go +++ b/command/agent/http_test.go @@ -552,7 +552,7 @@ func TestParseToken(t *testing.T) { { Name: "Parses token from X-Nomad-Token", HeaderKey: "X-Nomad-Token", - HeaderValue: "foobar", + HeaderValue: " foobar", ExpectedToken: "foobar", }, {