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

Update anti-request-forgery.md #34449

Merged
merged 2 commits into from
Jan 13, 2025
Merged

Update anti-request-forgery.md #34449

merged 2 commits into from
Jan 13, 2025

Conversation

Rick-Anderson
Copy link
Contributor

@Rick-Anderson Rick-Anderson commented Jan 8, 2025

Fixes #25564

@Tobikblom please review


Internal previews

📄 File 🔗 Preview link
aspnetcore/security/anti-request-forgery.md aspnetcore/security/anti-request-forgery

Copy link

@Tobikblom Tobikblom left a comment

Choose a reason for hiding this comment

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

See comments.

Consider alternative CSRF protection patterns if this poses an issue.
Multiple tabs logged in as different users, or one logged in as anonymous, are not supported.

With the Synchronizer Token Pattern, only the most recently posted page is guaranteed to contain a valid antiforgery token. Apps that wish to support multiple tabs should test supported browsers and log failures.
Copy link

@Tobikblom Tobikblom Jan 8, 2025

Choose a reason for hiding this comment

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

I don't believe this (line 164) statement is true; a fresh token is indeed created for each page request, but the token is validated against a security token stored in a cookie which is reused on all requests after it has initially been populated and is only changed upon changing identity.

Identity is to be understood in the broadest sense, i.e., anonymous is considered a form of identity.

Choose a reason for hiding this comment

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

Clarification: "[...] the most recently posted page is guaranteed to contain a valid antiforgery token" is not untrue, but may give the impression that using multiple tabs is a problem, which it really isn't as stated above.

With the Synchronizer Token Pattern, only the most recently loaded page is guaranteed to contain a valid antiforgery token. Apps that wish to support multiple tabs should test supported browsers and log failures. ***Using multiple tabs can be problematic***. For example, if a user opens multiple tabs, requests made from previously loaded tabs might fail with an error: `Antiforgery token validation failed. The antiforgery cookie token and request token do not match`

Consider alternative CSRF protection patterns if this poses an issue.
Multiple tabs logged in as different users, or one logged in as anonymous, are not supported.
Copy link

@Tobikblom Tobikblom Jan 8, 2025

Choose a reason for hiding this comment

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

I would consider scrapping the "Multiple browser tabs and the Synchronizer Token Pattern" section altogether.

I don't see why it would make sense to log in as one user, open another tab and log in as another user, and then expect the other tab to still be in a valid state, nor do I see how this would be specific to antiforgery tokens.

@Rick-Anderson Rick-Anderson enabled auto-merge (squash) January 13, 2025 21:36
@Rick-Anderson Rick-Anderson merged commit 8a730be into main Jan 13, 2025
3 checks passed
@Rick-Anderson Rick-Anderson deleted the Rick-Anderson-patch-12 branch January 13, 2025 21:37
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.

Clarify antiforgery protection behavior around multiple tabs being open
2 participants