mirror of
https://github.com/kemko/nomad.git
synced 2026-01-06 10:25:42 +03:00
agent: trim space when parsing X-Nomad-Token header (#16469)
Our auth token parsing code trims space around the `Authorization` header but not around `X-Nomad-Token`. When using the UI, it's easy to accidentally introduce a leading or trailing space, which results in spurious authentication errors. Trim the space at the HTTP server.
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -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",
|
||||
},
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user