Kimi K3.1 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 Haiku 5.5.

Gold bugs found
0 of 0
Comments published
8
Comments matching a bug
0
Comments not matching
8
Cost of this PR
$1.623

Published comments (8)

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

Constructor checks grantType twice and permits a null rawTokenId — A null raw ID reaches `encodeTokenId` and is serialized as the literal suffix `null`. Replace the duplicate `grantType` check with `Objects.requireNonNull(rawTokenId, "Null rawTokenId not allowed")`.

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

Inverted grant shortcut check accepts incorrect access token IDs — The matcher rejects an ID whose shortcut equals `expectedGrantShortcut` and accepts mismatches with a UUID suffix, so event assertions can pass for the wrong grant. Negate the equality test before returning `false`.

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

Grant shortcut check reads the wrong token prefix characters — Reading a token-type character and only one grant character makes the comparison validate the wrong value, even with the equality test corrected. Replace `substring(3, 5)` with `substring(4, 6)` to read both grant-shortcut characters.

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

Abstract getShortcut causes AbstractMethodError for legacy grant factories — Invoking the new abstract method on a previously compiled custom grant factory can throw `AbstractMethodError` in `DefaultTokenContextEncoderProviderFactory.postInit`, preventing startup. Give `getShortcut()` a default implementation returning `getId()`, or otherwise support factories without it.

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

Invalid grant shortcut lengths produce token IDs the decoder rejects — Without a two-character limit on `grantShort`, custom shortcuts such as the three-letter form suggested by `OAuth2GrantTypeFactory` produce IDs that the decoder rejects. Enforce the length during initial and lazy registration, or update the parser to support the declared format.

mediumbugservices/src/main/java/org/keycloak/protocol/oidc/encode/DefaultTokenContextEncoderProviderFactory.java:112-114

Lazy grant registration overwrites existing shortcut mappings — A newly deployed grant reusing a shortcut makes both grants encode identically and causes existing IDs to decode as the new grant. Before updating `grantsByShortcuts` or `grantsToShortcuts`, reject any shortcut already mapped to a different grant, as `postInit` does.

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

Token-exchange grant attribute is missing from V1 and inherited exchange paths — V1 exchange via `V1TokenExchangeProvider` and other inherited paths lack `Constants.GRANT_TYPE`, so their access-token IDs encode `na` instead of `te`. Set it to `OAuth2Constants.TOKEN_EXCHANGE_GRANT_TYPE` in the shared `AbstractTokenExchangeProvider` token-generation path as well.

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

Client-credentials access-token IDs encode na instead of cc — Because `ClientCredentialsGrantType` bypasses `OAuth2GrantTypeBase.createTokenResponse` and calls `generateAccessToken()` directly, `Constants.GRANT_TYPE` remains unset and every client-credentials ID encodes `na` instead of `cc`. Set it to `OAuth2Constants.CLIENT_CREDENTIALS` on the `ClientSessionContext` before generating the token.

Gold bugs found (0)

None.

Gold bugs missed (0)

None.