Skip to content

Commit 121ca12

Browse files
committed
Update qhelp with https:/example.com handling
1 parent 58ce3e8 commit 121ca12

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

python/ql/src/Security/CWE-601/UrlRedirect.qhelp

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,21 @@ attribute is empty.
4545
</p>
4646

4747
<p>
48-
Note, however, that many browsers accept backslash characters (<code>\</code>) as equivalent
49-
to forward slash characters (<code>/</code>) in URLs, but the <code>urlparse</code> function
50-
does not. To account for this, you can first replace all backslashes with forward slashes,
51-
as shown in the following example:
48+
Note, however, that some cases are not handled as we desire out-of-the-box by <code>urlparse</code>, so we need to adjust two things, as shown in the example below:
5249
</p>
5350

51+
<ul>
52+
<li>
53+
Many browsers accept backslash characters (<code>\</code>) as equivalent
54+
to forward slash characters (<code>/</code>) in URLs, but the <code>urlparse</code> function
55+
does not.
56+
</li>
57+
<li>
58+
Mistyped URLs such as <code>https:/example.com</code> or <code>https:///example.com</code> are parsed as having an empty <code>netloc</code> attribute, while browsers will still redirect to the correct site.
59+
</li>
60+
</ul>
61+
62+
5463
<sample src="examples/redirect_good2.py"/>
5564

5665
<p>

python/ql/src/Security/CWE-601/examples/redirect_good2.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
def hello():
88
target = request.args.get('target', '')
99
target = target.replace('\\', '')
10-
if not urlparse(target).netloc:
10+
if not urlparse(target).netloc and not urlparse(target).scheme:
1111
# relative path, safe to redirect
1212
return redirect(target, code=302)
1313
# ignore the target and redirect to the home page

0 commit comments

Comments
 (0)