Skip to content

Commit 6f346c6

Browse files
cldrncalumgrant
authored andcommitted
Adds CodeQL query to check for insecure RequestValidationMode in ASP.NET
1 parent a2827e9 commit 6f346c6

File tree

2 files changed

+106
-0
lines changed

2 files changed

+106
-0
lines changed
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
<!DOCTYPE qhelp PUBLIC
2+
"-//Semmle//qhelp//EN"
3+
"qhelp.dtd">
4+
<qhelp>
5+
6+
<overview>
7+
<p>
8+
The
9+
<code>requestValidationMode</code>
10+
attribute in ASP.NET is used to configure
11+
built-in validations to
12+
protect applications against code injections. Downgrading or
13+
disabling
14+
this configuration is not recommended. The default value 4.5
15+
is
16+
the only recommended value as previous versions only
17+
test a subset
18+
of
19+
requests.
20+
</p>
21+
22+
</overview>
23+
<recommendation>
24+
25+
<p>
26+
Always set
27+
<code>requestValidationMode</code>
28+
to 4.5. (Default value)
29+
</p>
30+
31+
</recommendation>
32+
<example>
33+
34+
<p>
35+
The following example shows the
36+
<code>requestValidationMode</code>
37+
attribute set to the value 4.0 which disables some protections and
38+
ignores individual
39+
<code>Page</code>
40+
directives:
41+
<code>
42+
<httpRuntime requestValidationMode="4.0" />
43+
44+
45+
46+
</code>
47+
</p>
48+
49+
<p>
50+
If the value is set to 2.0, request validation is enabled for pages
51+
but not for all requests:
52+
</p>
53+
54+
<code>
55+
<httpRuntime requestValidationMode="2.0" />
56+
57+
58+
59+
</code>
60+
61+
<p>
62+
If the value is set to 0, request validation is completely disabled
63+
(Only recognized in ASP.NET 4.6 and later):
64+
</p>
65+
66+
<code>
67+
<httpRuntime requestValidationMode="0.0" />
68+
69+
70+
71+
</code>
72+
</example>
73+
<references>
74+
75+
<li>
76+
Microsoft:
77+
<a
78+
href="https://docs.microsoft.com/en-us/dotnet/api/system.web.configuration.httpruntimesection.requestvalidationmode?view=netframework-4.8">requestValidationMode configuration to protect against code
79+
injection attacks</a>
80+
.
81+
</li>
82+
<li>
83+
OWASP:
84+
<a
85+
href="https://www.owasp.org/index.php/ASP.NET_Request_Validation">ASP.NET Request Validation on OWASP</a>
86+
</li>
87+
</references>
88+
89+
</qhelp>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/**
2+
* @name Insecure configuration for ASP.NET requestValidationMode
3+
* @description Setting requestValidationMode to less than 4.5 disables built-in validations
4+
* included by default in ASP.NET. Disabling or downgrading this protection is not
5+
* recommended.
6+
* @kind problem
7+
* @problem.severity warning
8+
*/
9+
10+
import csharp
11+
12+
from XMLAttribute reqValidationMode
13+
where
14+
reqValidationMode.getName().toLowerCase() = "requestvalidationmode" and
15+
reqValidationMode.getValue().toFloat() < 4.5
16+
select reqValidationMode,
17+
"Insecure value for requestValidationMode (" + reqValidationMode.getValue() + ")."

0 commit comments

Comments
 (0)