CVE-2020-7682: Path Traversal in marked-tree
Summary
CVE-2020-7682: Path Traversal in marked-tree. Affects marked-tree versions < 0.8.1. 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
marked-tree is an npm package used for parsing and manipulating Markdown files. It provides a convenient way to read and process Markdown files in Node.js applications. However, versions up to and including 0.8.1 of marked-tree are vulnerable to a path traversal vulnerability. This vulnerability arises due to the lack of path sanitization in the fs.readFile function in index.js.
Vulnerability Detail
The path traversal vulnerability in marked-tree allows an attacker to access files outside of the intended directory. By providing a specially crafted path, an attacker can navigate to sensitive files on the host system. This could lead to unauthorized access, information disclosure, or even remote code execution depending on the context in which the vulnerable code is used. The vulnerability has a CVSS score of 7.5, indicating a high severity.
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
As a temporary workaround, you can implement your own path sanitization logic before passing the path to the fs.readFile function. Ensure that the path only contains the necessary characters and restrict access to files outside of the intended directory. Here's an example of how you can sanitize the path:
const path = require('path');
function sanitizePath(filePath) {
const basePath = '/path/to/markdown/files'; // Set the base path to the directory containing your Markdown files
const resolvedPath = path.resolve(basePath, filePath);
if (!resolvedPath.startsWith(basePath)) {
throw new Error('Invalid file path');
}
return resolvedPath;
}
Before calling fs.readFile, pass the file path through the sanitizePath function to ensure it is safe.
Conclusion
The path traversal vulnerability in marked-tree can be mitigated by upgrading to a fixed version of the package or by implementing path sanitization logic. It is crucial to address this vulnerability promptly to prevent potential unauthorized access or information disclosure. For further support on vulnerability remediation, please contact DevNack.com.
See every vulnerability recorded for marked-tree →
FAQ
marked-tree is an npm package used for parsing and manipulating Markdown files in Node.js applications. It provides a convenient way to read and process Markdown files.
All versions up to and including 0.8.1 of marked-tree are affected by this vulnerability.
The path traversal vulnerability in marked-tree allows an attacker to access files outside of the intended directory. This could lead to unauthorized access, information disclosure, or remote code execution depending on the context.
To fix this vulnerability, upgrade to a version of marked-tree that is equal to or greater than 0.8.2.
Yes, you can implement your own path sanitization logic before passing the path to the fs.readFile function. Ensure that the path only contains the necessary characters and restrict access to files outside of the intended directory.