Skip to content

Commit 988c560

Browse files
picatzyycptt
authored andcommitted
Limit the number of parts allowed for auth token (#8122)
## What changed? This PR aims to add a limit to the number of parts when splitting an `Authorization` header `Bearer $token` values. ## Why? This is useful for limiting potential abuses from maliciously crafted header values. ## How did you test it? - [x] built - [x] run locally and tested manually - [x] covered by existing tests - [ ] added new unit test(s) - [ ] added new functional test(s) ## Potential risks I don't think there's any major risk here?
1 parent ed81e7c commit 988c560

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

common/authorization/default_jwt_claim_mapper.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,9 @@ func (a *defaultJWTClaimMapper) GetClaims(authInfo *AuthInfo) (*Claims, error) {
7272
return &claims, nil
7373
}
7474

75-
parts := strings.Split(authInfo.AuthToken, " ")
75+
// We use strings.SplitN even though we check the length later, to avoid
76+
// unnecessary allocations if the format is correct.
77+
parts := strings.SplitN(authInfo.AuthToken, " ", 2)
7678
if len(parts) != 2 {
7779
return nil, serviceerror.NewPermissionDenied("unexpected authorization token format", "")
7880
}

0 commit comments

Comments
 (0)