node: check authorization header case-insensitivity (#35408)

This commit is contained in:
rjl493456442 2026-07-24 16:19:14 +08:00 committed by GitHub
parent af03a271df
commit a524f2bb17
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 4 additions and 4 deletions

View file

@ -48,7 +48,7 @@ func (handler *jwtHandler) ServeHTTP(out http.ResponseWriter, r *http.Request) {
claims jwt.RegisteredClaims claims jwt.RegisteredClaims
) )
if auth := r.Header.Get("Authorization"); len(auth) >= 7 && strings.EqualFold(auth[:7], "bearer ") { if auth := r.Header.Get("Authorization"); len(auth) >= 7 && strings.EqualFold(auth[:7], "bearer ") {
strToken = strings.TrimPrefix(auth, "Bearer ") strToken = auth[7:]
} }
if len(strToken) == 0 { if len(strToken) == 0 {
http.Error(out, "missing token", http.StatusUnauthorized) http.Error(out, "missing token", http.StatusUnauthorized)

View file

@ -371,6 +371,9 @@ func TestJWT(t *testing.T) {
"bar": "baz", "bar": "baz",
})) }))
}, },
func() string {
return fmt.Sprintf("bearer %v", issueToken(secret, nil, testClaim{"iat": time.Now().Unix()}))
},
} }
for i, tokenFn := range expOk { for i, tokenFn := range expOk {
token := tokenFn() token := tokenFn()
@ -421,9 +424,6 @@ func TestJWT(t *testing.T) {
func() string { func() string {
return fmt.Sprintf("Bearer %v", issueToken(secret, nil, testClaim{"iat": time.Now().Unix()})) return fmt.Sprintf("Bearer %v", issueToken(secret, nil, testClaim{"iat": time.Now().Unix()}))
}, },
func() string {
return fmt.Sprintf("bearer %v", issueToken(secret, nil, testClaim{"iat": time.Now().Unix()}))
},
func() string { func() string {
return fmt.Sprintf("Bearer: %v", issueToken(secret, nil, testClaim{"iat": time.Now().Unix()})) return fmt.Sprintf("Bearer: %v", issueToken(secret, nil, testClaim{"iat": time.Now().Unix()}))
}, },