Skip to content

Commit 7596ff8

Browse files
Merge pull request #692 from Crozzers/xss-issue691
Fix XSS from code spans in link titles (#691)
2 parents 0499409 + 88d5d87 commit 7596ff8

5 files changed

Lines changed: 7 additions & 0 deletions

File tree

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## python-markdown2 2.5.6 (not yet released)
44

55
- [pull #687] Fix AssertionError hashing HTML blocks spread over multiple lines (#686)
6+
- [pull #692] Fix XSS from code spans in link titles (#691)
67

78

89
## python-markdown2 2.5.5

lib/markdown2.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3270,6 +3270,9 @@ def run(self, text: str):
32703270
.replace('_', self.md._escape_table['_'])
32713271
)
32723272
if title:
3273+
if self.md.safe_mode:
3274+
# expose code span contents for escaping - fix #691
3275+
title = self.md._unhash_html_spans(title, spans=False, code=True)
32733276
title = (
32743277
_xml_escape_attr(title)
32753278
.replace('*', self.md._escape_table['*'])
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<p><img src="x" alt="" title="&lt;code&gt;&quot; onerror=alert(1)//&lt;/code&gt;&quot;" /></p>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{'safe_mode': 'escape'}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
![](x "`" onerror=alert(1)//`"")

0 commit comments

Comments
 (0)