Skip to content

Commit

Permalink
Merge pull request #473 from vin01/master
Browse files Browse the repository at this point in the history
Add test for nested incomplete tag sanitization
  • Loading branch information
nicholasserra committed Sep 22, 2022
2 parents 47d3653 + eb5ff1a commit 9b6fc0b
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/markdown2.py
Original file line number Diff line number Diff line change
Expand Up @@ -2358,7 +2358,10 @@ def _encode_incomplete_tags(self, text):
if text.endswith(">"):
return text # this is not an incomplete tag, this is a link in the form <http://x.y.z>

return self._incomplete_tags_re.sub("&lt;\\1", text)
def incomplete_tags_sub(match):
return match.group().replace('<', '&lt;')

return self._incomplete_tags_re.sub(incomplete_tags_sub, text)

def _encode_backslash_escapes(self, text):
for ch, escape in list(self._escape_table.items()):
Expand Down
7 changes: 7 additions & 0 deletions test/tm-cases/nested_incomplete_tags_xss.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<p>&lt;img &lt;img src="" onerror=alert(/XSS/)</p>

<p>&lt;img&lt;img src="" onerror=alert(/XSS/)</p>

<p>&lt;img&lt;img/src="" onerror=alert(/XSS/)</p>

<p>&lt;img&lt;img&lt;img src="" onerror=alert(/XSS/)</p>
1 change: 1 addition & 0 deletions test/tm-cases/nested_incomplete_tags_xss.opts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"safe_mode": "replace"}
7 changes: 7 additions & 0 deletions test/tm-cases/nested_incomplete_tags_xss.text
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<img <img src="" onerror=alert(/XSS/)

<img<img src="" onerror=alert(/XSS/)

<img<img/src="" onerror=alert(/XSS/)

<img<img<img src="" onerror=alert(/XSS/)

0 comments on commit 9b6fc0b

Please sign in to comment.