mirror of
https://github.com/kemko/nomad.git
synced 2026-01-01 16:05: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:
3
.changelog/16469.txt
Normal file
3
.changelog/16469.txt
Normal file
@@ -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",
|
||||
},
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user