Skip to content

Commit 768c820

Browse files
Merge pull request #586 from Crozzers/xss-fix
Fix #583 by tweaking incomplete tag regex
2 parents adfc3fc + f507607 commit 768c820

File tree

5 files changed

+5
-2
lines changed

5 files changed

+5
-2
lines changed

lib/markdown2.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2342,7 +2342,7 @@ def _encode_amps_and_angles(self, text: str) -> str:
23422342
text = self._naked_gt_re.sub('>', text)
23432343
return text
23442344

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

23472347
def _encode_incomplete_tags(self, text: str) -> str:
23482348
if self.safe_mode not in ("replace", "escape"):

test/tm-cases/issue341_xss.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<p>Example 1:
2-
<ftp:<a href="#">[HTML_REMOVED]alert(1);//</a>&gt;<ftp:<a href="#">[HTML_REMOVED]</a>&gt;</p>
2+
&lt;ftp:<a href="#">[HTML_REMOVED]alert(1);//</a>&gt;&lt;ftp:<a href="#">[HTML_REMOVED]</a>&gt;</p>
33

44
<p>Example 2:
55
&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>

test/tm-cases/issue583_xss.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<p>&lt;img onerror=alert("hi")[HTML_REMOVED] src=a</p>

test/tm-cases/issue583_xss.opts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{'safe_mode': 'replace'}

test/tm-cases/issue583_xss.text

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<img onerror=alert("hi")<a> src=a

0 commit comments

Comments
 (0)