Skip to content

Commit

Permalink
All: Security: Prevent XSS by sanitizing certain HTML attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
laurent22 committed May 19, 2023
1 parent ccec93e commit 9e90d90
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 12 deletions.
2 changes: 1 addition & 1 deletion packages/app-cli/tests/md_to_html/sanitize_15.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<use href="data:image/svg+xml,&lt;svg id=&apos;x&apos; xmlns=&apos;http://www.w3.org/2000/svg&apos;&gt;&lt;image href=&apos;asdf&apos; onerror=&apos;top.require(`child_process`).execSync(`calc.exe`)&apos; /&gt;&lt;/svg&gt;#x" class="jop-noMdConv">
<use href="#" class="jop-noMdConv">
1 change: 1 addition & 0 deletions packages/app-cli/tests/md_to_html/sanitize_16.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<map name="test" class="jop-noMdConv"><area coords="0,0,1000,1000" href="#" class="jop-noMdConv"/></map><img usemap="#test" src="https://github.com/Ry0taK.png" class="jop-noMdConv"/>
1 change: 1 addition & 0 deletions packages/app-cli/tests/md_to_html/sanitize_16.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<map name="test"><area coords="0,0,1000,1000" href="javascript:top.require(`child_process`).execSync(`calc.exe`)"></map><img usemap="#test" src="https://github.com/Ry0taK.png">
22 changes: 11 additions & 11 deletions packages/renderer/htmlUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,18 +233,18 @@ class HtmlUtils {
delete attrs[attrName];
}

if (name === 'a') {
// Make sure that only non-acceptable URLs are filtered out.
// In particular we want to exclude `javascript:` URLs.
if ('href' in attrs && !this.isAcceptedUrl(attrs['href'])) {
attrs['href'] = '#';
}
// Make sure that only non-acceptable URLs are filtered out. In
// particular we want to exclude `javascript:` URLs. This
// applies to A tags, and also AREA ones but to be safe we don't
// filter on the tag name and process all HREF attributes.
if ('href' in attrs && !this.isAcceptedUrl(attrs['href'])) {
attrs['href'] = '#';
}

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

if (options.addNoMdConvClass) {
Expand Down

0 comments on commit 9e90d90

Please sign in to comment.