DeepSeek V4 Pro · 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
2 of 5
Comments published
3
Comments matching a bug
2
Comments not matching
1
Cost of this PR
$0.494

Published comments (3)

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

Abstract getShortcut() breaks binary compatibility for existing grant factories — Pre-existing grant factories compiled against older Keycloak versions will throw `AbstractMethodError` when `DefaultTokenContextEncoderProviderFactory.postInit` calls `getShortcut()`, breaking all access-token issuance. Make `getShortcut()` a `default` method so existing providers remain compatible.

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

isAccessTokenId matcher never verifies grant shortcut — The matcher never rejects a non-matching grant shortcut because `substring(3, 5)` reads the wrong indexes and the condition is inverted, so it only validates the UUID part. Use `substring(4, 6)` and return false when it does not equal `expectedGrantShortcut`.

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

Client-credentials access tokens are encoded with grant type 'na' instead of 'cc' — Tokens minted for this grant type carry `na` instead of `cc` because `ClientCredentialsGrantType.process` never sets `Constants.GRANT_TYPE` on `clientSessionCtx`. Set it to `OAuth2Constants.CLIENT_CREDENTIALS` before calling token generation.

Gold bugs found (2)

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.
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.

Gold bugs missed (3)

mediumThe AccessTokenContext constructor checks grantType twice instead of rawTokenId, so a null rawTokenId passes validation and is encoded as ':null'.
mediumtestIncorrectGrantType catches any RuntimeException, so it passes on a NullPointerException from the unset sessionFactory rather than verifying the unknown-grant IllegalArgumentException.
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.