Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix AadIssuerValidator's handling of trailing forward slashes #2361

Merged
merged 1 commit into from
Oct 16, 2023

Conversation

halter73
Copy link
Contributor

@halter73 halter73 commented Oct 14, 2023

This fixes errors like the following reported by multiple customers at dotnet/aspnetcore#51005 when they tried to upgrade their app using AddMicrosoftIdentityWebApp to .NET 8.

Issuer: 'https://munsonpickles3.b2clogin.com/f6c04159-d728-43cd-8ae1-c1f3793844d5/v2.0/', does not match any of the valid issuers provided for this application.

While https://login.microsoftonline.com/{TenantId}/v2.0/.well-known/openid-configuration, responds with "issuer": "https://login.microsoftonline.com/{TenantId}/v2.0" and issues JWTs with iss claims containing no trailing slashes, if you use a custom B2C authority like https://{TenantName}.b2clogin.com/{TenantName}.onmicrosoft.com/B2C_1_SignUpSignIn/v2.0/.well-known/openid-configuration you will get "issuer": "https://TenantName}.b2clogin.com/{TenantId}/v2.0/" responses and iss claims with trailing slashes.

This is causing upgrades of Azure B2C customers to .NET 8 to fail because AadIssuerValidator.GetEffectiveConfigurationManager() does not account for trailing slashes. This causes it to query V1 metadata for a V2 token, which causes a mismatch because the V1 metadata does not include a trailing forward slash for the issuer while the V2 token does include a trailing forward slash.

While it looks like this bug has been around for a while, I think the reason customers haven't seen this until upgrading to .NET 8 is because the OpenIdConnectHandler has stopped setting TokenValidationParameters.ValidIssuers. It is now expected expected setting TokenValidationParameters.ConfigurationMager is sufficient as of dotnet/aspnetcore#49542.

In the particular case of people using AadIssuerValidator, this PR is sufficient to fix regression because AadIssuerValidator.Validate falls back to querying the ConfigurationManager itself rather than completely rely on OpenIdConnectHandler.HandleRemoteAuthenticateAsync() having done that already.

However, I am concerned that there could be other custom TokenHander or TokenValidationParameters.IssuerValidator callbacks that read from TokenValidationParameters.ValidIssuers other than AadIssuerValidator, and that don't have the logic to query the ConfigurationManager itself since it was never before necessary.

I'm wondering if we shouldn't also just update the else if (_configuration != null) to be if (_configuration != null) in OpenIdConnectHandler.ValidateTokenUsingHandlerAsync, JwtBearerHandler.SetupTokenValidationParametersAsync and WsFederationHandler.SetupTokenValidationParametersAsync to be extra safe. I assume this would have perf implications though.

@jennyf19 @keegan-caruso @brentschmaltz @eerhardt @mkArtak

@brentschmaltz brentschmaltz merged commit 0134369 into AzureAD:dev Oct 16, 2023
4 checks passed
mkArtakMSFT added a commit to dotnet/aspnetcore that referenced this pull request Oct 18, 2023
…kages to the latest patch release (7.0.3 & 2.15.2) (#51430)

# Update the Microsoft.IdentityModel.* and Microsoft.Identity.Web.* packages to the latest patch release (7.0.3 & 2.15.2)

Update the reference to the Microsoft.IdentityModel.* and Microsoft.Identity.Web.* packages so that we don't regress AAD authentication scenarios for web apps.

## Description

We've hit an issue with AAD authentication in ASP.NET Core web apps, which was resulting in errors during login. This was due to an issue in the IdentityModel package, for which @halter73 has proposed a fix: AzureAD/azure-activedirectory-identitymodel-extensions-for-dotnet#2361
The Identity team has approved the fix and has released a new package to NuGet so that we can update our dependency and **avoid the regression in 8.0**.

Please note, that this change will have to include the soure-build change as well: dotnet/source-build-externals#228

Fixes #51005

## Customer Impact

Customers who will try to use AAD authentication for their ASP.NET Core web applications in 8.0 will fail to login.

## Regression?

- [x] Yes
- [ ] No

This was technically an existing bug, which was already in the IdentityModel package, however only after a recent change #49542 the issue has surfaced impacting 8.0 apps.
 
## Risk

- [ ] High
- [ ] Medium
- [x] Low

From our point of view this is a dependency update. And the dependency has taken only a targeted fix to avoid the bug, going through all the necessary validation on the AAD side.

## Verification

- [x] Manual (required)
- [ ] Automated

## Packaging changes reviewed?

- [ ] Yes
- [ ] No
- [x] N/A

----

## When servicing release/2.1

- [ ] Make necessary changes in eng/PatchConfig.props

---------

Co-authored-by: dotnet-maestro[bot] <dotnet-maestro[bot]@users.noreply.github.com>
Co-authored-by: Stephen Halter <[email protected]>
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.

2 participants