Claude Opus 5.5 · 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
7
Comments matching a bug
0
Comments not matching
7
Cost of this PR
$1.856

Published comments (7)

mediumbugservices/src/main/java/org/keycloak/protocol/oidc/encode/AccessTokenContext.java:73

Null check for rawTokenId validates grantType instead — A null `rawTokenId` is accepted and later encoded as the literal `...:null` token ID. Pass `rawTokenId` to `Objects.requireNonNull` instead of `grantType`.

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

Grant shortcut check is inverted in isAccessTokenId matcher — The grant assertion rejects correct token IDs and accepts tokens with the wrong grant. Negate the `equals` check so it returns false only when the shortcut differs from `expectedGrantShortcut`.

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

Grant shortcut check reads the wrong substring of the token ID prefix — The real grant shortcut is never compared, because `substring(3, 5)` spans the token-type and grant shortcuts while the grant sits at characters 4 to 6. Use `items[0].substring(4, 6)` instead.

mediumbugservices/src/main/java/org/keycloak/protocol/oidc/encode/DefaultTokenContextEncoderProvider.java:57-60

Client-credentials tokens fall back to "na" grant type instead of "cc" — Service-account tokens never carry the "cc" context the unit tests expect, because `ClientCredentialsGrantType` calls `generateAccessToken()` directly and never sets `Constants.GRANT_TYPE`. Set that attribute to `context.getGrantType()` in `ClientCredentialsGrantType.process` before the token is generated.

mediumbugservices/src/main/java/org/keycloak/protocol/oidc/tokenexchange/StandardTokenExchangeProvider.java:237

Legacy V1 token exchange tokens lack token-exchange grant type attribute — Legacy token exchange tokens are encoded with the "na" grant instead of "te", since `AbstractTokenExchangeProvider` calls `generateAccessToken()` without this attribute. Set `Constants.GRANT_TYPE` to `OAuth2Constants.TOKEN_EXCHANGE_GRANT_TYPE` in that legacy path too.

mediumbugserver-spi-private/src/main/java/org/keycloak/protocol/oidc/grants/OAuth2GrantTypeFactory.java:33

Abstract `getShortcut()` breaks startup for existing custom grant type factories — Existing custom `OAuth2GrantTypeFactory` implementations will abort server startup, either with `AbstractMethodError` or a null passed to `ConcurrentHashMap.put` in `DefaultTokenContextEncoderProviderFactory.postInit`. Add a default implementation, or skip and log factories without a shortcut.

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

Grant shortcuts that are not 2 characters create undecodable token IDs — `getTokenContextFromTokenId` requires a 2-character grant shortcut, so others, like the 3-letter one the interface Javadoc suggests, produce token IDs that fail with `IllegalArgumentException`. Validate that each shortcut is exactly 2 characters in `postInit` and `getShortcutByGrantType`.

Gold bugs found (0)

None.

Gold bugs missed (0)

None.