Skip to content

fix(op): guard against nil claims for opaque access tokens in token exchange - #959

Merged
wim07101993 merged 3 commits into
zitadel:mainfrom
ChrisJr404:fix-token-exchange-nil-claims
Aug 27, 2026
Merged

wim07101993 merged 3 commits into
zitadel:mainfrom
ChrisJr404:fix-token-exchange-nil-claims

Conversation

@ChrisJr404

Copy link
Copy Markdown
Contributor

Fixes #704.

Doing a token exchange with an opaque access token panics. When the token is an encrypted tokenID:subject string rather than a JWT, getTokenIDAndClaims returns nil claims with ok true, and GetTokenIDAndSubjectFromToken then dereferences that nil pointer on accessTokenClaims.Claims.

I added a nil guard so opaque tokens come back with empty claims (there are no JWT claims to read in that case), and a test for the opaque path since, as the issue mentions, it wasn't covered before.

ChrisJr404 and others added 2 commits August 25, 2026 02:01
…xchange

Exchanging an opaque access token (an encrypted tokenID:subject string)
panicked, because getTokenIDAndClaims returns nil claims with ok true and
the caller dereferenced them unconditionally. Skip the dereference when
there are no claims and add a test covering that path.

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.

Pull request overview

Fixes a panic in the token-exchange flow when the exchanged access token is opaque (encrypted tokenID:subject) rather than a JWT, by guarding against nil access-token claims and adding a regression test for that path.

Changes:

  • Add a nil-check in GetTokenIDAndSubjectFromToken to avoid dereferencing accessTokenClaims when opaque tokens return (nil, ok=true).
  • Add a unit test covering opaque access tokens to ensure the function does not panic and correctly returns token ID + subject.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
pkg/op/token_exchange.go Adds a nil guard so opaque access tokens don’t cause a panic when claims are absent.
pkg/op/token_exchange_test.go Adds a regression test for the opaque access-token code path.

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

Comment thread pkg/op/token_exchange_test.go Outdated
Co-authored-by: Copilot Autofix powered by AI <[email protected]>
@wim07101993

Copy link
Copy Markdown
Member

Thank you for the contribution. Will merge.

@wim07101993
wim07101993 merged commit 611e1a6 into zitadel:main Aug 27, 2026
6 checks passed
@github-actions

Copy link
Copy Markdown

🎉 This PR is included in version 3.49.3 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: null pointer exception in GetTokenIDAndSubjectFromToken

3 participants