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:
parent
a25d3ea792
commit
8579d1e479
|
@ -0,0 +1,3 @@
|
|||
```release-note:improvement
|
||||
agent: trim leading and trailing spaces when parsing `X-Nomad-Token` header
|
||||
```
|
|
@ -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",
|
||||
},
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue