Skip to content

Commit

Permalink
Merge pull request #586 from Crozzers/xss-fix
Browse files Browse the repository at this point in the history
Fix #583 by tweaking incomplete tag regex
  • Loading branch information
nicholasserra committed Jul 5, 2024
2 parents adfc3fc + f507607 commit 768c820
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/markdown2.py
Original file line number Diff line number Diff line change
Expand Up @@ -2342,7 +2342,7 @@ def _encode_amps_and_angles(self, text: str) -> str:
text = self._naked_gt_re.sub('>', text)
return text

_incomplete_tags_re = re.compile(r"<(!--|/?\w+?(?!\w)\s*?.+?[\s/]+?)")
_incomplete_tags_re = re.compile(r"<(!--|/?\w+?(?!\w)\s*?.+?(?:[\s/]+?|$))")

def _encode_incomplete_tags(self, text: str) -> str:
if self.safe_mode not in ("replace", "escape"):
Expand Down
2 changes: 1 addition & 1 deletion test/tm-cases/issue341_xss.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<p>Example 1:
<ftp:<a href="#">[HTML_REMOVED]alert(1);//</a>&gt;<ftp:<a href="#">[HTML_REMOVED]</a>&gt;</p>
&lt;ftp:<a href="#">[HTML_REMOVED]alert(1);//</a>&gt;&lt;ftp:<a href="#">[HTML_REMOVED]</a>&gt;</p>

<p>Example 2:
&lt;http://g<!s://q?<!-&lt;<a href="http://g">[HTML_REMOVED]alert(1);/\*</a>->a>&lt;http://g<!s://g.c?<!-&lt;<a href="http://g">a\\*/[HTML_REMOVED]alert(1);/*</a>->a></p>
1 change: 1 addition & 0 deletions test/tm-cases/issue583_xss.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<p>&lt;img onerror=alert("hi")[HTML_REMOVED] src=a</p>
1 change: 1 addition & 0 deletions test/tm-cases/issue583_xss.opts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{'safe_mode': 'replace'}
1 change: 1 addition & 0 deletions test/tm-cases/issue583_xss.text
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<img onerror=alert("hi")<a> src=a

0 comments on commit 768c820

Please sign in to comment.