Skip to content

Commit 2de9646

Browse files
committed
Updates
1 parent 9bfebee commit 2de9646

File tree

5 files changed

+33
-2
lines changed

5 files changed

+33
-2
lines changed

src/Servers/IIS/IIS/src/Core/IISHttpContext.FeatureCollection.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,10 @@ unsafe X509Certificate2 ITlsConnectionFeature.ClientCertificate
342342
{
343343
throw new ArgumentOutOfRangeException(nameof(value), CoreStrings.NonNegativeNumberOrNullRequired);
344344
}
345-
345+
if (value > _options.IisMaxRequestSizeLimit)
346+
{
347+
_logger.LogWarning("Cannot increase request size past IIS limit.");
348+
}
346349
MaxRequestBodySize = value;
347350
}
348351
}

src/Servers/IIS/IIS/src/IISServerOptions.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ public class IISServerOptions
4242
// https://www.iis.net/configreference/system.webserver/security/requestfiltering/requestlimits#005
4343
private long? _maxRequestBodySize = 30000000;
4444

45+
internal long? IisMaxRequestSizeLimit;
46+
4547
/// <summary>
4648
/// Gets or sets the maximum allowed size of any request body in bytes.
4749
/// When set to null, the maximum request body size is unlimited.

src/Servers/IIS/IIS/src/WebHostBuilderIISExtensions.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,12 @@ public static IWebHostBuilder UseIIS(this IWebHostBuilder hostBuilder)
4646
options => {
4747
options.ServerAddresses = iisConfigData.pwzBindings.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
4848
options.ForwardWindowsAuthentication = iisConfigData.fWindowsAuthEnabled || iisConfigData.fBasicAuthEnabled;
49+
if (options.MaxRequestBodySize > iisConfigData.maxRequestBodySize)
50+
{
51+
// Log warning and set the max to the IIS limit
52+
options.MaxRequestBodySize = iisConfigData.maxRequestBodySize;
53+
}
54+
options.IisMaxRequestSizeLimit = iisConfigData.maxRequestBodySize;
4955
}
5056
);
5157
});

src/Servers/IIS/IIS/test/Common.FunctionalTests/Inprocess/MaxRequestBodySizeTests.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,25 @@ public async Task MaxRequestBodySizeE2EWorks()
3030
var result = await deploymentResult.HttpClient.PostAsync("/ReadRequestBody", new StringContent("test"));
3131
Assert.Equal(HttpStatusCode.RequestEntityTooLarge, result.StatusCode);
3232
}
33+
34+
[ConditionalFact]
35+
[RequiresNewHandler]
36+
public async Task SetIISLimitMaxRequestBodySizeE2EWorks()
37+
{
38+
var deploymentParameters = Fixture.GetBaseDeploymentParameters();
39+
deploymentParameters.ServerConfigActionList.Add(
40+
(config, _) => {
41+
config
42+
.RequiredElement("system.webServer")
43+
.GetOrAdd("security")
44+
.GetOrAdd("requestFiltering")
45+
.GetOrAdd("requestLimits", "maxAllowedContentLength", "1");
46+
});
47+
var deploymentResult = await DeployAsync(deploymentParameters);
48+
49+
var result = await deploymentResult.HttpClient.PostAsync("/ReadRequestBody", new StringContent("test"));
50+
// IIS returns a 404 instead of a 413...
51+
Assert.Equal(HttpStatusCode.NotFound, result.StatusCode);
52+
}
3353
}
3454
}

src/Shared/HttpSys/RequestProcessing/RequestUriBuilder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ internal static class RequestUriBuilder
2020

2121
public static string DecodeAndUnescapePath(Span<byte> rawUrlBytes)
2222
{
23-
Debug.Assert(rawUrlBytes.Length > 0, "Length of the URL cannot be zero.");
23+
Debug.Assert(rawUrlBytes.Length != 0, "Length of the URL cannot be zero.");
2424
var rawPath = RawUrlHelper.GetPath(rawUrlBytes);
2525

2626
if (rawPath.Length == 0)

0 commit comments

Comments
 (0)