-
Notifications
You must be signed in to change notification settings - Fork 217
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
base: master
Are you sure you want to change the base?
Add checks to protect the internal claims used by MIW. Ref: issue #2968 #3131
Conversation
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
@bgavrilMS / @jennyf19 / @jmprieur please review. Thank you! |
@microsoft-github-policy-service agree |
There was a problem hiding this 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
src/Microsoft.Identity.Web.OWIN/InternalClaimDetectedException.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.Identity.Web.OWIN/Microsoft.Identity.Web.OWIN.xml
Outdated
Show resolved
Hide resolved
src/Microsoft.Identity.Web.OWIN/InternalClaimDetectedException.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.Identity.Web.OWIN/InternalClaimDetectedException.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.Identity.Web/WebAppExtensions/MicrosoftIdentityWebAppAuthenticationBuilder.cs
Outdated
Show resolved
Hide resolved
LGTM, I only have minor comments and resolving @msbw2 's comments |
src/Microsoft.Identity.Web/WebAppExtensions/MicrosoftIdentityWebAppAuthenticationBuilder.cs
Show resolved
Hide resolved
Update the description based on PR review Co-authored-by: Bogdan Gavril <[email protected]>
@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. |
ClaimsType should never be treated as case insensitive |
I think claim names should be case sensitive at least as per JWT spec. IdentityModel also treats them as case sensstive. |
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. |
/// <param name="claimType">The claim type</param> | ||
/// <param name="claimValue">The claim value</param> | ||
/// <exception cref="AuthenticationException">The <see cref="ClaimsIdentity"/> contains internal claims that are used internal use by this library</exception> | ||
private static void RejectInternalClaims(ClaimsIdentity identity, string claimType, string claimValue) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@DOMZE I am not clear on the intent, can you please clarify? Why are we comparing the claim value? My understanding is that we should just call FindFirst and if it returns something, then throw an exception because that claim is user-provided.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was suggested by @bgavrilMS that if an internal claim is found in the ID Token and the value of the claim in the ID Token matches what's in the client_info, then we shouldn't throw an exception as they match.
But happy to revisit if the team is not aligned.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this 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.
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)