GitHub Advisoryadvisory · npm
GHSA-xc2r-jf2x-gjr8 external-svg-loader Cross-site Scripting vulnerability
CRITICAL
Official page ↗
- Aliases
- CVE-2023-40013
- Ecosystem
- npm
- Packages
- external-svg-loader
- Severity
- Critical
- CVSS vector
- CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H
- Weaknesses
- CWE-79
- Reviewed
- 2023-08-14
Affected packages
• npm external-svg-loader: < 1.6.9 → fixed in 1.6.9
Description
Summary
According to the docs, svg-loader will strip all JS code before injecting the SVG file for security reasons but the input sanitization logic is not sufficient and can be trivially bypassed. This allows an attacker to craft a malicious SVG which can result in XSS.
Details
When trying to sanitize the svg the lib removes event attributes such as `onmouseover`, `onclick` but the list of events is not exhaustive. Here's a list of events not removed by svg-loader.
`onafterscriptexecute, onbeforecopy, onbeforecut, onbeforescriptexecute, onbeforetoggle, onbegin, onbounce, onend, onfinish, onfocusin, onfocusout, onmousewheel, onpointerrawupdate, onrepeat, onsearch, onshow, onstart, ontoggle(popover), ontouchend, ontouchmove, ontouchstart`
As you can see in the POC we can use `onbegin` in `animate` tag to execute JS code without needing to add `data-js="enabled"`.
PoC
```html
```
```html
```
Impact
Any website which uses external-svg-loader and allows its users to provide svg src, upload svg files would be susceptible to stored XSS attack.
Related
Alias · CVE (1)
- CVE-2023-40013 SVG Loader is a javascript library that fetches SVGs using XMLHttpRequests and injects the SVG code in the tag's place. vulnerability
Weakness · CWE (1)
- CWE-79 Improper Neutralization of Input During Web Page Generation weakness
References
- https://github.com/shubhamjain/svg-loader/security/advisories/GHSA-xc2r-jf2x-gjr8 web
- https://nvd.nist.gov/vuln/detail/CVE-2023-40013 advisory
- https://github.com/shubhamjain/svg-loader/commit/d3562fc08497aec5f33eb82017fa1417b3319e2c web
- https://github.com/shubhamjain/svg-loader package
- https://github.com/shubhamjain/svg-loader/blob/main/svg-loader.js#L125-L128 web
- https://github.com/shubhamjain/svg-loader/tree/main#2-enable-javascript web