Skip to content

Commit 56c12ad

Browse files
committed
Adds check for insecure MaxLengthRequest values
1 parent 351cb46 commit 56c12ad

4 files changed

Lines changed: 85 additions & 0 deletions

File tree

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<!DOCTYPE qhelp PUBLIC
2+
"-//Semmle//qhelp//EN"
3+
"qhelp.dtd">
4+
<qhelp>
5+
6+
<overview>
7+
<p>
8+
The
9+
<code>maxRequestLength</code>
10+
attribute sets the limit for the input stream buffering
11+
threshold in KB. Attackers can use large requests to cause denial-of-service
12+
attacks.
13+
</p>
14+
</overview>
15+
<recommendation>
16+
17+
<p>
18+
The recommended value is 4096 KB but you should try setting it as small
19+
as possible according
20+
to business requirements.
21+
</p>
22+
23+
</recommendation>
24+
<example>
25+
26+
<p>
27+
The following example shows the
28+
<code>maxRequestLength</code>
29+
attribute set to a high value
30+
(255 MB) in a
31+
<code>Web.config</code>
32+
file for ASP.NET:
33+
</p>
34+
35+
<sample src="Web.config.ASPNetMaxRequestLength.bad" />
36+
37+
<p>
38+
Unless such a high value is strictly needed, it is better to set the
39+
recommended value (4096 KB):
40+
</p>
41+
42+
<sample src="Web.config.ASPNetMaxRequestLength.good" />
43+
44+
</example>
45+
46+
<references>
47+
48+
<li>
49+
.NET API:
50+
<a
51+
href="https://docs.microsoft.com/en-us/dotnet/api/system.web.configuration.httpruntimesection.maxrequestlength?view=netframework-4.8">MaxRequestLength limit to prevent denial of service attacks</a>
52+
.
53+
</li>
54+
</references>
55+
</qhelp>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/**
2+
* @name Large maxRequestLength value
3+
* @description Setting a large 'maxRequestLength' value may render a webpage vulnerable to
4+
* denial-of-service attacks.
5+
* @kind problem
6+
* @problem.severity warning
7+
*/
8+
9+
import csharp
10+
import semmle.code.asp.WebConfig
11+
12+
from SystemWebXMLElement web, XMLAttribute maxReqLength
13+
where
14+
maxReqLength = web
15+
.getAChild(any(string s | s.toLowerCase() = "httpruntime"))
16+
.getAttribute(any(string s | s.toLowerCase() = "maxrequestlength")) and
17+
maxReqLength.getValue().toInt() > 4096
18+
select maxReqLength, "Large 'maxRequestLength' value (" + maxReqLength.getValue() + " KB)."
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<configuration>
3+
<system.web>
4+
<httpRuntime maxRequestLength="255000" />
5+
</system.web>
6+
</configuration>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<configuration>
3+
<system.web>
4+
<httpRuntime maxRequestLength="4096" />
5+
</system.web>
6+
</configuration>

0 commit comments

Comments
 (0)