Skip to content

Commit

Permalink
Merge pull request #602 from Crozzers/fix-xss-601
Browse files Browse the repository at this point in the history
Fix XSS issue in safe mode (#601)
  • Loading branch information
nicholasserra authored Sep 23, 2024
2 parents ded5e74 + e266576 commit cc432bf
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
- [pull #590] Fix underscores within bold text getting emphasized (#589)
- [pull #591] Add Alerts extra
- [pull #595] Fix img alt text being processed as markdown (#594)
- [pull #602] Fix XSS issue in safe mode (#601)
- [pull #604] Fix XSS injection in image URLs (#603)


Expand Down
9 changes: 7 additions & 2 deletions lib/markdown2.py
Original file line number Diff line number Diff line change
Expand Up @@ -1260,8 +1260,13 @@ def _run_span_gamut(self, text: str) -> str:
(?:
# tag
</?
(?:\w+) # tag name
(?:\s+(?:[\w-]+:)?[\w-]+=(?:".*?"|'.*?'))* # attributes
(?:\w+) # tag name
(?: # attributes
\s+ # whitespace after tag
(?:[^\t<>"'=/]+:)?
[^<>"'=/]+= # attr name
(?:".*?"|'.*?'|[^<>"'=/\s]+) # value, quoted or unquoted. If unquoted, no spaces allowed
)*
\s*/?>
|
# auto-link (e.g., <http://www.activestate.com/>)
Expand Down
1 change: 1 addition & 0 deletions test/tm-cases/issue601_xss.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<p>&lt;img src=# onerror="alert()"&gt;&lt;/p&gt;</p>
1 change: 1 addition & 0 deletions test/tm-cases/issue601_xss.opts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"safe_mode": "escape"}
1 change: 1 addition & 0 deletions test/tm-cases/issue601_xss.text
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<img src=# onerror="alert()"></p>

0 comments on commit cc432bf

Please sign in to comment.