Skip to content

Fix CVE-2018-5773: #285 #303

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

Merged
merged 1 commit into from
Sep 26, 2018
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
10 changes: 9 additions & 1 deletion lib/markdown2.py
Original file line number Diff line number Diff line change
Expand Up @@ -1203,7 +1203,7 @@ def _is_auto_link(s):
self.html_spans[key] = sanitized
tokens.append(key)
else:
tokens.append(token)
tokens.append(self._encode_incomplete_tags(token))
is_html_markup = not is_html_markup
return ''.join(tokens)

Expand Down Expand Up @@ -2140,6 +2140,14 @@ def _encode_amps_and_angles(self, text):
text = self._naked_gt_re.sub('>', text)
return text

_incomplete_tags_re = re.compile("<(/?\w+\s+)")

def _encode_incomplete_tags(self, text):
if self.safe_mode not in ("replace", "escape"):
return text

return self._incomplete_tags_re.sub("&lt;\\1", text)

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

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

</img src="" onerror=alert(/XSS/)
2 changes: 1 addition & 1 deletion test/tm-cases/basic_safe_mode.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

<p><img src="http://example.com&gt;[HTML_REMOVED]alert(1)[HTML_REMOVED]" alt="img3" /></p>

<p><img src="javascript:alert(1)"</p>
<p>&lt;img src="javascript:alert(1)"</p>

<p><img src="http://example.com/image.gif?h=200&amp;w=500" alt="ok img" /></p>

Expand Down