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

CA5391 ("Use antiforgery tokens... ") but for API controllers binding FromForm or IFormFile #7424

Open
AnthonyMastrean opened this issue Sep 27, 2024 · 0 comments

Comments

@AnthonyMastrean
Copy link

A classic API controller, not a minimal API, binding FromForm or IFormFile should participate in antiforgery. The only way to do that is with this new [RequireAntiforgeryToken] attribute.

It would be nice to have a rule like CA5391.

[ApiController]
public class ExampleController
{
    [HttpPost] 
    public void PostA([FromForm] IFormFile file) { ... } // ❌ 

    [HttpPost]
    [RequiredAntiforgeryToken]
    public void PostB([FromForm] IFormFile file) { ... } // ✅ 
}

It would be nice if this were documented, but it is not. I have opened a separate issue in the documentation repository (dotnet/AspNetCore.Docs#33740).

https://learn.microsoft.com/en-us/aspnet/core/security/anti-request-forgery?view=aspnetcore-8.0

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

No branches or pull requests

1 participant