-
Notifications
You must be signed in to change notification settings - Fork 10.1k
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
Modelbinding/AntiForgery validation suppresses IOException/BadHttpRequestException #40810
Comments
To be clear, the exception handling should be removed as you cannot proceed with modelbinding (or antiforgery validation for that matter) if an IOException has occurred. The fix should also be backported to 5.x. |
Triage: the easiest/safest thing to do is probably add another catch in the highlighted code for BadHttpRequestException so as to preserve the original error. |
Thanks for contacting us. We're moving this issue to the |
@jcracknell Is this not producing an empty 500 response? The correct behavior might just be to rethrow the |
@halter73 Ok so there is a response (and a Firefox fetch API bug), but the issue remains that IOExceptions are being suppressed and controller action invocation proceeds even when the request was not fully received. I'm still very skeptical that you can proceed in the event of an IOException, except in the case where the request was actually fully received and the client hung up. 3.1 + custom BadHttpRequestExceptionMiddleware (3.1 did not automatically set response codes for BadHttpRequestException):
6.0 without custom BadHttpRequestException middleware (not checking the validation state is my problem):
Kestrel messages for the same request:
|
In case anyone is looking for a workaround it is reasonably straightforward to replace all of the form-related IValueProviderFactory implementations with patched versions via MvcOptions.ValueProviderFactories (as the factories are relatively trivial), however the JQueryFormValueProviderFactory depends on internal static helpers. Alternatively you could wrap the existing factories to unwrap and rethrow ValueProviderExceptions over inner IOExceptions, but doing so alters the stack trace of the IOException. |
Thanks for contacting us. We're moving this issue to the |
We would like to note that one other place where an IOException is caught where it probably shouldn't be is
In our case this behavior lead to HTTP 400 (instead of 500) when e.g. the disk is full (IOException "There is not enough space on the disk") when browsing to routes protected by an AntiforgeryToken. Other routes would just skip model binding leading to the model being In either case we think that the correct response would be a 500 error to show that something went wrong on the server. |
This is still an issue. If I send a request that's too large, I get a screen telling me, "A valid antiforgery token was not provided with the request. Add an antiforgery token, or disable antiforgery validation for this endpoint." This leads a developer to try and debug why the anti forgery token isn't working rather than telling them the issue is that the request is too large. It'd be a lot better if the developer saw this, giving them the "BadHttpRequestException: Request body too large. The max request body size is 30000000 bytes.": |
Is there an existing issue for this?
Describe the bug
Upgrading from 3.1 to 6.0, and a multipart body exceeding the configured MaxHttpRequestBodySize no longer produces an error response (or a response at all).
Under 3.1 attempting this would produce the trace:
Interestingly the log reports:
But what I actually get is a closed connection (no response), and a ModelBinding error with a null IFormFile on the server.
This appears to be caught by FormValueProviderFactory per 78a587b:
aspnetcore/src/Mvc/Mvc.Core/src/ModelBinding/FormValueProviderFactory.cs
Lines 50 to 55 in 57c3104
Expected Behavior
Any request exceeding MaxRequestBodySize should produce an HTTP 413: Payload too large.
Steps To Reproduce
No response
Exceptions (if any)
No response
.NET Version
6.0.102
Anything else?
No response
The text was updated successfully, but these errors were encountered: