Skip to content

Commit fede9ae

Browse files
authored
Merge pull request #2355 from cldrn/AspNetMaxRequestLength
CodeQL query to check for insecure MaxLengthRequest values in ASP.NET applications
2 parents d58a6b0 + 795959e commit fede9ae

File tree

9 files changed

+100
-0
lines changed

9 files changed

+100
-0
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<!DOCTYPE qhelp PUBLIC
2+
"-//Semmle//qhelp//EN"
3+
"qhelp.dtd">
4+
<qhelp>
5+
6+
<overview>
7+
<p>
8+
The <code>maxRequestLength</code> attribute sets the limit for the input
9+
stream buffering threshold in KB. Attackers can use large requests to cause
10+
denial-of-service attacks.
11+
</p>
12+
</overview>
13+
<recommendation>
14+
15+
<p>
16+
The recommended value is 4096 KB but you should try setting it as
17+
small as possible according to business requirements.
18+
</p>
19+
20+
</recommendation>
21+
<example>
22+
23+
<p>
24+
The following example shows the <code>maxRequestLength</code>
25+
attribute set to a high value (255 MB) in a <code>Web.config</code>
26+
file for ASP.NET:
27+
</p>
28+
29+
<sample src="Web.config.ASPNetMaxRequestLength.bad" />
30+
31+
<p>
32+
Unless such a high value is strictly needed, it is better to set
33+
the recommended value (4096 KB):
34+
</p>
35+
36+
<sample src="Web.config.ASPNetMaxRequestLength.good" />
37+
38+
</example>
39+
40+
<references>
41+
42+
<li>
43+
MSDN:
44+
<a href="https://docs.microsoft.com/en-us/dotnet/api/system.web.configuration.httpruntimesection.maxrequestlength?view=netframework-4.8">HttpRuntimeSection.MaxRequestLength Property</a>.
45+
</li>
46+
</references>
47+
</qhelp>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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+
* @id cs/web/large-max-request-length
8+
* @tags security
9+
* frameworks/asp.net
10+
* external/cwe/cwe-16
11+
*/
12+
13+
import csharp
14+
import semmle.code.asp.WebConfig
15+
16+
from SystemWebXMLElement web, XMLAttribute maxReqLength
17+
where
18+
maxReqLength = web
19+
.getAChild(any(string s | s.toLowerCase() = "httpruntime"))
20+
.getAttribute(any(string s | s.toLowerCase() = "maxrequestlength")) and
21+
maxReqLength.getValue().toInt() > 4096
22+
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>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// Dummy class for extraction purposes
2+
public class ASPNetMaxRequestLengthDummyClass
3+
{
4+
5+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
| bad/Web.config:4:5:4:46 | maxRequestLength=262144 | Large 'maxRequestLength' value (262144 KB). |
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Security Features/CWE-016/ASPNetMaxRequestLength.ql
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>
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="262144" />
5+
</system.web>
6+
</configuration>

0 commit comments

Comments
 (0)