Cross-Site Scripting Vulnerability in react-svg
Summary
GHSA-8xqr-4cpm-wx7g: Cross-Site Scripting in react-svg. Affects react-svg versions < 2.2.18. Fixed in 2.2.18. How to fix ↓
Check if this vulnerability affects your application
Upload a manifest or SBOM and we'll show whether you're affected, plus every other risky package in the same scan.
No signup required · Results in about 60 seconds
Background
react-svg is an npm package that provides a React component for rendering SVG files. It allows developers to easily incorporate SVG images into their React applications. However, versions of react-svg before 2.2.18 are vulnerable to a cross-site scripting (XSS) attack. This vulnerability arises from the fact that scripts found in SVG files are executed by default.
Vulnerability Detail
The cross-site scripting vulnerability in react-svg can be exploited by an attacker to inject malicious scripts into SVG files. When these files are rendered by the react-svg component, the injected scripts will be executed in the context of the user's browser, potentially leading to unauthorized access, data theft, or other malicious activities. This vulnerability has a high severity rating and is classified under CWE-79.
How To Fix
Minimum fixed version
2.2.18
This is the first release that contains the fix.
npm install react-svg@2.2.18
Tip — Not sure which version your app runs? Vulert can match this fix to it. Scan free →
Workaround
If updating react-svg is not immediately feasible, a temporary workaround is to sanitize the SVG files before rendering them with the react-svg component. This can be done by removing any script tags or other potentially malicious content from the SVG files. Here is an example of how to sanitize an SVG file using the DOMPurify library:
import DOMPurify from 'dompurify';
const sanitizedSvg = DOMPurify.sanitize(svgContent);
Conclusion
In conclusion, react-svg versions prior to 2.2.18 are vulnerable to a cross-site scripting (XSS) attack. This vulnerability can be mitigated by updating to the latest version of react-svg or by sanitizing SVG files before rendering them. For further assistance or support in addressing this vulnerability, please contact DevNack.com.
See every vulnerability recorded for react-svg →
FAQ
react-svg is an npm package that provides a React component for rendering SVG files. It simplifies the process of incorporating SVG images into React applications.
Cross-site scripting (XSS) is a type of security vulnerability that allows attackers to inject malicious scripts into web pages viewed by other users. These scripts can be used to steal sensitive information, perform unauthorized actions, or deface websites.
The vulnerability in react-svg arises from the fact that scripts found in SVG files are executed by default. This allows an attacker to inject malicious scripts into SVG files, which will then be executed when rendered by the react-svg component.
The cross-site scripting vulnerability in react-svg can lead to unauthorized access, data theft, or other malicious activities. Attackers can exploit this vulnerability to execute arbitrary scripts in the context of a user's browser, potentially compromising sensitive information or performing actions on behalf of the user.
To protect your application from this vulnerability, it is recommended to update react-svg to version 2.2.18 or later. This version includes a fix that prevents the execution of scripts in SVG files by default. Additionally, you can sanitize SVG files before rendering them with the react-svg component to remove any potentially malicious content.