Skip to content

Commit 28d94df

Browse files
Merge pull request #704 from Crozzers/702-703-xss-issues
Fix XSS from smuggling spans into image attributes (#702, #703)
2 parents 9050ae0 + 2ca6d22 commit 28d94df

14 files changed

Lines changed: 30 additions & 18 deletions

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
- [pull #695] Fix XSS issue from incomplete tags with no attributes (#694)
88
- [pull #700] Fix XSS from code spans in image alt text (#699)
99
- [pull #701] Allow boolean attribute syntax in `markdown-in-html` extra
10+
- [pull #704] Fix XSS from smuggling spans into image attributes (#702, #703)
1011

1112

1213
## python-markdown2 2.5.5

lib/markdown2.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1984,7 +1984,7 @@ def _do_code_blocks(self, text: str) -> str:
19841984
(?<!`)
19851985
\1 # Matching closer
19861986
(?!`)
1987-
''', re.X | re.S)
1987+
''', re.X)
19881988

19891989
def _code_span_sub(self, match: re.Match[str]) -> str:
19901990
c = match.group(2).strip(" \t")
@@ -3262,8 +3262,8 @@ def run(self, text: str):
32623262
)
32633263
if title:
32643264
if self.md.safe_mode:
3265-
# expose code span contents for escaping - fix #691
3266-
title = self.md._unhash_html_spans(title, spans=False, code=True)
3265+
# expose span contents for escaping - fix #691, #703
3266+
title = self.md._unhash_html_spans(title, spans=True, code=True)
32673267
title = (
32683268
_xml_escape_attr(title)
32693269
.replace('*', self.md._escape_table['*'])
@@ -3282,8 +3282,8 @@ def run(self, text: str):
32823282
continue
32833283

32843284
if link_text and self.md.safe_mode:
3285-
# expose code span contents for escaping - fix #699
3286-
link_text = self.md._unhash_html_spans(link_text, spans=False, code=True)
3285+
# expose span contents for escaping - fix #699, #703
3286+
link_text = self.md._unhash_html_spans(link_text, spans=True, code=True)
32873287

32883288
start_idx -= 1
32893289
result, skip = self.process_image(url, title_str, link_text)

test/tm-cases/image_title_xss_issue691.html

Lines changed: 0 additions & 1 deletion
This file was deleted.

test/tm-cases/image_title_xss_issue691.text

Lines changed: 0 additions & 1 deletion
This file was deleted.

test/tm-cases/latex.html

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ <h2>Simple Test</h2>
55

66
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mrow><mi>x</mi><mo>&#x0003D;</mo><mfrac><mrow><mo>&#x02212;</mo><mi>b</mi><mi>&#x000B1;</mi><msqrt><mrow><msup><mi>b</mi><mn>2</mn></msup><mo>&#x02212;</mo><mn>4</mn><mi>a</mi><mi>c</mi></mrow></msqrt></mrow><mrow><mn>2</mn><mi>a</mi></mrow></mfrac></mrow></math>
77

8-
<p>This code block will not have the math rendered.
9-
<code>
10-
some random code, describing $a and $b will not be rendered, $y=mx$
11-
</code>
12-
This will not work either <code>$\sqrt{2}</code> or</p>
8+
<p>This code block will not have the math rendered.</p>
139

14-
<p><code>
15-
$$
10+
<pre><code>some random code, describing $a and $b will not be rendered, $y=mx$
11+
</code></pre>
12+
13+
<p>This will not work either <code>$\sqrt{2}</code> or</p>
14+
15+
<pre><code>$$
1616
f = 12
1717
$$
18-
</code></p>
18+
</code></pre>

test/tm-cases/latex.opts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"extras": ["latex","latex2mathml"]}
1+
{"extras": ["latex","latex2mathml", "fenced-code-blocks"]}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<p>`
2+
&lt;img src onerror="alert(origin)"&gt;</p>
File renamed without changes.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
`
2+
<img src onerror="alert(origin)">
3+
[x]: `

test/tm-cases/xss_issue699.html

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)