Skip to content

Commit 82aadc9

Browse files
ryowrightheppu
authored andcommitted
Fix null token type bug (hashicorp#13236)
* Fixed null token panic from 'v1/auth/token/' endpoints and returned proper error response * Fixed panic resulting from null token_type in /auth/token/roles/{role_name} to returne proper error response * added changelog entry for PR hashicorp#13236 * edit changelog entry for PR hashicorp#13236
1 parent f82f070 commit 82aadc9

File tree

3 files changed

+9
-0
lines changed

3 files changed

+9
-0
lines changed

changelog/13236.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:bug
2+
core/token: Fix null token_type panic resulting from 'v1/auth/token/roles/{role_name}' endpoint
3+
```

vault/request_handling.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -543,6 +543,9 @@ func (c *Core) handleCancelableRequest(ctx context.Context, req *logical.Request
543543
}
544544
break
545545
}
546+
if token == nil {
547+
return logical.ErrorResponse("bad token"), logical.ErrPermissionDenied
548+
}
546549
_, nsID := namespace.SplitIDFromString(token.(string))
547550
if nsID != "" {
548551
ns, err := NamespaceByID(ctx, nsID, c)

vault/token_store.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3348,6 +3348,9 @@ func (ts *TokenStore) tokenStoreRoleCreateUpdate(ctx context.Context, req *logic
33483348
oldEntryTokenType := entry.TokenType
33493349
if tokenTypeRaw, ok := data.Raw["token_type"]; ok {
33503350
tokenTypeStr = new(string)
3351+
if tokenTypeRaw == nil {
3352+
return logical.ErrorResponse("Invalid 'token_type' value: null"), nil
3353+
}
33513354
*tokenTypeStr = tokenTypeRaw.(string)
33523355
delete(data.Raw, "token_type")
33533356
entry.TokenType = logical.TokenTypeDefault

0 commit comments

Comments
 (0)