DeepSeek V4 Pro · Heavy
implement-access-token-context-encoding-framework-keycloak
Keycloak · Java · L · 300–799 lines · 6 files
The generalist plus 9 specialist lens agents in parallel, then the same verify and dedup steps. Judge: Claude Opus 5.5.
- Gold bugs found
- 3 of 5
- Comments published
- 6
- Comments matching a bug
- 3
- Comments not matching
- 3
- Cost of this PR
- $1.644
Published comments (6)
Client credentials token grant type encoded as na instead of cc — Without this attribute, `getTokenContextFromClientSessionContext` falls back to UNKNOWN and client-credentials tokens encode `na` instead of `cc`. Set `Constants.GRANT_TYPE` to `context.getGrantType()` on the client session context in `ClientCredentialsGrantType.process` before generating the access token.
Constructor validates grantType twice and fails to validate rawTokenId — A null `rawTokenId` passes silently and later makes `encodeTokenId` emit a token id ending in `null`. Change the second `Objects.requireNonNull` to target `rawTokenId`.
Access token ID matcher extracts grant-type shortcut at wrong offset — The grant shortcut occupies indices 4–5, so reading `substring(3, 5)` yields part of the token type plus the first grant character (for `trltcc` it gives `tc` instead of `cc`) and never inspects the complete shortcut. Use `substring(4, 6)` and invert the condition so a mismatch returns false.
isAccessTokenId validates grant shortcut at wrong substring indexes — The encoder places the grant shortcut at indices 4–5 of the pre-colon context, so this matcher reads the wrong slice and can also throw on short contexts. Require `items[0].length() >= 6` and return `expectedGrantShortcut.equals(items[0].substring(4, 6)) && isUUID().matches(items[1])`.
Inverted condition rejects correct grant type in isAccessTokenId — Returning false when the extracted shortcut equals the expected one rejects correct grant types, so these assertion helpers only check the UUID and never verify the grant type. Invert the condition so only a genuine mismatch returns false.
OAuth2 grant type shortcut length not constrained to two characters but encoder assumes it — A custom factory returning a shortcut length other than two produces token IDs that later throw `IllegalArgumentException` in `DefaultTokenContextEncoderProvider.getTokenContextFromTokenId`. Enforce an exact two-character shortcut here, validate it in `DefaultTokenContextEncoderProviderFactory.postInit`, or make the encoder handle variable lengths. **Also found in:** - `services/src/main/java/org/keycloak/protocol/oidc/encode/DefaultTokenContextEncoderProvider.java:109-117`