Skip to content

Commit

Permalink
Merge pull request from GHSA-xc2r-jf2x-gjr8
Browse files Browse the repository at this point in the history
Fix XSS vulnerability
  • Loading branch information
shubhamjain committed Aug 12, 2023
2 parents 0004635 + c35e032 commit d3562fc
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -9,7 +9,7 @@
"url": "https://github.com/shubhamjain/svg-loader.git"
},
"main": "dist/svg-loader.min.js",
"version": "1.6.8",
"version": "1.6.9",
"scripts": {
"postinstall": "npm-run-all build:*",
"build:js": "cross-env NODE_ENV=production webpack build",
Expand Down
10 changes: 8 additions & 2 deletions svg-loader.js
Expand Up @@ -62,6 +62,12 @@ const getAllEventNames = () => {
}
}

// SVG <animate> events
DOM_EVENTS.push('onbegin', 'onend', 'onrepeat');

// Some non-standard events, just in case the browser is handling them
DOM_EVENTS.push('onfocusin', 'onfocusout', 'onbounce', 'onfinish', 'onshow');

return DOM_EVENTS;
};

Expand Down Expand Up @@ -128,7 +134,7 @@ const renderBody = (elem, options, body) => {
}

// Remove "javascript:..." unless specifically enabled
if (["href", "xlink:href"].includes(name) && value.startsWith("javascript") && !enableJs) {
if (["href", "xlink:href", "values"].includes(name) && value.startsWith("javascript") && !enableJs) {
attributesToRemove.push(name);
}
}
Expand Down Expand Up @@ -391,4 +397,4 @@ globalThis.SVGLoader.destroyCache = async () => {
localStorage.removeItem(key);
}
});
}
}
3 changes: 3 additions & 0 deletions test/icons/svg-xss-2.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions test/icons/svg-xss.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 9 additions & 1 deletion test/index.html
@@ -1,6 +1,5 @@
<html>
<head>
<link rel="stylesheet" href="/main.css">
<style>
body {
padding-bottom: 80px;
Expand Down Expand Up @@ -61,6 +60,15 @@ <h1>
<div>This is a more complicated SVG with JS, only map with overlay message should be shown</div>
<svg data-src="./USStates.svg"></svg>

<div class="heading">Icon with XSS</div>
<div>Tricky XSS that needs to be filtered out. On clicking "X" nothing should happen </div>
<svg data-src="/icons/svg-xss.svg"></svg>

<div class="heading">Icon with XSS 2</div>
<div>Alert should not come</div>
<svg data-src="/icons/svg-xss-2.svg"></svg>


<div class="heading">Icon with JS (enabled)</div>
<div>On hover alert should be thrown</div>
<svg data-src="/icons/cog-with-script.svg" data-js="enabled"></svg>
Expand Down

0 comments on commit d3562fc

Please sign in to comment.