Skip to content

fix: preserve ID token claims over UserInfo response claims#19

Merged
tphakala merged 1 commit intomasterfrom
fix/oidc-userinfo-claim-priority
Mar 15, 2026
Merged

fix: preserve ID token claims over UserInfo response claims#19
tphakala merged 1 commit intomasterfrom
fix/oidc-userinfo-claim-priority

Conversation

@tphakala
Copy link
Owner

@tphakala tphakala commented Mar 15, 2026

Summary

  • Change UserInfo claim merge to only add claims not already present in the ID token
  • ID token claims (cryptographically signed) now take precedence over UserInfo claims (unsigned)

Security impact: Previously, a compromised UserInfo endpoint could overwrite signed ID token claims (e.g., email), allowing identity spoofing while the sub claim still matched.

Test plan

  • go test ./providers/openidConnect/... -v passes
  • New Test_GetUserInfo_PreservesIDTokenClaims verifies ID token email is preserved when UserInfo returns a different email, and new claims from UserInfo are still added

Summary by CodeRabbit

  • Bug Fixes

    • Fixed OpenID Connect merge logic so existing ID token claims are preserved and not overwritten by UserInfo data.
  • Tests

    • Added test coverage to verify ID token claims remain intact while new UserInfo fields are merged.

@gemini-code-assist
Copy link

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request strengthens the security posture of OpenID Connect authentication by modifying how user claims are processed. It ensures that claims obtained from the cryptographically signed ID token are never overwritten by claims from the UserInfo endpoint, thereby preventing potential identity spoofing if the UserInfo endpoint were to be compromised.

Highlights

  • Claim Precedence: ID token claims are now prioritized over UserInfo response claims, ensuring that cryptographically signed claims take precedence over unsigned ones.
  • UserInfo Claim Merging: UserInfo claims are now merged only if they are not already present in the ID token, preventing overwrites of existing signed claims.
  • Security Enhancement: This change mitigates a security vulnerability where a compromised UserInfo endpoint could overwrite signed ID token claims, preventing potential identity spoofing.
Changelog
  • providers/openidConnect/openidConnect.go
    • Modified the getUserInfo function to only add UserInfo claims if they are not already present in the ID token's claims map.
    • Added comments explaining the new claim merging logic and its security implications.
  • providers/openidConnect/openidConnect_test.go
    • Introduced Test_GetUserInfo_PreservesIDTokenClaims to verify that ID token claims (specifically 'email') are preserved when UserInfo returns a different value, while new claims from UserInfo are still added.
Activity
  • The author provided a clear summary of changes and their security impact.
  • A detailed test plan was included, outlining existing and new tests.
  • A new unit test, Test_GetUserInfo_PreservesIDTokenClaims, was added to validate the core logic change.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@coderabbitai
Copy link

coderabbitai bot commented Mar 15, 2026

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: a269cdf4-3f8e-4245-b153-ca4b1aa463e7

📥 Commits

Reviewing files that changed from the base of the PR and between 0839c1a and c26cb25.

📒 Files selected for processing (2)
  • providers/openidConnect/openidConnect.go
  • providers/openidConnect/openidConnect_test.go

Walkthrough

Updated OpenID Connect provider claim merging: getUserInfo now preserves existing ID token claims and only adds UserInfo claims for keys not present in the ID token. A unit test was added to verify this preservation and augmentation behavior.

Changes

Cohort / File(s) Summary
Claim Merging Logic
providers/openidConnect/openidConnect.go
Modified getUserInfo to avoid overwriting existing ID token claims when merging UserInfo claims; added comments clarifying ID token precedence.
Test Coverage
providers/openidConnect/openidConnect_test.go
Added Test_GetUserInfo_PreservesIDTokenClaims to assert ID token claims are preserved and additional UserInfo claims are merged.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: preserving ID token claims over UserInfo response claims during the merge operation.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/oidc-userinfo-claim-priority
📝 Coding Plan
  • Generate coding plan for human review comments

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request addresses a security vulnerability by ensuring that cryptographically signed ID token claims are not overwritten by claims from the UserInfo endpoint. The implementation correctly prioritizes the ID token claims. A new test is added to verify this behavior. The changes are well-implemented, and I have one suggestion to improve the robustness of the new test case.

