Skip to content

Commit

Permalink
Merge pull request #140 from junorouse/master
Browse files Browse the repository at this point in the history
Fix XXS
  • Loading branch information
lepture authored Oct 26, 2017
2 parents 5b8c3f7 + d6f0b64 commit ab8f7de
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 2 deletions.
5 changes: 3 additions & 2 deletions mistune.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,9 @@ def escape(text, quote=False, smart_amp=True):
def escape_link(url):
"""Remove dangerous URL schemes like javascript: and escape afterwards."""
lower_url = url.lower().strip('\x00\x1a \n\r\t')

for scheme in _scheme_blacklist:
if lower_url.startswith(scheme):
if re.sub(r'[^A-Za-z0-9\/:]+', '', lower_url).startswith(scheme):
return ''
return escape(url, quote=True, smart_amp=False)

Expand Down Expand Up @@ -844,7 +845,7 @@ def autolink(self, link, is_email=False):
:param link: link content or email address.
:param is_email: whether this is an email or not.
"""
text = link = escape(link)
text = link = escape_link(link)
if is_email:
link = 'mailto:%s' % link
return '<a href="%s">%s</a>' % (link, text)
Expand Down
Empty file added tests/__init__.py
Empty file.
2 changes: 2 additions & 0 deletions tests/test_extra.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ def test_safe_links():
('javascript:alert`1`', ''),
# bypass attempt
('jAvAsCrIpT:alert`1`', ''),
# bypass with newline
('javasc\nript:alert`1`', ''),
# javascript pseudo protocol with entities
('javascript&colon;alert`1`', 'javascript&amp;colon;alert`1`'),
# javascript pseudo protocol with prefix (dangerous in Chrome)
Expand Down

0 comments on commit ab8f7de

Please sign in to comment.