Anti Forgery Claim Extractor: option to define claim name
See original GitHub issueBackground and Motivation
In a project that uses anti forgery features and 3rd party authentication provider, I found you can get anti forgery token validation failures in certain scenarios (auth provider does not use sub, nameidentifier or upn claims, whilst the iat claim value has changed).
If we could configure the name(s) of claims we want to use in the DefaultClaimUidExtractor class, we could fix the issue without having to change the configuration of the auth provider.
Proposed API
services.AddAntiForgery(options =>
options.UidClaimNames = new string[] { "myUniqueUserClaim" }
);
Alternative Designs
Tell the framework that there is an iat claim, then update DefaultClaimUidExtractor to not include the claim in the extraction.
services.AddAntiForgery(options =>
options.IatClaims = new string[] { "iat" }
);
Risks
Developers could configure a claim that is not unique to the user.
Issue Analytics
- State:
- Created 8 months ago
- Reactions:1
- Comments:6 (4 by maintainers)
Top Results From Across the Web
c# - Anti-forgery token issues
Starting with MVC4 the anti-forgery-token doesn't use User.Identity.Name as the unique identifier. Instead it looks for the two claims given ...
Read more >How to Include AntiForgeryToken for MVC Integration Testing
Once we do this, we can extract those properties from the HTML response by using the same names as declared in the AntiForgeryTokenExtractor ......
Read more >XSRF/CSRF Prevention in ASP.NET MVC and Web Pages
Cross-site request forgery (also known as XSRF or CSRF) is an attack against web-hosted applications whereby a malicious web site can ...
Read more >AntiForgeryToken: A Claim of Type NameIdentifier or ...
Name as anti-forgery token to validate form submitted. Worth to note that by default, ASP.NET MVC is not Claims-aware app.
Read more >Claims-based authentication in MVC4 with .NET4.5 C# part 1
The incoming ClaimsPrincipal object is the outcome of the authentication; it represents the User that has just been authenticated on the login ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Triage: This API would be a nice to have given more interest in it. Anyone interested in seeing this can give the issue a thumbs up to help us prioritize.
Nice, that would sort it. I would definitely forget why that middleware exists and delete it in a couple of years though 😜 We’re getting the auth service admins to add/remove claims, saves us a few lines of code