Kimi K3.1 Pro · Heavy
implement-access-token-context-encoding-framework-keycloak
Keycloak · Java · L · 300–799 lines · 6 files
The generalist plus 9 specialist lens agents in parallel, then the same verify and dedup steps. Judge: Claude Haiku 5.5.
- Gold bugs found
- 0 of 0
- Comments published
- 12
- Comments matching a bug
- 0
- Comments not matching
- 12
- Cost of this PR
- $3.349
Published comments (12)
This lazy registration path does not preserve the shortcut-uniqueness invariant checked in postInit — If a grant discovered after startup reuses an existing shortcut, line 113 overwrites grantsByShortcuts for the old grant while the old grant remains in grantsToShortcuts; both grants can then encode the same context and tokens from the old grant decode as the new one. Validate collisions before modifying either map and publish the two mappings atomically, including when concurrent lazy lookups occur.
This test does not reach the intended unknown-grant `IllegalArgumentException` — Since `ac` is absent from the fixture map and `sessionFactory` was never initialized, `getGrantTypeByShortcut` dereferences the null session factory during its lazy refresh and throws `NullPointerException`; `catch (RuntimeException)` treats that as success. The test would therefore remain green if the intended validation were broken.
Abstract getShortcut() breaks existing custom grant type factories — Adding getShortcut() as an abstract SPI method breaks existing custom OAuth2GrantTypeFactory implementations. DefaultTokenContextEncoderProviderFactory.postInit() calls it for every registered grant factory, so a custom provider compiled against the previous interface will fail startup with AbstractMethodError; rebuilding also fails until the method is added.
Client credentials and UMA token IDs use the na fallback — The grant type is propagated only through `createTokenResponse`, but `ClientCredentialsGrantType.process` (lines 140-141) and the UMA flow in `AuthorizationTokenService` (lines 357-358) generate access tokens directly without setting `Constants.GRANT_TYPE`. Their token IDs therefore use the `na` fallback instead of `cc` or `pg`; set the grant attribute on these direct paths or move propagation into the shared access-token creation path. **Also found in:** - `services/src/main/java/org/keycloak/protocol/oidc/tokenexchange/StandardTokenExchangeProvider.java:237-237`
getShortcut Javadoc specifies the wrong shortcut length — This contract describes a “3-letters” shortcut, but all shortcut implementations added here return two characters and `DefaultTokenContextEncoderProvider` decodes exactly two grant characters as part of a six-character prefix. An implementer following this Javadoc could return a three-character shortcut whose encoded token ID is then rejected. **Also found in:** - `services/src/main/java/org/keycloak/protocol/oidc/encode/DefaultTokenContextEncoderProvider.java:74-81` - `services/src/main/java/org/keycloak/protocol/oidc/encode/DefaultTokenContextEncoderProvider.java:109-117`
Constructor validates grantType twice and allows a null rawTokenId — The constructor checks `grantType` twice, allowing `rawTokenId` to remain null so `encodeTokenId` emits a literal `null` suffix instead of rejecting the invalid context. Change this check to `Objects.requireNonNull(rawTokenId, "Null rawTokenId not allowed")`.
Access-token matcher extracts the wrong grant shortcut — `substring(3, 5)` reads the last token-type character and first grant-type character rather than the grant shortcut at indexes 4–5, allowing events with the wrong grant to pass the new assertions. Read `substring(4, 6)` after validating the six-character prefix.
Access token matcher uses the wrong grant shortcut offsets — The grant shortcut is at offsets 4 and 5 of the six-character context, but `substring(3, 5)` reads the second token-type character and only the first grant-type character. For example, `onrtac` produces `ta` instead of `ac`, so the assertion is not comparing the grant field.
Grant shortcut is extracted from the wrong token ID offset — The new comment says the grant shortcut starts at the fourth character, but the encoder layout is two session-type characters, two token-type characters, then two grant-type characters; the encoder therefore extracts it with `substring(4, 6)`, starting at the fifth character. This comment documents the wrong offset (and the adjacent extraction uses that same wrong offset); align it with the encoder’s `substring(4, 6)` layout.
Access token matcher reads the grant shortcut at the wrong offset — The grant shortcut is read from the wrong position. The encoder/decoder layout places it at character indices 4 and 5 (the decoder uses substring(4, 6)), but this matcher reads indices 3 and 4.
Access token ID matcher does not validate the expected grant — DefaultTokenContextEncoderProvider.encodeTokenId places the two-character grant shortcut at indexes 4–5, after the two-character session and token types. This extracts indexes 3–4 instead, so it checks the last token-type character plus only the first grant character rather than the generated grant field.
Access token matcher rejects IDs with the expected grant shortcut — The matcher returns false when the extracted shortcut equals `expectedGrantShortcut`, so valid IDs are rejected whenever the extracted text accidentally matches, and correcting the bounds alone would reject every valid ID. Negate the equality test so a mismatch returns false.
Gold bugs found (0)
None.
Gold bugs missed (0)
None.