Skip to content

Commit eeffd7c

Browse files
cldrncalumgrant
authored andcommitted
Adds CodeQL query to check for Pages validateRequest directive
1 parent 2051356 commit eeffd7c

4 files changed

Lines changed: 99 additions & 0 deletions

File tree

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<!DOCTYPE qhelp PUBLIC
2+
"-//Semmle//qhelp//EN"
3+
"qhelp.dtd">
4+
<qhelp>
5+
6+
<overview>
7+
<p>
8+
<code>Request validation</code>
9+
is a feature in ASP.NET that protects web applications against
10+
potentially malicious content
11+
in requests, specifically against
12+
cross-site scripting attacks (XSS).
13+
</p>
14+
15+
</overview>
16+
<recommendation>
17+
18+
<p>
19+
Enable the directive validateRequest in your web.config file:
20+
<code>
21+
<pages validateRequest="true" />
22+
</code>
23+
</p>
24+
25+
</recommendation>
26+
<example>
27+
28+
<p>
29+
The following example shows the 'validateRequest' flag set to true in
30+
a
31+
<code>Web.config</code>
32+
file for ASP.NET. This will protect the web application against
33+
common XSS attacks:
34+
</p>
35+
36+
<sample src="Web.config.ASPNetPagesValidateRequest.good" />
37+
38+
<p>
39+
If validateRequest is set to
40+
<code>false</code>
41+
, validation is disabled:
42+
</p>
43+
44+
<sample src="Web.config.ASPNetPagesValidateRequest.bad" />
45+
46+
</example>
47+
<references>
48+
49+
<li>
50+
MSDN:
51+
<a
52+
href=https://docs.microsoft.com/en-us/previous-versions/aspnet/hh882339(v=vs.110)?redirectedfrom=MSDN ">Request
53+
Validation in ASP.NET</a>
54+
.
55+
</li>
56+
<li>
57+
MSDN:
58+
<a
59+
href="https://docs.microsoft.com/en-us/previous-versions/aspnet/debza5t0(v=vs.100)?redirectedfrom=MSDN">Validation ASP.NET Controls</a>
60+
.
61+
</li>
62+
63+
64+
</references>
65+
</qhelp>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/**
2+
* @name Page Request Validation is disabled
3+
* @description ASP.NET Pages should not disable the built-in request validation.
4+
* @kind problem
5+
*/
6+
7+
import csharp
8+
import semmle.code.asp.WebConfig
9+
10+
from SystemWebXMLElement web, XMLAttribute requestvalidateAttribute
11+
where
12+
requestvalidateAttribute = web.getAChild("pages").getAttribute("validateRequest") and
13+
requestvalidateAttribute.getValue().toLowerCase() = "false"
14+
select requestvalidateAttribute, "validateRequest is set to false"
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<configuration>
3+
<system.web>
4+
<compilation
5+
defaultLanguage="c#"
6+
/>
7+
<pages validateRequest="false" />
8+
...
9+
</system.web>
10+
</configuration>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<configuration>
3+
<system.web>
4+
<compilation
5+
defaultLanguage="c#"
6+
/>
7+
<pages validateRequest="true" />
8+
...
9+
</system.web>
10+
</configuration>

0 commit comments

Comments
 (0)