GLM-5.3 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 Opus 5.5.

Gold bugs found
3 of 5
Comments published
4
Comments matching a bug
3
Comments not matching
1
Cost of this PR
$0.086

Published comments (4)

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

Wrong null check: grantType checked instead of rawTokenId — A null `rawTokenId` slips through silently and gets encoded into the token id as the literal string "null". Make the second call `Objects.requireNonNull(rawTokenId, ...)` instead of re-checking `grantType`.

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

isAccessTokenId matcher inverts grant shortcut check and reads wrong substring — Tokens with any wrong grant type pass because the comparison is inverted and `items[0].substring(3, 5)` reads the wrong window, missing where `encodeTokenId` puts the shortcut. Negate the check and use `items[0].substring(4, 6)`.

mediumbugservices/src/main/java/org/keycloak/protocol/oidc/encode/DefaultTokenContextEncoderProvider.java:74-76

Decoder's fixed 6-char context check conflicts with variable-length grant shortcut SPI — The `getShortcut()` SPI advertises variable-length shortcuts, so a compliant provider produces token ids the decoder rejects with `IllegalArgumentException`, breaking the round-trip. Validate shortcut lengths in `encodeTokenId`, or relax the decoder to a variable-length grant segment.

mediumbugservices/src/test/java/org/keycloak/protocol/oidc/encode/DefaultTokenContextEncoderProviderTest.java:77-85

testIncorrectGrantType passes via NPE instead of exercising shortcut validation — The test still passes if validation regresses: without `postInit`, `getGrantTypeByShortcut` throws a `NullPointerException` that the broad `RuntimeException` catch swallows. Call `postInit` and catch `IllegalArgumentException` specifically.

Gold bugs found (3)

mediumThe AccessTokenContext constructor checks grantType twice instead of rawTokenId, so a null rawTokenId passes validation and is encoded as ':null'.
mediumisAccessTokenId reads the grant shortcut at the wrong offset (3,5 instead of 4,6) and inverts the comparison, so the event assertions never verify the token's grant type.
mediumtestIncorrectGrantType catches any RuntimeException, so it passes on a NullPointerException from the unset sessionFactory rather than verifying the unknown-grant IllegalArgumentException.

Gold bugs missed (2)

mediumClient-credentials (and UMA permission) token issuance never sets the GRANT_TYPE attribute, so their access token ids are encoded with the unknown grant 'na' instead of their shortcut.
mediumThe legacy token-exchange path in AbstractTokenExchangeProvider never sets Constants.GRANT_TYPE on the client session context, so tokens it issues are encoded with grant shortcut 'na' instead of the token-exchange shortcut.