Skip to content

Commit 3049bf2

Browse files
authored
Merge pull request #2358 from cldrn/ASPNetPagesValidateRequest
Adds CodeQL query to check for Pages with disabled built-in validation
2 parents 25265bd + 59ce884 commit 3049bf2

File tree

10 files changed

+93
-0
lines changed

10 files changed

+93
-0
lines changed

change-notes/1.24/analysis-csharp.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ The following changes in version 1.24 affect C# analysis in all applications.
77
| **Query** | **Tags** | **Purpose** |
88
|-----------------------------|-----------|--------------------------------------------------------------------|
99
| Insecure configuration for ASP.NET requestValidationMode (`cs/insecure-request-validation-mode`) | security, external/cwe/cwe-016 | Finds where this attribute has been set to a value less than 4.5, which turns off some validation features and makes the application less secure. |
10+
| Page request validation is disabled (`cs/web/request-validation-disabled`) | security, frameworks/asp.net, external/cwe/cwe-016 | Finds where ASP.NET page request validation has been disabled, which could makes the application less secure. |
1011

1112
## Changes to existing queries
1213

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<!DOCTYPE qhelp PUBLIC "-//Semmle//qhelp//EN" "qhelp.dtd">
2+
<qhelp>
3+
4+
<overview>
5+
<p>
6+
Request validation is a feature in ASP.NET that protects web applications against
7+
potentially malicious content in requests, specifically against
8+
cross-site scripting attacks (XSS).
9+
</p>
10+
11+
</overview>
12+
<recommendation>
13+
14+
<p>
15+
Enable the directive <code>validateRequest</code> in your <code>web.config</code> file:
16+
17+
<code>
18+
&lt;pages validateRequest="true" /&gt;
19+
</code>
20+
</p>
21+
22+
</recommendation>
23+
<example>
24+
25+
<p>
26+
The following example shows the <code>validateRequest</code> flag set to <code>false</code>
27+
in a <code>Web.config</code> file for ASP.NET. This will disable validation, and leave
28+
the web application vulnerable against common XSS attacks:
29+
</p>
30+
31+
<sample src="ASPNetPagesValidateRequestBad.config" />
32+
33+
<p>
34+
If <code>validateRequest</code> is set to <code>true</code>, validation is enabled:
35+
</p>
36+
37+
<sample src="ASPNetPagesValidateRequestGood.config" />
38+
39+
</example>
40+
<references>
41+
42+
<li>
43+
MSDN:
44+
<a
45+
href="https://docs.microsoft.com/en-us/previous-versions/aspnet/hh882339(v=vs.110)?redirectedfrom=MSDN">
46+
Request Validation in ASP.NET
47+
</a>.
48+
</li>
49+
50+
</references>
51+
</qhelp>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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+
* @problem.severity warning
6+
* @id cs/web/request-validation-disabled
7+
* @tags security
8+
* frameworks/asp.net
9+
* external/cwe/cwe-16
10+
*/
11+
12+
import csharp
13+
import semmle.code.asp.WebConfig
14+
15+
from SystemWebXMLElement web, XMLAttribute requestvalidateAttribute
16+
where
17+
requestvalidateAttribute = web.getAChild("pages").getAttribute("validateRequest") and
18+
requestvalidateAttribute.getValue().toLowerCase() = "false"
19+
select requestvalidateAttribute, "The 'validateRequest' attribute is set to 'false'."
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<configuration>
2+
<system.web>
3+
<pages validateRequest="false" />
4+
</system.web>
5+
</configuration>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<configuration>
2+
<system.web>
3+
<pages validateRequest="true" />
4+
</system.web>
5+
</configuration>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
| ASPNetPagesValidateRequestBad.config:3:5:3:38 | validateRequest=false | The 'validateRequest' attribute is set to 'false'. |
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Security Features/CWE-016/ASPNetPagesValidateRequest.ql
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<configuration>
2+
<system.web>
3+
<pages validateRequest="false" />
4+
</system.web>
5+
</configuration>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<configuration>
2+
<system.web>
3+
<pages validateRequest="true" />
4+
</system.web>
5+
</configuration>

csharp/ql/test/query-tests/Security Features/CWE-016/ASPNetPagesValidateRequest/Program.cs

Whitespace-only changes.

0 commit comments

Comments
 (0)