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

NEST-524: Not increasing MaxRequestBodySize beyond its preconfigured size #108

Merged
merged 1 commit into from
Feb 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,13 @@ public async Task OnAuthorizationAsync(AuthorizationFilterContext context)
context.HttpContext.Features.Set<IFormFeature>(new FormFeature(context.HttpContext.Request, formOptions));

var maxRequestBodySizeFeature = context.HttpContext.Features.Get<IHttpMaxRequestBodySizeFeature>();
if (maxRequestBodySizeFeature is { IsReadOnly: false })
// Only setting MaxRequestBodySize if it wouldn't go over the preconfigured size. This is necessary because
// larger requests would pose a security issue (since the original limit was configured for a reason), and under
// IIS it wouldn't work with the following message anyway: "Increasing the MaxRequestBodySize conflicts with the
// max value for IIS limit maxAllowedContentLength. HTTP requests that have a content length greater than
// maxAllowedContentLength will still be rejected by IIS. You can disable the limit by either removing or
// setting the maxAllowedContentLength value to a higher limit."
if (maxRequestBodySizeFeature is { IsReadOnly: false } && maxRequestBodySizeFeature.MaxRequestBodySize > maxFileSize)
{
maxRequestBodySizeFeature.MaxRequestBodySize = maxFileSize;
}
Expand Down