-
Notifications
You must be signed in to change notification settings - Fork 10.2k
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 antiforgery (anti-csrf) support to minimal endpoints #38630
Comments
The whole point of our CSRF is a dual token approach, and it's a well understood approach. The cookie is there both for user checks, and also for things coming from other sites, which can happen with shared domain suffixes such as azurewebsites.net However if you want to propose something different @GrabYourPitchforks and I will listen. |
This isn't just for minimal APIs right? It's also for ApiControllers as well? |
Thanks for contacting us. We're moving this issue to the |
As a reminder, CSRF is only a concern for endpoints that use "ambient" authentication. By "ambient" I mean something that flows automatically as part of the request without active consent by the user: cookies, NTLM auth, client certs, etc. For things like standard API calls, where authentication flows as part of a manually added Authorize request header, CSRF is not a concern and no checks are needed. |
Thanks for contacting us. We're moving this issue to the |
#38314 (comment)
Thanks @pranavkm for the Antiforgery middleware PR and the nice description in the comments. And extra thanks to @martincostello for adding support for form file parameters to minimal endpoints with #35158!
Now that it is possible to accept
IFormFile
andIFormFileCollection
parameters in minimal actions, we will need to require an antiforgery token for all authenticated endpoints taking these parameter types. Right now, because we don't check for an antiforgery token on these endpoints, we reject any request with a cookie, cert or auth header.I don't think we'll end up needing the
.ValidateAntiforgery()
extension method, but maybe that would be useful for endpoints manually consuming a form from the HttpRequest.Since minimal endpoints are not opinionated about the client app language or framework, having a single solution for generating and sending the antiforgery token is difficult. The current IAntiforgery service interface is built around idea that the client will be performing a request before posting form data and will be able to send a cookie set during that prior request during the actual POST. This makes sense for web clients, but we want to make uploading files easier for non-web clients as well because "multipart/form-data" is one of the most widely adopted ways to upload files over HTTP.
My understanding is that the cookie is there to prevent an attacker from laundering an antiforgery token meant for a different user. It would be more convenient if this could be done without a cookie and instead with a single token tied to the IPrincipal in some other way.
@blowdart
The text was updated successfully, but these errors were encountered: