Skip to content

Security improvements in Spring Cloud Azure AAD#49033

Merged
rujche merged 31 commits intomainfrom
rujche/main/fix-issue-in-AadJwtIssuerValidator.trustedIssuerRepoValidIssuer
May 7, 2026
Merged

Security improvements in Spring Cloud Azure AAD#49033
rujche merged 31 commits intomainfrom
rujche/main/fix-issue-in-AadJwtIssuerValidator.trustedIssuerRepoValidIssuer

Conversation

@rujche
Copy link
Copy Markdown
Member

@rujche rujche commented May 4, 2026

This pull request introduces breaking changes to Azure Active Directory (AAD) resource server configuration in the Spring Cloud Azure autoconfigure module, primarily strengthening security by requiring explicit tenant configuration and enforcing audience validation by default. The changes also update related tests and documentation to reflect these new requirements.

Breaking changes to AAD resource server configuration:

  • The resource server now requires spring.cloud.azure.active-directory.profile.tenant-id to be set to a specific, non-reserved tenant ID. Using empty, common, organizations, or consumers values will cause application startup to fail with an IllegalArgumentException. [1]], [2]])
  • The AadAuthenticationFilter now enables explicit audience validation by default. JWT tokens must have an aud claim matching either the configured client ID or App ID URI; tokens for other audiences are rejected. [1]], [2]], [3]])

Security improvements:

Documentation and error messaging:

  • The changelog and exception messages are updated to clearly communicate the new requirements and error scenarios. [1]], [2]])

Test updates:

  • Unit tests and context runners are updated to require an explicit tenant ID in their property values, ensuring test coverage for the new validation logic. [1]], [2]], [3]], [4]])

These changes enforce best security practices for OAuth2/OIDC resource servers and prevent misconfiguration or cross-application token acceptance.

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 4, 2026 04:39
@rujche rujche requested review from a team, Netyyyy, moarychan and saragluna as code owners May 4, 2026 04:39
@rujche rujche self-assigned this May 4, 2026
@rujche rujche added azure-spring All azure-spring related issues azure-spring-aad Spring active directory related issues. labels May 4, 2026
@rujche rujche moved this from Todo to In Progress in Spring Cloud Azure May 4, 2026
@rujche rujche added this to the 2026-06 milestone May 4, 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 tightens default AAD JWT validation behavior in spring-cloud-azure-autoconfigure by enforcing tenant-aware issuer validation for single-tenant resource servers and enabling explicit audience validation by default in AadAuthenticationFilter.

Changes:

  • Wire AadResourceServerConfiguration issuer validation to use AadTrustedIssuerRepository for single-tenant tenant IDs while preserving legacy prefix-based issuer validation for common/organizations/consumers.
  • Change AadAuthenticationFilter default constructors to enable explicit audience checking by default.
  • Add/update tests covering the new default behaviors.

Reviewed changes

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

Show a summary per file
File Description
sdk/spring/spring-cloud-azure-autoconfigure/src/main/java/com/azure/spring/cloud/autoconfigure/implementation/aad/filter/AadAuthenticationFilter.java Switch constructor defaults to enable explicit audience validation.
sdk/spring/spring-cloud-azure-autoconfigure/src/main/java/com/azure/spring/cloud/autoconfigure/implementation/aad/configuration/AadResourceServerConfiguration.java Use trusted-issuer exact matching for single-tenant issuer validation; keep multi-tenant legacy behavior.
sdk/spring/spring-cloud-azure-autoconfigure/src/test/java/com/azure/spring/cloud/autoconfigure/implementation/aad/filter/AadAuthenticationFilterTests.java Add tests validating constructor defaults for explicit audience checking.
sdk/spring/spring-cloud-azure-autoconfigure/src/test/java/com/azure/spring/cloud/autoconfigure/implementation/aad/configuration/AadResourceServerConfigurationTests.java Add tests validating single-tenant vs multi-tenant issuer validator wiring.
sdk/spring/CHANGELOG.md Document the hardened defaults in changelog.

Comment thread sdk/spring/CHANGELOG.md Outdated
@rujche
Copy link
Copy Markdown
Member Author

rujche commented May 4, 2026

@copilot apply changes based on the comments in this thread

…pplication, fix changelog link

