Skip to content

Commit 16e3941

Browse files
authored
Reword of help file
1 parent ef53e44 commit 16e3941

File tree

1 file changed

+33
-18
lines changed

1 file changed

+33
-18
lines changed

csharp/ql/src/experimental/CWE-099/TaintedWebClient.qhelp

Lines changed: 33 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,48 @@
11
<!DOCTYPE qhelp PUBLIC
2-
"-//Semmle//qhelp//EN"
3-
"qhelp.dtd">
2+
"-//Semmle//qhelp//EN"
3+
"qhelp.dtd">
44
<qhelp>
55
<overview>
6-
<p>The WebClient class provices common methods for sending data to and receiving data from a resource identified by a URI.
7-
Even that the name of the class is WebClient the support is not only limited to WebResources but also local resources. This
8-
can result in sensitive information being revealed.</p>
9-
10-
<p>URIs that are naively constructed from data controlled by a user may contain local paths with unexpected special characters,
11-
such as "..". Such a path may potentially point to any directory on the file system.</p>
6+
<p>The WebClient class provides a variety of methods for data transmission and
7+
communication with a particular URI. Despite of the class' naming convention,
8+
the URI scheme can also identify local resources, not only remote ones. Tainted
9+
by user-supplied input, the URI can be leveraged to access resources available
10+
on the local file system, therefore leading to the disclosure of sensitive
11+
information. This can be trivially achieved by supplying path traversal
12+
sequences (../) followed by an existing directory or file path.</p>
13+
14+
<p>Sanitization of user-supplied URI values using the
15+
<code>StartsWith("https://")</code> method is deemed insufficient in preventing
16+
arbitrary file reads. This is due to the fact that .NET ignores the protocol
17+
handler (https in this case) in URIs like the following:
18+
"https://../../../../etc/passwd".</p>
1219

1320
</overview>
1421
<recommendation>
1522

16-
<p>Validate user input before using it to ensure that is a URI of an external resource and not a local one.
17-
Pontetial solutions:</p>
23+
<p>Validate user input before using it to ensure that is a URI of an external
24+
resource and not a local one.
25+
Potential solutions:</p>
1826

1927
<ul>
20-
<li>Sanitize potentially tainted paths using <code>System.Uri.IsWellFormedUriString</code>.</li>
28+
<li>Sanitize potentially tainted paths using
29+
<code>System.Uri.IsWellFormedUriString</code>.</li>
2130
</ul>
2231

2332
</recommendation>
2433
<example>
2534

26-
<p>In the first example, a domain name is read from a <code>HttpRequest</code> and then used to request this domain. However, a
27-
malicious user could enter a local path - for example, "../../../etc/passwd". In the second example, it
28-
appears that user is restricted to the HTTPS protocol handler. However, a malicious user could
29-
still enter a local path. For example, the string "../../../etc/passwd" will result in the code
30-
reading the file located at "/etc/passwd", which is the system's password file. This file would then be
31-
sent back to the user, giving them access to all the system's passwords.</p>
35+
<p>In the first example, a domain name is read from a <code>HttpRequest</code>
36+
and then this domain is requested using the method <code>DownloadString</code>.
37+
However, a malicious user could enter a local path - for example,
38+
"../../../etc/passwd" instead of a domain.
39+
In the second example, it appears that the user is restricted to the HTTPS
40+
protocol handler. However, a malicious user could still enter a local path,
41+
since as explained above the protocol handler will be ignored by .net. For
42+
example, the string "https://../../../etc/passwd" will result in the code
43+
reading the file located at "/etc/passwd", which is the system's password file.
44+
This file would then be sent back to the user, giving them access to all the
45+
system's passwords.</p>
3246

3347
<sample src="TaintedWebClient.cs" />
3448

@@ -41,7 +55,8 @@ OWASP:
4155
</li>
4256
<li>
4357
CWE-099:
44-
<a href="https://cwe.mitre.org/data/definitions/99.html">Resource Injection</a>.
58+
<a href="https://cwe.mitre.org/data/definitions/99.html">Resource
59+
Injection</a>.
4560
</li>
4661

4762
</references>

0 commit comments

Comments
 (0)