Skip to content

Commit cc432bf

Browse files
Merge pull request #602 from Crozzers/fix-xss-601
Fix XSS issue in safe mode (#601)
2 parents ded5e74 + e266576 commit cc432bf

File tree

5 files changed

+11
-2
lines changed

5 files changed

+11
-2
lines changed

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
- [pull #590] Fix underscores within bold text getting emphasized (#589)
66
- [pull #591] Add Alerts extra
77
- [pull #595] Fix img alt text being processed as markdown (#594)
8+
- [pull #602] Fix XSS issue in safe mode (#601)
89
- [pull #604] Fix XSS injection in image URLs (#603)
910

1011

lib/markdown2.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1260,8 +1260,13 @@ def _run_span_gamut(self, text: str) -> str:
12601260
(?:
12611261
# tag
12621262
</?
1263-
(?:\w+) # tag name
1264-
(?:\s+(?:[\w-]+:)?[\w-]+=(?:".*?"|'.*?'))* # attributes
1263+
(?:\w+) # tag name
1264+
(?: # attributes
1265+
\s+ # whitespace after tag
1266+
(?:[^\t<>"'=/]+:)?
1267+
[^<>"'=/]+= # attr name
1268+
(?:".*?"|'.*?'|[^<>"'=/\s]+) # value, quoted or unquoted. If unquoted, no spaces allowed
1269+
)*
12651270
\s*/?>
12661271
|
12671272
# auto-link (e.g., <http://www.activestate.com/>)

test/tm-cases/issue601_xss.html

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

test/tm-cases/issue601_xss.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/issue601_xss.text

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

0 commit comments

Comments
 (0)