8000 Fix AccessTokenContext raw token id null check by DDINGJOO · Pull Request #53990 · keycloak/keycloak · GitHub
[go: up one dir, main page]

Skip to content

Fix AccessTokenContext raw token id null check - #53990

Merged
mposolda merged 1 commit into
keycloak:mainfrom
DDINGJOO:fix-access-token-context-raw-token-id-check
Oct 19, 2026
Merged

mposolda merged 1 commit into
keycloak:mainfrom
DDINGJOO:fix-access-token-context-raw-token-id-check

Conversation

@DDINGJOO
@DDINGJOO DDINGJOO commented Oct 14, 2026 •
Copy link
Copy Markdown
Contributor

AccessTokenContext checks grantType twice, so a null rawTokenId argument bypasses the intended validation:

Objects.requireNonNull(grantType, "Null grantType not allowed");
Objects.requireNonNull(grantType, "Null rawTokenId not allowed");

The constructor is a @JsonCreator, so the value also arrives from deserialized token context JSON. A null is stored and later concatenated into the encoded token id in DefaultTokenContextEncoderProvider, where it shows up as the literal null instead of failing fast at construction.

Replace the second check with rawTokenId and add tests covering all four constructor arguments.

Validation:

keycloak-evidence
mvn -pl services test -Dtest=AccessTokenContextTest
  before:  Tests run: 4, Failures: 1   (shouldRejectNullRawTokenId: expected NullPointerException to be thrown, but nothing was thrown)
  after:   Tests run: 4, Failures: 0

mvn -pl services test -Dtest="*TokenContext*"
  Tests run: 10, Failures: 0   BUILD SUCCESS

Closes #54051

@DDINGJOO
DDINGJOO requested a review from a team as a code owner October 14, 2026 22:39
Copilot AI balanced review requested due to automatic review settings October 14, 2026 22:39
DDINGJOO added a commit to DDINGJOO/DDINGJOO that referenced this pull request Oct 14, 2026
Copilot AI left a comment
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The focused fix enforces the intended constructor contract and includes regression coverage, with no blocking issues identified.

0 open findings

What changed in this PR

Fixes constructor validation in AccessTokenContext so null raw token IDs are rejected before encoding.

Changes:

  • Corrects the duplicated grantType check to validate rawTokenId.
  • Adds null-validation tests for all four constructor arguments.
File Description
services/​src/​test/​java/​org/​keycloak/​protocol/​oidc/​encode/​AccessTokenContextTest.java Adds four constructor null-validation tests.
services/​src/​main/​java/​org/​keycloak/​protocol/​oidc/​encode/​AccessTokenContext.java Checks rawTokenId instead of checking grantType twice.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@DDINGJOO
DDINGJOO force-pushed the fix-access-token-context-raw-token-id-check branch from eb45242 to 10175f0 Compare October 16, 2026 03:39
@DDINGJOO
DDINGJOO force-pushed the fix-access-token-context-raw-token-id-check branch from 10175f0 to ba7a611 Compare October 16, 2026 03:45
Copilot AI balanced review requested due to automatic review settings October 16, 2026 14:01
Copilot AI left a comment
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The focused fix restores the intended validation and includes regression coverage, with no unresolved issues.

0 open findings

🧠 Review effort: Balanced

@DDINGJOO
DDINGJOO force-pushed the fix-access-token-context-raw-token-id-check branch from 77e5356 to 0624663 Compare October 18, 2026 08:56
Copilot AI balanced review requested due to automatic review settings October 18, 2026 08:56
Copilot AI left a comment
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The focused fix restores the intended validation with regression coverage and no blocking issues.

No open issues 🎉

Review effort: Balanced

mposolda
mposolda previously approved these changes Oct 19, 2026
@mposolda mposolda left a comment
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@DDINGJOO Thanks!

@mposolda mposolda self-assigned this Oct 19, 2026
AccessTokenContext checks grantType twice, so a null rawTokenId argument
bypasses the intended validation. Replace the second check with rawTokenId
and add tests covering all four constructor arguments.

Closes keycloak#54051

Signed-off-by: DDINGJOO <173995233+DDINGJOO@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings October 19, 2026 14:01
@DDINGJOO
DDINGJOO force-pushed the fix-access-token-context-raw-token-id-check branch from 0624663 to e3d4fe4 Compare October 19, 2026 14:01
@DDINGJOO
Copy link
Copy Markdown
Contributor Author

@mposolda Thanks for the approval! The CI build failed on Spotless (import order in the new test), so I amended the commit with mvn spotless:apply. The only change is moving the org.keycloak import to the top; it's still a single commit. Sorry for the extra round.

Copilot AI left a comment
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The focused fix restores the intended validation contract and includes regression coverage for every constructor argument.

No open issues 🎉

Review effort: Balanced

@mposolda
mposolda merged commit 082ead2 into keycloak:main Oct 19, 2026
159 of 161 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

AccessTokenContext does not reject a null rawTokenId

3 participants

0