Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test for nested incomplete tag sanitization #473

Merged
merged 3 commits into from
Sep 22, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 4 additions & 1 deletion lib/markdown2.py
Original file line number Diff line number Diff line change
Expand Up @@ -2356,7 +2356,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/)