Comment on lines +224 to +228
provider, _ := NewCustomisedURL(
"client_id", "client_secret", "http://localhost/callback",
"https://example.com/auth", "https://example.com/token",
"https://example.com", userInfoServer.URL, "",
)

Choose a reason for hiding this comment

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

medium

It's good practice to check for errors returned from functions, even in tests, to make them more robust. While NewCustomisedURL currently doesn't return an error, its signature allows for it, and this could change in the future. It would be safer to handle the potential error.

Suggested change
provider, _ := NewCustomisedURL(
"client_id", "client_secret", "http://localhost/callback",
"https://example.com/auth", "https://example.com/token",
"https://example.com", userInfoServer.URL, "",
)
provider, err := NewCustomisedURL(
"client_id", "client_secret", "http://localhost/callback",
"https://example.com/auth", "https://example.com/token",
"https://example.com", userInfoServer.URL, "",
)
a.NoError(err)
References
  1. Use the testify package for assertions in tests to maintain consistency with the existing codebase.

Copy link
Owner Author

Choose a reason for hiding this comment

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

Fixed in latest push — now checks a.NoError(err) on NewCustomisedURL.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
providers/openidConnect/openidConnect_test.go (1)

224-229: Assert provider construction error in test setup.

Line [224] currently discards NewCustomisedURL error. Please assert it (a.NoError(err)) so setup failures fail fast and don’t cascade into misleading assertion errors.

Suggested patch
-	provider, _ := NewCustomisedURL(
+	provider, err := NewCustomisedURL(
 		"client_id", "client_secret", "http://localhost/callback",
 		"https://example.com/auth", "https://example.com/token",
 		"https://example.com", userInfoServer.URL, "",
 	)
+	a.NoError(err)
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@providers/openidConnect/openidConnect_test.go` around lines 224 - 229, The
test currently discards the error returned by NewCustomisedURL; change the call
to capture the error (e.g., provider, err := NewCustomisedURL(...)) and assert
it with a.NoError(err) immediately after construction so setup failures fail
fast and don't produce cascading test errors; reference the NewCustomisedURL
call and the provider variable in the change.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@providers/openidConnect/openidConnect_test.go`:
- Around line 224-229: The test currently discards the error returned by
NewCustomisedURL; change the call to capture the error (e.g., provider, err :=
NewCustomisedURL(...)) and assert it with a.NoError(err) immediately after
construction so setup failures fail fast and don't produce cascading test
errors; reference the NewCustomisedURL call and the provider variable in the
change.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 7e10a5b7-e8cf-4a4e-bb26-1da33e127d96

📥 Commits

Reviewing files that changed from the base of the PR and between d37c475 and 0839c1a.

📒 Files selected for processing (2)
  • providers/openidConnect/openidConnect.go
  • providers/openidConnect/openidConnect_test.go

@tphakala
Copy link
Owner Author

/gemini review

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request addresses a security vulnerability by ensuring that claims from a signed ID token are not overwritten by claims from an unsigned UserInfo response. The change modifies the claim merging logic to only add new claims from the UserInfo endpoint if they don't already exist. A new test case has been added to verify this behavior, confirming that existing claims are preserved and new ones are added correctly. The changes are logical, well-implemented, and properly tested.

@tphakala tphakala enabled auto-merge (squash) March 15, 2026 12:19
@tphakala tphakala force-pushed the fix/oidc-userinfo-claim-priority branch from 22d0905 to d6e8310 Compare March 15, 2026 12:37
Previously, UserInfo response claims overwrote ID token claims. Since
ID token claims are cryptographically signed and UserInfo claims are
not, the signed claims should take precedence. UserInfo claims are now
only added when not already present in the ID token.
@tphakala tphakala force-pushed the fix/oidc-userinfo-claim-priority branch from d6e8310 to c26cb25 Compare March 15, 2026 12:38
@tphakala tphakala merged commit 2e41a52 into master Mar 15, 2026
14 of 15 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.

1 participant