Skip to content

Commit d3562fc

Browse files
authored
Merge pull request from GHSA-xc2r-jf2x-gjr8
Fix XSS vulnerability
2 parents 0004635 + c35e032 commit d3562fc

File tree

5 files changed

+24
-4
lines changed

5 files changed

+24
-4
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"url": "https://github.com/shubhamjain/svg-loader.git"
1010
},
1111
"main": "dist/svg-loader.min.js",
12-
"version": "1.6.8",
12+
"version": "1.6.9",
1313
"scripts": {
1414
"postinstall": "npm-run-all build:*",
1515
"build:js": "cross-env NODE_ENV=production webpack build",

svg-loader.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,12 @@ const getAllEventNames = () => {
6262
}
6363
}
6464

65+
// SVG <animate> events
66+
DOM_EVENTS.push('onbegin', 'onend', 'onrepeat');
67+
68+
// Some non-standard events, just in case the browser is handling them
69+
DOM_EVENTS.push('onfocusin', 'onfocusout', 'onbounce', 'onfinish', 'onshow');
70+
6571
return DOM_EVENTS;
6672
};
6773

@@ -128,7 +134,7 @@ const renderBody = (elem, options, body) => {
128134
}
129135

130136
// Remove "javascript:..." unless specifically enabled
131-
if (["href", "xlink:href"].includes(name) && value.startsWith("javascript") && !enableJs) {
137+
if (["href", "xlink:href", "values"].includes(name) && value.startsWith("javascript") && !enableJs) {
132138
attributesToRemove.push(name);
133139
}
134140
}
@@ -391,4 +397,4 @@ globalThis.SVGLoader.destroyCache = async () => {
391397
localStorage.removeItem(key);
392398
}
393399
});
394-
}
400+
}

test/icons/svg-xss-2.svg

Lines changed: 3 additions & 0 deletions
Loading

test/icons/svg-xss.svg

Lines changed: 3 additions & 0 deletions
Loading

test/index.html

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
<html>
22
<head>
3-
<link rel="stylesheet" href="/main.css">
43
<style>
54
body {
65
padding-bottom: 80px;
@@ -61,6 +60,15 @@ <h1>
6160
<div>This is a more complicated SVG with JS, only map with overlay message should be shown</div>
6261
<svg data-src="./USStates.svg"></svg>
6362

63+
<div class="heading">Icon with XSS</div>
64+
<div>Tricky XSS that needs to be filtered out. On clicking "X" nothing should happen </div>
65+
<svg data-src="/icons/svg-xss.svg"></svg>
66+
67+
<div class="heading">Icon with XSS 2</div>
68+
<div>Alert should not come</div>
69+
<svg data-src="/icons/svg-xss-2.svg"></svg>
70+
71+
6472
<div class="heading">Icon with JS (enabled)</div>
6573
<div>On hover alert should be thrown</div>
6674
<svg data-src="/icons/cog-with-script.svg" data-js="enabled"></svg>

0 commit comments

Comments
 (0)