-
Notifications
You must be signed in to change notification settings - Fork 5k
[API Proposal]: ClaimsIdentity to perform case-sensitive comparison #113562
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
Comments
Tagging subscribers to this area: @dotnet/area-system-security, @bartonjs, @vcsjones |
@bartonjs Please invite @pmaytak and @keegan-caruso to the API Review session for when this bubbles to the top of the queue and make sure it has my attention for me to attend as well. Thank you in advance. |
I worry about how this change would affect libraries that run on both .NET Core and .NET Framework. New overloads for FindAll etc. could be polyfilled on .NET Framework but it would not be possible to construct a case-sensitive ClaimsIdentity on .NET Framework. So a library that constructs identities would have to decide whether to have different behaviour on different target frameworks or abstain from using the new constructors. |
namespace System.Security.Claims
{
public partial class ClaimsIdentity
{
public ClaimsIdentity(
IIdentity? identity = null,
IEnumerable<Claim>? claims = null,
string? authenticationType = null,
string? nameType = null,
string? roleType = null,
StringComparison stringComparison = StringComparison.OrdinalIgnoreCase);
}
} |
I took a quick look at implementing this
The compelling reason (to me) is that a derived type has no way to respect the
|
Either ClaimsIdentity was constructed directly ( |
Background and motivation
Certain means of representing and handling of claims, like JWT, treat claim names (i.e. types) in a case-sensitive manner. Current ClaimsIdentity class in .NET compares claim names in a case-insensitive way. The issue could arise, if some application creates a claims identity and multiple claims with names that differ in casing. When retrieving this claim, the user may end up getting either of those claims and inconsistent with their expectations. For example, if there are two claims, "ID, 1" and "Id, 2"; a request to get "Id" claim will return the first one, not the second one.
The goals of these proposed changes is to make sure the users do the right and secure thing; to ensure secure behavior by making case sensitivity an intentional choice when creating a ClaimsIdentity instance; to avoid breaking existing functionality by not changing the default behavior, while still offering a secure alternative.
An earlier issue #83128 was created with a similar proposal.
API Proposal
Updates ClaimsIdentity class.
StringComparison
parameter to all relevant constructors.StringComparison
value is defaulted toStringComparison.OrdinalIgnoreCase
.StringComparison
value is used inFindAll
,FindFirst
,HasClaim
methods.FindAll
,FindFirst
,HasClaim
methods which accepts an additionalStringComparison
parameter.Some examples of the above proposals:
API Usage
Alternative Designs
ClaimsIdentity
class case-sensitive by default.ClaimsIdentity
and with aClaimsIdentity
being a more general purpose type in conceptFindAll
,FindFirst
,HasClaim
methods with predicate overloads which can be customized to do a case-sensitive match.Risks
ClaimsIdentity
API surface area, which could make the class more complex to use.Claim
object reference). Although, the same difference exists between find and add and remove operations today.The text was updated successfully, but these errors were encountered: