CVE-2021-39134 Overview
CVE-2021-39134 is a symlink-based arbitrary file overwrite vulnerability in @npmcli/arborist, the core library responsible for calculating dependency trees and managing the node_modules folder hierarchy for the npm command line interface. The vulnerability exploits a case sensitivity mismatch between Arborist's internal data structures and case-insensitive file systems (macOS and Windows), allowing attackers to write arbitrary contents to any location on the filesystem through specially crafted package dependencies.
Critical Impact
Attackers can overwrite arbitrary files on case-insensitive file systems (Windows, macOS) by exploiting case sensitivity handling in npm's dependency resolution, potentially leading to full system compromise.
Affected Products
- npmjs Arborist versions prior to 2.8.2
- npmjs npm versions 7.20.6 and earlier
- Oracle GraalVM Enterprise Edition 20.3.3 and 21.2.0
- Siemens SINEC Infrastructure Network Services
Discovery Timeline
- 2021-08-31 - CVE CVE-2021-39134 published to NVD
- 2024-11-21 - Last updated in NVD database
Technical Details for CVE-2021-39134
Vulnerability Analysis
The vulnerability resides in how @npmcli/arborist handles package dependency resolution on case-insensitive file systems. Arborist's internal data structure treats package names with different letter casing (e.g., foo vs FOO) as separate, distinct items that can coexist at the same level within the node_modules hierarchy. However, on case-insensitive file systems like those used by macOS and Windows, these names refer to the same directory location.
When combined with symlink dependencies using the file: protocol specifier, this behavior creates a dangerous condition where the contents of one package can be extracted to an arbitrary filesystem location controlled by another package. The attack requires two malicious packages working in concert: one to establish a symlink to the target location and another to overwrite that location with attacker-controlled content.
Root Cause
The root cause is an improper handling of case-insensitive file systems (CWE-178) combined with symlink following vulnerability (CWE-61). Arborist's dependency resolution logic fails to account for the filesystem behavior where directory names differing only in case are treated as identical on macOS and Windows systems. The library's internal data structures permit case-variant names to coexist, but the actual filesystem cannot maintain this separation, leading to unintended file operations.
Attack Vector
This vulnerability requires local access and user interaction to exploit. An attacker must craft two malicious npm packages with coordinated dependency declarations:
- Package pwn-a declares a dependency using a symlink to the target path: "foo": "file:/some/path"
- Package pwn-b declares a dependency with case-variant name containing the payload: "FOO": "file:foo.tgz"
When a victim installs pwn-a followed by pwn-b on a case-insensitive file system, Arborist creates a symlink from node_modules/foo to /some/path. Subsequently, when processing the case-variant FOO dependency, Arborist extracts the contents of foo.tgz to what it believes is a separate node_modules/FOO directory, but the filesystem redirects this to /some/path, overwriting any existing contents at that location.
Detection Methods for CVE-2021-39134
Indicators of Compromise
- Unexpected file modifications or deletions in system directories outside of node_modules
- Package installations with dependencies containing case-variant names (e.g., foo and FOO or Bar and bar)
- Presence of file: protocol dependencies pointing to system paths outside the project directory
- Unusual symlinks within node_modules directories pointing to sensitive filesystem locations
Detection Strategies
- Monitor npm install operations for packages with case-variant dependency names in their package.json manifests
- Implement filesystem integrity monitoring on critical system directories during npm operations
- Audit package.json and package-lock.json files for file: protocol dependencies targeting paths outside the project scope
- Use software composition analysis (SCA) tools to detect vulnerable npm versions in development environments
Monitoring Recommendations
- Enable audit logging for file system operations during npm package installations
- Deploy endpoint detection solutions capable of monitoring for symlink-based attacks and unexpected file writes
- Implement CI/CD pipeline checks to identify packages with suspicious file: protocol dependencies
- Review npm audit reports regularly and alert on installations of vulnerable npm versions
How to Mitigate CVE-2021-39134
Immediate Actions Required
- Upgrade npm to version 7.20.7 or later immediately on all case-insensitive file systems (Windows, macOS)
- Update @npmcli/arborist to version 2.8.2 or later in projects using it as a direct dependency
- Audit existing package-lock.json files for suspicious file: protocol dependencies
- Run npm audit to identify potentially compromised packages in existing projects
Patch Information
The vulnerability is patched in @npmcli/arborist version 2.8.2, which is included in npm v7.20.7 and above. Users should verify their npm version using npm --version and upgrade if running 7.20.6 or earlier. For enterprise deployments, refer to the Oracle Security Alerts October 2021 for GraalVM patches and the Siemens Security Advisory SSA-389290 for SINEC Infrastructure Network Services updates. Additional details are available in the GitHub Security Advisory GHSA-2h3h-q99f-3fhc.
Workarounds
- Use case-sensitive file systems where possible for npm development environments
- Manually review all file: protocol dependencies before installing third-party packages
- Implement strict package policies that prohibit file: protocol dependencies from untrusted sources
- Consider using containerized development environments with isolated file systems
# Verify npm version and upgrade if vulnerable
npm --version
# If version is 7.20.6 or earlier, upgrade immediately
npm install -g npm@latest
# Audit existing projects for vulnerabilities
npm audit
# Check for suspicious file: protocol dependencies
grep -r "file:" package.json package-lock.json
Disclaimer: This content was generated using AI. While we strive for accuracy, please verify critical information with official sources.