Agent-Logs-Url: https://github.com/Azure/azure-sdk-for-java/sessions/ac6fd8b6-366e-4630-bcaf-fee4ad6e62c3

Co-authored-by: rujche <171773178+rujche@users.noreply.github.com>
Copy link
Copy Markdown
Contributor

Copilot AI commented May 4, 2026

@copilot apply changes based on the comments in this thread

Applied all three changes from the review thread in commit 3d2b4b46:

  1. Import ordering (AadAuthenticationFilterTests.java): Moved ReflectionTestUtils import before the static imports block.
  2. Centralized isMultiTenantsApplication (AadAuthenticationProperties): Changed the method to public static so it can be shared, and updated AadResourceServerConfiguration to call AadAuthenticationProperties.isMultiTenantsApplication(tenantId) — removing the duplicate private method.
  3. CHANGELOG link (CHANGELOG.md): Fixed the label from [49032] to ([#49033](...)) to match the standard format.

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 6 out of 6 changed files in this pull request and generated 1 comment.

@rujche
Copy link
Copy Markdown
Member Author

rujche commented May 6, 2026

Ignore the test failure about java - spring - ci (Build Test ubuntu2404_121_NotFromSource_TestsOnly), it's a know issue: #48622

Copilot finished work on behalf of rujche May 6, 2026 01:32
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 11 out of 11 changed files in this pull request and generated 2 comments.

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 11 out of 11 changed files in this pull request and generated 1 comment.

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
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 11 out of 11 changed files in this pull request and generated 2 comments.

@rujche
Copy link
Copy Markdown
Member Author

rujche commented May 7, 2026

@copilot apply changes based on the comments in this thread

1 similar comment
@rujche
Copy link
Copy Markdown
Member Author

rujche commented May 7, 2026

@copilot apply changes based on the comments in this thread

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 11 out of 11 changed files in this pull request and generated no new comments.

@rujche
Copy link
Copy Markdown
Member Author

rujche commented May 7, 2026

@copilot apply changes based on the comments in this thread

1 similar comment
@rujche
Copy link
Copy Markdown
Member Author

rujche commented May 7, 2026

@copilot apply changes based on the comments in this thread

…ion; add uppercase GUID test

Agent-Logs-Url: https://github.com/Azure/azure-sdk-for-java/sessions/065745e5-0b86-4d87-a559-fae10571fc21

Co-authored-by: rujche <171773178+rujche@users.noreply.github.com>
Copy link
Copy Markdown
Contributor

Copilot AI commented May 7, 2026

@copilot apply changes based on the comments in this thread

Fixed in commit 6822bf79. getTrimmedTenantId() now applies .toLowerCase(Locale.ROOT) after .trim(), so an uppercase GUID in configuration is normalized before being used in the tid claim validator and AadTrustedIssuerRepository. A new test testValidateTenantIdNormalizesUppercaseGuid covers the uppercase GUID path.

Copy link
Copy Markdown
Contributor

Copilot AI commented May 7, 2026

@copilot apply changes based on the comments in this thread

Fixed in commit 6822bf79c. getTrimmedTenantId() now applies .toLowerCase(Locale.ROOT) after .trim(), normalizing the configured tenant ID before it is used in the tid claim validator and AadTrustedIssuerRepository. A new test testValidateTenantIdNormalizesUppercaseGuid verifies that an uppercase GUID in configuration is normalized and accepted.

@copilot apply changes based on the comments in this thread

Fixed in commit 6822bf79c. getTrimmedTenantId() now applies .toLowerCase(Locale.ROOT) after .trim(), normalizing the configured tenant ID before it is used in the tid claim validator and AadTrustedIssuerRepository. A new test testValidateTenantIdNormalizesUppercaseGuid verifies that an uppercase GUID in configuration is normalized and accepted.

@copilot apply changes based on the comments in this thread

These changes were already applied in commit 6822bf79. getTrimmedTenantId() now normalizes via trim().toLowerCase(Locale.ROOT), and testValidateTenantIdNormalizesUppercaseGuid covers the uppercase GUID path.

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 11 out of 11 changed files in this pull request and generated no new comments.

@rujche rujche changed the title Security: Enforce tenant-aware issuer validation and enable audience check by default for AAD authentication Security improvements in Spring Cloud Azure AAD May 7, 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 Spring active directory related issues.

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

4 participants