Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
- [pull #705] XSS fixes in links, images, and more
- [pull #720] Add `wiki-links` extra for `[[Page Name]]` style links (#221)
- [pull #722] Harden URL safety checks and sanitization in safe mode (#721)
- [pull #728] Fix XSS from zero-padded colon entities in link URLs (#726)


## python-markdown2 2.5.5
Expand Down
3 changes: 2 additions & 1 deletion lib/markdown2.py
Original file line number Diff line number Diff line change
Expand Up @@ -1618,7 +1618,8 @@ def _safe_href(self):
less_safe = r'#/\.!#$%&\(\)\+,/:;=\?@\[\]^`\{\}\|~'
# html encoded colon in a URL still functions as a normal colon, so need to detect those
# semicolon at the end is optional in browsers - see #721
protocol_seperators = [':', r':?', r':?', r':?']
# numeric references can be zero-padded (&#058, &#x003a) - see #726
protocol_seperators = [':', r'&#x0*3a;?', r'&#0*58;?', r':?']
# dot seperated hostname, optional port number, not followed by protocol seperator
domain = r'(?:[{}]+(?:\.[{}]+)*)(?:(?<!tel)(?<!javascript):\d+/?)?(?![^:/]*(?:{})/*)'.format(safe, safe, '|'.join(protocol_seperators))
fragment = r'[%s]*' % (safe + less_safe)
Expand Down
7 changes: 7 additions & 0 deletions test/tm-cases/xss_issue726.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<p><a href="#">Click me</a></p>

<p><a href="#">Click me</a></p>

<p><a href="#">Click me</a></p>

<p><a href="#">Click me</a></p>
1 change: 1 addition & 0 deletions test/tm-cases/xss_issue726.opts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"safe_mode": "escape"}
7 changes: 7 additions & 0 deletions test/tm-cases/xss_issue726.text
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[Click me](javascript&#058alert(origin))

[Click me](javascript&#0000058;alert(origin))

[Click me](javascript&#x003a;alert(origin))

[Click me](javascript&#X003A;alert(origin))
Loading