Skip to content

Security: Harden B2C resource server token validation defaults#49252

Merged
rujche merged 3 commits into
mainfrom
rujche/main/fix-problems-in-AadB2cResourceServerAutoConfiguration
May 25, 2026
Merged

Security: Harden B2C resource server token validation defaults#49252
rujche merged 3 commits into
mainfrom
rujche/main/fix-problems-in-AadB2cResourceServerAutoConfiguration

Conversation

@rujche
Copy link
Copy Markdown
Member

@rujche rujche commented May 25, 2026

Description

Summary

This PR fixes security gaps in B2C resource-server JWT validation by mirroring the hardening introduced for AAD in #49033.

The previous B2C default configuration could accept tokens from unintended issuers because:

  • tenant-id values such as common were not rejected,
  • tid claim validation was missing,
  • audience validation used a containsAll predicate that allowed unsafe cases,
  • B2C trusted issuers inherited default AAD issuer entries.

What changed

1. Enforced tenant-id validation in B2C resource server

Updated AadB2cResourceServerAutoConfiguration to reject null/empty/reserved tenant IDs (common, organizations, consumers) and normalize tenant ID for comparison.

2. Added tid claim validator

Added JwtClaimValidator<String>(AadJwtClaimNames.TID, tenantId::equals) to bind tokens to the configured tenant.

3. Hardened aud claim predicate

Replaced validAudiences::containsAll with a strict predicate requiring:

  • non-null audience claim,
  • non-empty audience list,
  • at least one audience matching configured valid audiences.

4. Removed unintended AAD issuer inheritance from B2C trusted issuer repository

Refactored AadTrustedIssuerRepository with an overload that can skip default AAD issuer seeding.
AadB2cTrustedIssuerRepository now calls the new constructor with includeAadIssuers=false, so B2C trusts only B2C issuers it explicitly adds.

Tests

Added/updated tests in AadB2cResourceServerAutoConfigurationTests to verify:

  • invalid tenant IDs are rejected at startup,
  • B2C trusted issuers do not contain AAD-line issuers.

Executed tests:

  • mvn -pl spring-cloud-azure-autoconfigure -Dtest=AadB2cResourceServerAutoConfigurationTests test
  • mvn -pl spring-cloud-azure-autoconfigure test

Result:

  • BUILD SUCCESS
  • full artifact run: Tests run: 1090, Failures: 0, Errors: 0, Skipped: 7

Impact

This change prevents cross-issuer acceptance paths in the B2C resource-server default configuration and aligns B2C token validation posture with recent AAD hardening.

All SDK Contribution checklist:

  • The pull request does not introduce [breaking changes]
  • CHANGELOG is updated for new features, bug fixes or other significant changes.
  • I have read the contribution guidelines.

General Guidelines and Best Practices

  • Title of the pull request is clear and informative.
  • There are a small number of commits, each of which have an informative message. This means that previously merged commits do not appear in the history of the PR. For more information on cleaning up the commits in your PR, see this page.

Testing Guidelines

  • Pull request includes test coverage for the included changes.

Copilot AI review requested due to automatic review settings May 25, 2026 01:52
@rujche rujche requested review from a team, Netyyyy, moarychan and saragluna as code owners May 25, 2026 01:52
@github-actions github-actions Bot added the azure-spring All azure-spring related issues label May 25, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR hardens Azure AD B2C resource-server JWT validation defaults in spring-cloud-azure-autoconfigure, aligning B2C validation behavior with the earlier AAD security hardening (e.g., explicit tenant binding, stricter aud validation, and issuer trust scoping).

Changes:

  • Enforced B2C tenant-id validation (rejecting common/organizations/consumers and empty values) and normalized tenant-id for comparisons.
  • Added a tid claim validator and replaced permissive aud validation (containsAll) with a strict “any configured audience matches” predicate.
  • Prevented B2C trusted issuer repositories from inheriting default AAD issuer entries, and added/updated tests for the new behavior.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.

File Description
sdk/spring/spring-cloud-azure-autoconfigure/src/main/java/com/azure/spring/cloud/autoconfigure/implementation/aadb2c/configuration/AadB2cResourceServerAutoConfiguration.java Adds tenant-id validation/normalization, tid claim validation, and hardens aud claim validation for B2C JWT decoding.
sdk/spring/spring-cloud-azure-autoconfigure/src/main/java/com/azure/spring/cloud/autoconfigure/implementation/aad/security/jwt/AadTrustedIssuerRepository.java Introduces an overload/constructor path to optionally skip default AAD issuer seeding (enabling B2C to avoid inheriting AAD issuers).
sdk/spring/spring-cloud-azure-autoconfigure/src/main/java/com/azure/spring/cloud/autoconfigure/implementation/aadb2c/security/jwt/AadB2cTrustedIssuerRepository.java Uses the new issuer-repo constructor to exclude default AAD issuers and normalizes tenant-id passed to the base repository.
sdk/spring/spring-cloud-azure-autoconfigure/src/test/java/com/azure/spring/cloud/autoconfigure/implementation/aadb2c/configuration/AadB2cResourceServerAutoConfigurationTests.java Adds assertions that B2C trusted issuers don’t include AAD issuers and verifies startup failure for invalid/empty tenant-id values.

@rujche rujche self-assigned this May 25, 2026
@rujche rujche added the azure-spring-aad-b2c Spring active directory b2c related issues. label May 25, 2026
@rujche rujche moved this from Todo to In Progress in Spring Cloud Azure May 25, 2026
@rujche rujche added this to the 2026-06 milestone May 25, 2026
@rujche rujche requested a review from Copilot May 25, 2026 01:58
@rujche rujche added the bug This issue requires a change to an existing behavior in the product in order to be resolved. label May 25, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

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

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

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

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

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

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated no new comments.

@rujche
Copy link
Copy Markdown
Member Author

rujche commented May 25, 2026

/azp run java - spring - tests

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

@rujche rujche merged commit 13bd94b into main May 25, 2026
88 checks passed
@rujche rujche deleted the rujche/main/fix-problems-in-AadB2cResourceServerAutoConfiguration branch May 25, 2026 07:23
@github-project-automation github-project-automation Bot moved this from In Progress to Done in Spring Cloud Azure May 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

azure-spring All azure-spring related issues azure-spring-aad-b2c Spring active directory b2c related issues. bug This issue requires a change to an existing behavior in the product in order to be resolved.

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants