aspnet / Announcements

Subscribe to this repo to be notified about major changes in ASP.NET Core and Entity Framework Core
Other
1.66k stars 80 forks source link

[Breaking change]: Minimal APIs consuming IFormFile or IFormFileCollection parameters require anti-forgery checks #509

Open captainsafia opened 10 months ago

captainsafia commented 10 months ago

Description

Minimal API endpoints that consume an IFormFile or IFormFileCollection will now be opted-in to requiring anti-forgery token validation using the new anti-forgery middleware.

Version

.NET 8 RC 1

Previous behavior

Minimal API endpoints that bound a parameter from the form via IFormFile or IFormFileCollection did not require anti-forgery validation.

New behavior

Minimal API endpoints that bound a parameter from the form via IFormFile or IFormFileCollection did require anti-forgery validation. An exception will be thrown at startup if the anti-forgery middleware is not registered for an API that defines these input types.

Type of breaking change

Reason for change

Anti-forgery token validation is a recommended security precaution for APIs that consume data from a form.

Recommended action

Users can opt out of anti-forgery validation for specific endpoints by using the DisableAntiforgery method like so:

var app = WebApplication.Create();

app.MapPost("/", (IFormFile formFile) => ...)
  .DisableAntiforgery();

app.Run();

Affected APIs

None.