CVE-2021-23631: Path Traversal in convert-svg packages
Summary
CVE-2021-23631: Path Traversal in convert-svg packages. Affects convert-svg-core versions < 0.5.0. No fix is published. 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
The convert-svg package is a collection of npm packages that provide functionality for converting SVG files to other formats such as PNG and JPEG. The affected packages include convert-svg-core, convert-svg-to-png, and convert-svg-to-jpeg. These packages are widely used for converting SVG files in various applications.
Vulnerability Detail
The vulnerability (CVE-2021-23631) allows an attacker to perform path traversal attacks by exploiting a flaw in the convert-svg packages. By providing a specially crafted SVG file, an attacker can read arbitrary files from the file system. The attacker can then display the content of these files as converted PNG files. This can lead to unauthorized access to sensitive information and potential data breaches.
How To Fix
No fixed version is published for this vulnerability.
Tip — Not sure whether your app is affected? Vulert can check the versions your app actually runs. Scan free →
Workaround
If updating the packages is not immediately feasible, a temporary workaround is to implement input validation and sanitization for SVG files. This can help prevent the exploitation of the path traversal vulnerability. Here is an example of how to validate and sanitize SVG file paths in Node.js:
const path = require('path');
function sanitizeSvgPath(filePath) {
const baseDir = '/path/to/svgs'; // Set the base directory for SVG files
const resolvedPath = path.resolve(baseDir, filePath);
if (!resolvedPath.startsWith(baseDir)) {
throw new Error('Invalid SVG file path');
}
return resolvedPath;
}
This code snippet ensures that the resolved file path is within the specified base directory, preventing any attempts to traverse outside of it.
Conclusion
The path traversal vulnerability in the convert-svg packages (convert-svg-core, convert-svg-to-png, and convert-svg-to-jpeg) can allow an attacker to read arbitrary files from the file system. It is crucial to update the packages to the latest patched versions (0.5.1 or higher) to mitigate this vulnerability. Additionally, implementing input validation and sanitization for SVG file paths can provide a temporary workaround until the packages are updated. For further support on vulnerability remediation, please contact DevNack.com.
See every vulnerability recorded for convert-svg-core →
FAQ
The vulnerability allows an attacker to read arbitrary files from the file system and display their content as converted PNG files. This can lead to unauthorized access to sensitive information and potential data breaches.
All versions of convert-svg-core, convert-svg-to-png, and convert-svg-to-jpeg up to and including version 0.5.0 are affected by this vulnerability.
You can use the Vulert Playground (https://vulert.com/scanner) to check if your application is affected by this vulnerability. Simply upload your package-lock.json file to the playground and it will analyze your dependencies for known vulnerabilities.
Yes, a fix is available in the latest versions of the convert-svg packages (0.5.1 or higher). It is recommended to update your package dependencies to ensure you are using the patched versions.
A temporary workaround is to implement input validation and sanitization for SVG file paths. This can help prevent the exploitation of the path traversal vulnerability. Refer to the 'workaround' section for an example implementation.
Related vulnerabilities
Recent vulnerabilities recorded for convert-svg-core.