8000 Custom OIDC identity providers parse email_verified from validated tokens when not pre-populated in context by msdaly200 · Pull Request #54268 · keycloak/keycloak · GitHub
[go: up one dir, main page]

Skip to content

Custom OIDC identity providers parse email_verified from validated tokens when not pre-populated in context - #54268

Merged
rmartinc merged 1 commit into
keycloak:mainfrom
msdaly200:54245
Nov 12, 2026
Merged

rmartinc merged 1 commit into
keycloak:mainfrom
msdaly200:54245

Conversation

@msdaly200
Copy link
Copy Markdown
Contributor

Closes #54245

When a provider like GitLab overrides extractIdentity() and stores VALIDATED_ID_TOKEN but not the EMAIL_VERIFIED context entry, an explicit email_verified=false from the ID token is silently ignored. With "Trust Email" enabled, setEmailVerified() finds a null context entry, falls through to the superclass default, and marks the email as verified, the opposite of what the token declared.

Fix:

  • setEmailVerified(): When the EMAIL_VERIFIED context entry is absent, fall back to reading email_verified from the VALIDATED_ID_TOKEN. The context entry still takes precedence when present.
  • extractIdentity(): When userinfo provides an email but omits email_verified, preserve the ID token's value instead of overwriting it with null.

Tests:

  • Added Unit tests to verify context-entry-takes-precedence, fallback-to-token for both true and false, and absent context entry behavior
  • Added Integration test to confirm that email_verified=false in the ID token is preserved when userinfo returns an email without an email_verified claim (the GitLab scenario)

@msdaly200
msdaly200 marked this pull request as ready for review October 22, 2026 14:18
@msdaly200
msdaly200 requested a review from a team as a code owner October 22, 2026 14:18
Copilot AI balanced review requested due to automatic review settings October 22, 2026 14:18
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

Static review found no blocking issues in the focused claim-handling changes or regression tests; tests were not executed.

No open issues 🎉

What changed in this PR

Fixes #54245 by preserving the ID token’s email_verified claim when userinfo or custom OIDC provider context omits it, while keeping explicit context values authoritative.

Changes:

  • Falls back to the validated ID token when the context has no email-verification value.
  • Preserves the token’s value when userinfo supplies an email without email_verified.
  • Adds unit tests for fallback and precedence, plus an integration regression test.
File Description
tests/​base/​src/​test/​java/​org/​keycloak/​tests/​broker/​oidc/​KcOidcBrokerTest.java Tests preservation of the token’s false value when userinfo omits verification.
services/​src/​test/​java/​org/​keycloak/​test/​broker/​oidc/​OIDCIdentityProviderTest.java Tests token fallback and explicit context precedence.
services/​src/​main/​java/​org/​keycloak/​broker/​oidc/​OIDCIdentityProvider.java Implements token fallback and preserves verification during userinfo extraction.

Review effort: Balanced

@rmartinc rmartinc 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.

Just a nitpick for the test. The rest LGTM.

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.

🟡 Changes recommended

Verification claims can be applied to a different email address, incorrectly clearing existing verification during FORCE synchronization.

1 open issue

Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings October 22, 2026 15:18
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.

🔵 Needs a closer look

Human review is needed to confirm that token verification claims remain valid for the selected email address.

1 open issue

Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings October 22, 2026 15:36
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.

🟡 Changes recommended

The mismatched-email guard mutates validated token claims consumed by downstream attribute and role mappers.

1 open issue
1 resolved since last review

Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings October 23, 2026 00:29
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

No blocking issues were identified in the focused fallback logic, address-mismatch guards, regression coverage, or upgrade guidance.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

@rmartinc rmartinc 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.

Thanks @msdaly200! Just one comment, as the equals returns true when null I think we should check the token email is not null. In the other path we are checking the userInfoEmail is not null previously.

@msdaly200
msdaly200 requested review from a team as code owners October 27, 2026 13:07
Copilot AI balanced review requested due to automatic review settings October 27, 2026 13:07
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.

🔵 Needs a closer look

Security-sensitive email trust and synchronization changes warrant human review, with regression-test corrections still needed.

2 open issues

Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings October 29, 2026 10:27
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

No active review issues have been identified for this change.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

@rmartinc rmartinc added the status/hold PR should not be merged. On hold for later. label Oct 29, 2026
@rmartinc
Copy link
Copy Markdown
Contributor

This one is ready but we need to wait to the next patch and move the notes to the proper version when everything is released. Thanks @msdaly200!

Copilot AI balanced review requested due to automatic review settings November 9, 2026 15:38
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

No active review issues are reported for the OIDC email-verification claim preservation and token fallback changes.

No open issues 🎉

Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings November 9, 2026 15:50
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.

🟡 Changes recommended

The custom-extractor fallback still lets Trust Email verify a new user's email when the token has email_verified=false but no email, and the unit test currently expects this incorrect behavior.

1 open issue

Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings November 9, 2026 16:22
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.

🔵 Needs a closer look

The guard still ignores email_verified=false when an overridden extractor supplies the email but the ID token omits it, allowing Trust Email to incorrectly verify the profile email; the new test does not cover this path.

1 open issue

Review effort: Balanced

@msdaly200 msdaly200 changed the title Preserve email_verified from ID token when userinfo omits it. Custom OIDC identity providers parse email_verified from validated tokens when not pre-populated in context Nov 10, 2026
@mabartos
mabartos requested a review from rmartinc November 10, 2026 13:44
Copilot AI balanced review requested due to automatic review settings November 12, 2026 08:22
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

No active review issues are recorded for the OIDC email-verification fallback changes.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

@mabartos mabartos left a comment
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@msdaly200 I don't see any issue with this approach. LGTM, thanks!

@rmartinc rmartinc 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.

Thanks @msdaly200 and @mabartos!

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

Labels

status/hold PR should not be merged. On hold for later. team/core-authn

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Custom OIDC identity providers parse email_verified from validated tokens when not pre-populated in context

4 participants

0