CVE-2017-16877: Directory Traversal Vulnerability in next
Summary
CVE-2017-16877: Next.js Directory Traversal Vulnerability. Affects next versions >= 1.0.0, < 2.4.1. Fixed in 2.4.1. 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
next is an open-source framework for building server-side rendered React applications. It provides a streamlined development experience and offers features like automatic code splitting, server-side rendering, and static exporting. The vulnerability affects versions of next.js before 2.4.1. It allows attackers to perform directory traversal under the /_next and /static request namespace, potentially leading to the disclosure of sensitive information.
Vulnerability Detail
The directory traversal vulnerability in next.js allows an attacker to access files outside of the intended directory structure. By manipulating the request path, an attacker can bypass access restrictions and retrieve sensitive information. This can include configuration files, source code, or any other files accessible to the application. The vulnerability has a high severity rating with a CVSS score of 7.5. It was first published on December 5, 2017, and has been reviewed by GitHub.
How To Fix
Latest published version: 16.4.2 as of 22 Oct 2026
npm install next@16.4.2
Upgrading to it may include breaking changes; the version below is the minimum fixed release for this vulnerability.
If you need the minimum change
2.4.1
This is the first release that contains the fix.
npm install next@2.4.1
Tip — Not sure which version your app runs? Vulert can match this fix to it. Scan free →
Workaround
If upgrading to the latest version is not immediately possible, a temporary workaround is to implement additional access controls or input validation to prevent directory traversal attacks. This can involve validating and sanitizing user input, enforcing strict file path restrictions, and implementing proper authorization checks. Here is an example of input validation using regular expressions in Node.js:
const path = require('path');
function validateFilePath(filePath) {
const regex = /^[a-zA-Z0-9_-]+$/;
return regex.test(filePath);
}
const userFilePath = req.query.filePath;
if (!validateFilePath(userFilePath)) {
// Handle invalid file path
}
const resolvedPath = path.resolve(__dirname, 'public', userFilePath);
// Process the file
This code snippet demonstrates how to validate a user-provided file path and resolve it within a restricted directory structure.
Conclusion
The directory traversal vulnerability in next.js before version 2.4.1 allows attackers to obtain sensitive information by performing directory traversal under the /_next and /static request namespace. It is crucial to upgrade to the latest version or apply the recommended workarounds to mitigate the risk of unauthorized access to sensitive data. For further support on vulnerability remediation, you can reach out to DevNack.com.
See every vulnerability recorded for next →
FAQ
Next.js is an open-source framework for building server-side rendered React applications. It provides a streamlined development experience and offers features like automatic code splitting, server-side rendering, and static exporting.
Directory traversal, also known as path traversal, is a vulnerability that allows an attacker to access files outside of the intended directory structure. By manipulating the file path in a request, an attacker can bypass access restrictions and retrieve sensitive information.
The directory traversal vulnerability in next.js can lead to the disclosure of sensitive information. This can include configuration files, source code, or any other files accessible to the application. An attacker could exploit this vulnerability to gain unauthorized access to sensitive data.
To fix this vulnerability, it is recommended to upgrade to version 2.4.1 or later of next.js. This version includes a fix for the directory traversal issue. Update the package using the package manager of your choice, such as npm or yarn.
If upgrading to the latest version is not immediately possible, a temporary workaround is to implement additional access controls or input validation to prevent directory traversal attacks. This can involve validating and sanitizing user input, enforcing strict file path restrictions, and implementing proper authorization checks.
Related vulnerabilities
Recent vulnerabilities recorded for next.