DeepSeek V4.1 Flash · Balanced

implement-access-token-context-encoding-framework-keycloak

Keycloak · Java · L · 300–799 lines · 6 files

The normal review, with one generalist agent. Judge: Claude Haiku 5.5.

Gold bugs found
0 of 0
Comments published
5
Comments matching a bug
0
Comments not matching
5
Cost of this PR
$0.158

Published comments (5)

highbugserver-spi-private/src/main/java/org/keycloak/protocol/oidc/grants/OAuth2GrantTypeFactory.java:29-34

New abstract getShortcut() breaks binary compatibility for custom grants — Any externally deployed custom `OAuth2GrantTypeFactory` compiled against the previous SPI throws `AbstractMethodError` when `DefaultTokenContextEncoderProviderFactory.postInit` calls `getShortcut()`, so the server fails to start after upgrade. Give `getShortcut()` a default implementation, such as deriving it from `getId()` or returning the UNKNOWN `na` value.

mediumbugservices/src/main/java/org/keycloak/protocol/oidc/encode/AccessTokenContext.java:69-78

Duplicate null check on grantType means rawTokenId is never validated — Because `grantType` is checked twice, a null `rawTokenId` is silently encoded as the literal "null" suffix instead of failing fast. Change the second check to `Objects.requireNonNull(rawTokenId, "Null rawTokenId not allowed")`.

mediumbugservices/src/main/java/org/keycloak/protocol/oidc/encode/DefaultTokenContextEncoderProvider.java:109-118

Grant shortcut length is not validated before token ID encoding — A grant factory returning a 3-character shortcut mints access tokens whose IDs always throw `IllegalArgumentException` in `getTokenContextFromTokenId`, which requires exactly 6 characters. Validate that the shortcut is exactly 2 characters in `encodeTokenId`, or make the decoder length-agnostic.

mediumbugservices/src/main/java/org/keycloak/protocol/oidc/grants/ClientCredentialsGrantTypeFactory.java:38-42

client_credentials tokens encoded with UNKNOWN grant type — Set it before `generateAccessToken()` so the new `cc` shortcut is emitted.

mediumbugtestsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/AssertEvents.java:483

isAccessTokenId checks wrong grant substring and inverts the comparison — `substring(3, 5)` reads the token type's second character plus the grant's first character, so the grant shortcut is never validated. Use `substring(4, 6)`, otherwise every valid encoded token ID is rejected once the inverted comparison is fixed.

Gold bugs found (0)

None.

Gold bugs missed (0)

None.