|
1 | 1 | <!DOCTYPE qhelp PUBLIC |
2 | | - "-//Semmle//qhelp//EN" |
3 | | - "qhelp.dtd"> |
| 2 | +"-//Semmle//qhelp//EN" |
| 3 | +"qhelp.dtd"> |
4 | 4 | <qhelp> |
5 | 5 | <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> |
12 | 19 |
|
13 | 20 | </overview> |
14 | 21 | <recommendation> |
15 | 22 |
|
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> |
18 | 26 |
|
19 | 27 | <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> |
21 | 30 | </ul> |
22 | 31 |
|
23 | 32 | </recommendation> |
24 | 33 | <example> |
25 | 34 |
|
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> |
32 | 46 |
|
33 | 47 | <sample src="TaintedWebClient.cs" /> |
34 | 48 |
|
|
41 | 55 | </li> |
42 | 56 | <li> |
43 | 57 | 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>. |
45 | 60 | </li> |
46 | 61 |
|
47 | 62 | </references> |
|
0 commit comments