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

Add checks to protect the internal claims used by MIW. Ref: issue #2968 #3131

Merged

Conversation

DOMZE
Copy link
Contributor

@DOMZE DOMZE commented Nov 6, 2024

Add checks to protect the users to not use internal claims used by the library

Summary of the changes (Less than 80 chars)

Description

Introduce InternalClaimDetectedException in Microsoft.Identity.Web and Microsoft.Identity.Web.OWIN namespaces. This exception is thrown when internal ID Token claims (UniqueTenantIdentifier, UniqueObjectIdentifier) are detected in the user's ID Token. Updated AppBuilderExtension.cs and MicrosoftIdentityWebAppAuthenticationBuilder.cs to check for these claims and throw the exception if found. The new exception class includes a property to store the invalid claim

Fixes #2968 (in this specific format)

DOMZE added 2 commits November 5, 2024 15:08
Introduce InternalClaimDetectedException in Microsoft.Identity.Web and Microsoft.Identity.Web.OWIN namespaces. This exception is thrown when internal ID Token claims (UniqueTenantIdentifier, UniqueObjectIdentifier) are detected in the user's ID Token. Updated AppBuilderExtension.cs and MicrosoftIdentityWebAppAuthenticationBuilder.cs to check for these claims and throw the exception if found. The new exception class includes a property to store the invalid claim
@DOMZE DOMZE requested a review from a team as a code owner November 6, 2024 17:07
@DOMZE
Copy link
Contributor Author

DOMZE commented Nov 6, 2024

@bgavrilMS / @jennyf19 / @jmprieur please review.

Thank you!

@DOMZE
Copy link
Contributor Author

DOMZE commented Nov 6, 2024

@microsoft-github-policy-service agree

Copy link

@dstamand-msft dstamand-msft left a comment

Choose a reason for hiding this comment

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

Changes were made in regards to feedback

@jennyf19 jennyf19 added this to the 3.3.2 milestone Nov 8, 2024
@bgavrilMS
Copy link
Member

LGTM, I only have minor comments and resolving @msbw2 's comments

@DOMZE
Copy link
Contributor Author

DOMZE commented Nov 12, 2024

@bgavrilMS @jmprieur @jennyf19 @pmaytak to be able to go forward, we just need your input on claims casing match (type+value/value only) and the changes are done.

Thank you!

@bgavrilMS
Copy link
Member

@bgavrilMS @jmprieur @jennyf19 @pmaytak to be able to go forward, we just need your input on claims casing match (type+value/value only) and the changes are done.

Thank you!

I am fine with case insensitive.

@jennyf19
Copy link
Collaborator

@bgavrilMS @jmprieur @jennyf19 @pmaytak to be able to go forward, we just need your input on claims casing match (type+value/value only) and the changes are done.

Thank you!

ClaimsType should never be treated as case insensitive

@pmaytak
Copy link
Contributor

pmaytak commented Nov 13, 2024

I think claim names should be case sensitive at least as per JWT spec. IdentityModel also treats them as case sensstive.

@pmaytak
Copy link
Contributor

pmaytak commented Nov 14, 2024

Read the issue, thought about this more. When we search for a claim to validate or use, then we should be case sensitive. This way we get the exact claim we're looking for. However, if our intent is to throw an exception if the user specified any variation of utid or uid, then we should use case insensitive approach to broaden the search. This way we ensure that the token only ever has utid and uid variations of claim names.

Copy link
Contributor

@pmaytak pmaytak left a comment

Choose a reason for hiding this comment

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

Not clear on the intent.

@pmaytak pmaytak removed this from the 3.3.2 milestone Nov 14, 2024
@bgavrilMS bgavrilMS requested a review from pmaytak December 9, 2024 14:45
@bgavrilMS bgavrilMS requested a review from Copilot December 22, 2024 09:34

Choose a reason for hiding this comment

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

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

Files not reviewed (8)
  • src/Microsoft.Identity.Web.OWIN/Microsoft.Identity.Web.OWIN.xml: Language not supported
  • src/Microsoft.Identity.Web.TokenAcquisition/PublicAPI/net462/InternalAPI.Shipped.txt: Language not supported
  • src/Microsoft.Identity.Web.TokenAcquisition/PublicAPI/net472/InternalAPI.Shipped.txt: Language not supported
  • src/Microsoft.Identity.Web.TokenAcquisition/PublicAPI/net6.0/InternalAPI.Shipped.txt: Language not supported
  • src/Microsoft.Identity.Web.TokenAcquisition/PublicAPI/net7.0/InternalAPI.Shipped.txt: Language not supported
  • src/Microsoft.Identity.Web.TokenAcquisition/PublicAPI/net8.0/InternalAPI.Shipped.txt: Language not supported
  • src/Microsoft.Identity.Web.TokenAcquisition/PublicAPI/net9.0/InternalAPI.Shipped.txt: Language not supported
  • src/Microsoft.Identity.Web.TokenAcquisition/PublicAPI/netstandard2.0/InternalAPI.Shipped.txt: Language not supported
@pmaytak pmaytak dismissed their stale review January 1, 2025 06:51

Unblocking

@DOMZE DOMZE requested review from pmaytak and bgavrilMS January 2, 2025 19:04
@bgavrilMS bgavrilMS merged commit 4b63b6a into AzureAD:master Jan 3, 2025
1 check passed
@DOMZE DOMZE deleted the domze/fix-issue-2968-claim-already-exist branch January 3, 2025 14:58
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.

[BUG] GetAuthenticationResultForUserAsync throws an exception when user is authenticated
6 participants