Validate iss and aud claims on AAD/B2C OIDC login ID token decoders#49423
Merged
rujche merged 3 commits intoJun 11, 2026
Conversation
AadOidcIdTokenDecoderFactory and AadB2cOidcIdTokenDecoderFactory previously only verified the token signature and expiry on the oauth2Login path, never validating the iss (issuer) or aud (audience) claims. This allowed users from unauthorized tenants to sign in to multi-tenant applications that rely on the issuer/tenant claim for tenant restriction. Both factories now set a JWT validator that runs OidcIdTokenValidator (audience, expiry, issued-at, subject) plus issuer validation. For AAD single-tenant the issuer must belong to the configured tenant; for multi-tenant (common/organizations/consumers) the issuer must be a trusted Microsoft issuer consistent with the token's own tid claim. B2C validates against the trusted B2C issuers.
Contributor
There was a problem hiding this comment.
Pull request overview
This PR strengthens Spring Cloud Azure’s oauth2Login ID token validation for both AAD and AAD B2C by adding explicit iss (issuer) and aud (audience) claim validation in the ID token decoder factories. This closes a gap where previously only signature and timestamp checks were performed, allowing tokens from unauthorized tenants to be accepted in some multi-tenant configurations.
Changes:
- Update
AadOidcIdTokenDecoderFactoryto applyOidcIdTokenValidator(standard OIDC ID token claim checks) plus issuer validation (single-tenant: configured tenant; multi-tenant: issuer must match a trusted Microsoft issuer consistent withtid). - Update
AadB2cOidcIdTokenDecoderFactoryto applyOidcIdTokenValidatorplus issuer validation against trusted B2C issuers derived from configured tenant/user flows. - Add focused unit tests for both factories and document the fix in
sdk/spring/CHANGELOG.md.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| sdk/spring/spring-cloud-azure-autoconfigure/src/main/java/com/azure/spring/cloud/autoconfigure/implementation/aadb2c/security/AadB2cOidcIdTokenDecoderFactory.java | Adds OIDC ID token claim validation + B2C issuer validation to the login ID token decoder. |
| sdk/spring/spring-cloud-azure-autoconfigure/src/main/java/com/azure/spring/cloud/autoconfigure/implementation/aadb2c/configuration/AadB2cAutoConfiguration.java | Wires AadB2cProperties into the decoder factory bean so issuer validation can be configured. |
| sdk/spring/spring-cloud-azure-autoconfigure/src/main/java/com/azure/spring/cloud/autoconfigure/implementation/aad/security/AadOidcIdTokenDecoderFactory.java | Adds OIDC ID token claim validation + single-tenant/multi-tenant issuer validation, caching decoders per registration. |
| sdk/spring/spring-cloud-azure-autoconfigure/src/main/java/com/azure/spring/cloud/autoconfigure/implementation/aad/configuration/AadOAuth2ClientConfiguration.java | Updates bean construction to pass AadAuthenticationProperties into the updated decoder factory constructor. |
| sdk/spring/spring-cloud-azure-autoconfigure/src/test/java/com/azure/spring/cloud/autoconfigure/implementation/aadb2c/security/AadB2cOidcIdTokenDecoderFactoryTests.java | New unit tests validating trusted/untrusted issuer behavior and audience rejection for B2C login tokens. |
| sdk/spring/spring-cloud-azure-autoconfigure/src/test/java/com/azure/spring/cloud/autoconfigure/implementation/aad/security/AadOidcIdTokenDecoderFactoryTests.java | New unit tests for single-tenant and multi-tenant issuer validation logic and audience rejection. |
| sdk/spring/CHANGELOG.md | Records the security/bug fix for oauth2Login ID token issuer/audience validation. |
Member
Author
|
/azp run java - spring - tests |
|
Azure Pipelines successfully started running 1 pipeline(s). |
Member
Author
|
/azp run java - spring - tests |
|
Azure Pipelines successfully started running 1 pipeline(s). |
Netyyyy
approved these changes
Jun 11, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
AadOidcIdTokenDecoderFactory and AadB2cOidcIdTokenDecoderFactory previously only verified the token signature and expiry on the oauth2Login path, never validating the iss (issuer) or aud (audience) claims. This allowed users from unauthorized tenants to sign in to multi-tenant applications that rely on the issuer/tenant claim for tenant restriction.
Both factories now set a JWT validator that runs OidcIdTokenValidator (audience, expiry, issued-at, subject) plus issuer validation. For AAD single-tenant the issuer must belong to the configured tenant; for multi-tenant (common/organizations/consumers) the issuer must be a trusted Microsoft issuer consistent with the token's own tid claim. B2C validates against the trusted B2C issuers.
All SDK Contribution checklist:
General Guidelines and Best Practices
Testing Guidelines