CVE-2019-5444: Path Traversal in serve-here.js
Summary
CVE-2019-5444: Path Traversal in serve-here.js. Affects serve-here.js versions < 1.2.0. Fixed in 1.2.0. 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
serve-here.js is an npm package used for serving files over HTTP. It allows developers to easily create a server and serve files from a specified folder. However, versions prior to 1.2.0 are vulnerable to a path traversal attack. This means that the package fails to properly sanitize URLs, allowing attackers to access server files outside of the served folder using relative paths.
Vulnerability Detail
The path traversal vulnerability in serve-here.js can be exploited by an attacker to access sensitive files on the server. By crafting a malicious URL with a relative path, an attacker can bypass the intended file serving restrictions and retrieve files that should not be accessible. This could lead to unauthorized access to sensitive information or even remote code execution if the accessed files contain executable code.
How To Fix
Minimum fixed version
1.2.0
This is the first release that contains the fix.
npm install serve-here.js@1.2.0
Tip — Not sure which version your app runs? Vulert can match this fix to it. Scan free →
Workaround
If updating to the latest version is not possible, a temporary workaround is to manually sanitize the URLs before passing them to serve-here.js. This can be done by ensuring that the requested paths are within the intended served folder and rejecting any requests that try to access files outside of it. Here's an example of how to implement this workaround in Node.js:
const serveHere = require('serve-here.js');
const path = require('path');
const servedFolder = path.join(__dirname, 'public');
const server = serveHere({
folder: servedFolder,
sanitizeUrl: (url) => {
const requestedPath = path.join(servedFolder, url);
if (!requestedPath.startsWith(servedFolder)) {
throw new Error('Invalid path');
}
return url;
}
});
server.listen(3000);
Conclusion
serve-here.js versions prior to 1.2.0 are vulnerable to a path traversal attack. Developers should update to the latest version or manually sanitize URLs to prevent this vulnerability. For further support on vulnerability remediation, contact DevNack.com.
See every vulnerability recorded for serve-here.js →
FAQ
The vulnerability allows attackers to access server files outside of the intended served folder. This could lead to unauthorized access to sensitive information or even remote code execution.
Versions prior to 1.2.0 are vulnerable to this path traversal attack.
Yes, updating to version 1.2.0 or later of serve-here.js fixes the vulnerability.
Yes, developers can manually sanitize the URLs before passing them to serve-here.js to prevent path traversal attacks.
You can find more information about this vulnerability in the GitHub Advisory Database: https://github.com/github/advisory-database/blob/main/advisories/github-reviewed/2021/09/GHSA-4448-rc82-fcr7/GHSA-4448-rc82-fcr7.json