Skip to content

Commit c2d73a3

Browse files
Merge pull request #700 from Crozzers/fix-xss-699
Fix XSS from code spans in image alt text (#699)
2 parents 8ec7a71 + 9806f75 commit c2d73a3

5 files changed

Lines changed: 8 additions & 0 deletions

File tree

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
- [pull #687] Fix AssertionError hashing HTML blocks spread over multiple lines (#686)
66
- [pull #692] Fix XSS from code spans in link titles (#691)
77
- [pull #695] Fix XSS issue from incomplete tags with no attributes (#694)
8+
- [pull #700] Fix XSS from code spans in image alt text (#699)
89

910

1011
## python-markdown2 2.5.5

lib/markdown2.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3279,6 +3279,10 @@ def run(self, text: str):
32793279
curr_pos = start_idx + 1
32803280
continue
32813281

3282+
if link_text and self.md.safe_mode:
3283+
# expose code span contents for escaping - fix #699
3284+
link_text = self.md._unhash_html_spans(link_text, spans=False, code=True)
3285+
32823286
start_idx -= 1
32833287
result, skip = self.process_image(url, title_str, link_text)
32843288
elif start_idx >= anchor_allowed_pos:

test/tm-cases/xss_issue699.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<p><img src="" alt="&lt;code&gt;&quot; onerror=&quot;alert(1)//&lt;/code&gt;" /></p>

test/tm-cases/xss_issue699.opts

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

test/tm-cases/xss_issue699.text

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
![`" onerror="alert(1)//`]()

0 commit comments

Comments
 (0)