Summary
A path traversal vulnerability in Next.js can allow remote requests to escape the intended incremental-cache directory on Windows-hosted servers. An attacker may disclose private build data, including the server-reference-manifest encryption key, and possession of that key could enable remote code execution in the affected application.
Affected context
The issue can arise in Next.js applications using the Pages Router or App Router without Cache Components when hosted on Windows. It involves route processing and incremental-cache path construction that do not consistently treat encoded Windows path separators as delimiters, potentially allowing cache paths to resolve outside their intended root.
Exploit preconditions
- Attack surface: Remotely accessible Next.js route handling
- Required access: Ability to send requests to the affected application; authentication requirements depend on deployment and route exposure
- Trigger point: Processing of route segments that influence incremental-cache file paths
- Why exploitation is possible: Encoded Windows path separators may be insufficiently escaped before filesystem paths are constructed, allowing resolution beyond the intended cache directory
Why this happens
The underlying bug is improper canonicalization and validation of user-influenced path components on Windows. Route segments containing encoded path separators are not consistently escaped before they participate in incremental-cache path construction, allowing attacker-controlled input to alter the resulting filesystem location. This behavior maps to CWE-22: Improper Limitation of a Pathname to a Restricted Directory, commonly known as path traversal.
Potential impact
- Sensitive build artifacts may be disclosed
- Private application configuration or runtime metadata could be exposed
- The server-reference-manifest encryption key may be revealed
- An attacker could potentially achieve remote code execution in the application
- Application integrity and confidentiality may be compromised
General mitigation guidance
Mitigation generally focuses on treating route-derived filesystem components as untrusted and enforcing containment before file access.
Common defensive patterns include:
- Normalize and validate path components using platform-aware, allowlist-based logic
- Reject encoded separators and traversal indicators before constructing filesystem paths
- Resolve candidate paths and verify that they remain beneath the intended cache root
- Avoid exposing incremental-cache files or build artifacts through request-controlled paths
- Protect sensitive signing and encryption keys using least-privilege secrets management
- Run application processes with only the filesystem permissions they require
- Apply vendor-provided security fixes through the normal dependency maintenance process
How teams detect issues like this
Organizations can look for this class of issue through:
- Static analysis rules targeting path joins that combine request-derived values with filesystem locations
- Code review checks for missing normalization, canonicalization, or cache-root containment validation
- Tests covering encoded forward and backward separators on Windows-specific execution paths
- Runtime monitoring for requests containing encoded traversal patterns or unusual cache-file access
- Policy enforcement that blocks direct exposure of build directories and cache storage
- Automated dependency and security review tools that flag vulnerable framework versions

