Skip to content

Commit bf4018c

Browse files
Merge pull request #728 from rmz-oz/fix-safe-href-zero-padded-entities
Fix zero-padded colon entities passing _safe_href check
2 parents db58ad8 + 5f8630d commit bf4018c

5 files changed

Lines changed: 18 additions & 1 deletion

File tree

‎CHANGES.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
- [pull #705] XSS fixes in links, images, and more
1515
- [pull #720] Add `wiki-links` extra for `[[Page Name]]` style links (#221)
1616
- [pull #722] Harden URL safety checks and sanitization in safe mode (#721)
17+
- [pull #728] Fix XSS from zero-padded colon entities in link URLs (#726)
1718

1819

1920
## python-markdown2 2.5.5

‎lib/markdown2.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1618,7 +1618,8 @@ def _safe_href(self):
16181618
less_safe = r'#/\.!#$%&\(\)\+,/:;=\?@\[\]^`\{\}\|~'
16191619
# html encoded colon in a URL still functions as a normal colon, so need to detect those
16201620
# semicolon at the end is optional in browsers - see #721
1621-
protocol_seperators = [':', r':?', r':?', r':?']
1621+
# numeric references can be zero-padded (&#058, &#x003a) - see #726
1622+
protocol_seperators = [':', r'&#x0*3a;?', r'&#0*58;?', r':?']
16221623
# dot seperated hostname, optional port number, not followed by protocol seperator
16231624
domain = r'(?:[{}]+(?:\.[{}]+)*)(?:(?<!tel)(?<!javascript):\d+/?)?(?![^:/]*(?:{})/*)'.format(safe, safe, '|'.join(protocol_seperators))
16241625
fragment = r'[%s]*' % (safe + less_safe)

‎test/tm-cases/xss_issue726.html‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<p><a href="#">Click me</a></p>
2+
3+
<p><a href="#">Click me</a></p>
4+
5+
<p><a href="#">Click me</a></p>
6+
7+
<p><a href="#">Click me</a></p>

‎test/tm-cases/xss_issue726.opts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"safe_mode": "escape"}

‎test/tm-cases/xss_issue726.text‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[Click me](javascript&#058alert(origin))
2+
3+
[Click me](javascript&#0000058;alert(origin))
4+
5+
[Click me](javascript&#x003a;alert(origin))
6+
7+
[Click me](javascript&#X003A;alert(origin))

0 commit comments

Comments
 (0)