Skip to content

Commit

Permalink
Desktop: Security: Protect against certain types of DOM clobbering
Browse files Browse the repository at this point in the history
attacks
  • Loading branch information
personalizedrefrigerator committed Jan 6, 2025
1 parent 1cdb74b commit ad0323e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
2 changes: 2 additions & 0 deletions packages/app-cli/tests/md_to_html/sanitize_22.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<img src="test/" class="jop-noMdConv"/>
<img src="http://example.com/test.png" class="jop-noMdConv"/>
3 changes: 3 additions & 0 deletions packages/app-cli/tests/md_to_html/sanitize_22.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<img name=getElementById src=test/>

<IMG NAME="getElementById" SRC="http://example.com/test.png">
6 changes: 6 additions & 0 deletions packages/renderer/htmlUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,12 @@ class HtmlUtils {
attrs['href'] = '#';
}

// Allowing the 'name' attribute allows an attacker to overwrite
// DOM methods (e.g. getElementById) with elements.
if ('name' in attrs) {
delete attrs['name'];
}

// We need to clear any such attribute, otherwise it will
// make any arbitrary link open within the application.
if ('data-from-md' in attrs) {
Expand Down

0 comments on commit ad0323e

Please sign in to comment.