CVE-2021-39135: @npmcli/arborist UNIX Symbolic Link (Symlink) Following Vulnerability

HIGH
Advisory Identifier: GHSA-gmw6-94gg-2rc2
CVSS 8.2
CWE-59 CWE-61
Published
Advisory Summary

CVE-2021-39135 is a HIGH (CVSS 8.2) unix symbolic link (symlink) following vulnerability (CWE-59: Improper Link Resolution Before File Access ('Link Following')) affecting @npmcli/arborist libraries in the npm ecosystem. The issue involves unix symbolic link (symlink) following in @npmcli/arborist. Remediation is available by upgrading affected packages to version 2.8.2.

CVE-2021-39135 at a Glance

CVE Identifier CVE-2021-39135
GHSA Identifier GHSA-gmw6-94gg-2rc2
Severity HIGH
CVSS v3.1 Base Score 8.2
CWE Classification CWE-59: Improper Link Resolution Before File Access ('Link Following')
Affected Product @npmcli/arborist
Package Ecosystem npm
Published Date
Last Updated

Security Impact

CVSS: 8.2

The security impact metrics below are parsed directly from the CVSS v3.1 vector string (CVSS:3.1/AV:L/AC:L/PR:N/UI:R/S:C/C:H/I:H/A:N).

Attack Vector Local (AV:L)
Attack Complexity Low (AC:L)
Privileges Required None (PR:N)
User Interaction Required (UI:R)
Scope Changed (S:C)
Confidentiality High (C:H)
Integrity High (I:H)
Availability None (A:N)

How to Fix CVE-2021-39135

To remediate this vulnerability, upgrade all affected @npmcli/arborist dependencies to a patched release. Both direct and transitive dependencies should be checked, as frameworks or security libraries may pull in vulnerable versions transitively.

@npmcli/arborist fixed: 2.8.2
npm install @npmcli/arborist@2.8.2
Verify Direct and Transitive Dependencies

Run the following command in your project directory to verify that all resolved dependencies use the patched release:

npm ls @npmcli/arborist

How to Check if You Are Affected

To determine whether your Node.js application is affected by CVE-2021-39135, inspect your project dependencies using npm:

npm ls @npmcli/arborist

Analyze the terminal output to locate any version of @npmcli/arborist in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 2.8.2), your application is affected.

Note: The npm ls @npmcli/arborist command inspects dependencies declared in your package.json and lockfile; it does not perform automated runtime dynamic scanning.

Technical Details

Vulnerability Mechanism & Technical Analysis

This vulnerability is classified under CWE-59: Improper Link Resolution Before File Access ('Link Following'), where the product attempts to access a file based on the filename, but it does not properly prevent that filename from identifying a link or shortcut that resolves to an unintended resource. In @npmcli/arborist, software state validation or input boundaries are circumvented during processing. Review the official source advisory statement below for specific affected components, classes, and reproduction details.

Source Advisory Statement

### Impact Arbitrary File Creation, Arbitrary File Overwrite, Arbitrary Code Execution `@npmcli/arborist`, the library that calculates dependency trees and manages the node_modules folder hierarchy for the npm command line interface, aims to guarantee that package dependency contracts will be met, and the extraction of package contents will always be performed into the expected folder. This is accomplished by extracting package contents into a project's `node_modules` folder. If the `node_modules` folder of the root project or any of its dependencies is somehow replaced with a symbolic link, it could allow Arborist to write package dependencies to any arbitrary location on the file system. Note that symbolic links contained within package artifact contents are filtered out, so another means of creating a `node_modules` symbolic link would have to be employed. 1. A `preinstall` script could replace `node_modules` with a symlink. (This is prevented by using `--ignore-scripts`.) 2. An attacker could supply the target with a git repository, instructing them to run `npm install --ignore-scripts` in the root. This may be successful, because `npm install --ignore-scripts` is typically not capable of making changes outside of the project directory, so it may be deemed safe. ### Patches 2.8.2 (included in npm v7.20.7 and above) ### Workarounds Do not run `npm install` on untrusted codebases, without first ensuring that the `node_modules` directory in the project is not a symbolic link. ### Fix Prior to extracting any package contents, the `node_modules` folder into which it is extracted is verified to be a real directory. If it is not, then it is removed. Caveat: if you are currently relying on creating a symbolic link to the `node_modules` folder in order to share dependencies between projects, then that will no longer be possible. Please use the `npm link` command, explicit `file:...` dependencies, and/or `workspaces` to share dependencies in a development environment.

CVE-2021-39135 Affected @npmcli/arborist Versions

1 component(s)
Fixed Versions:
2.8.2
Product / Package Ecosystem Affected Versions Fixed Version
@npmcli/arborist
npm
< 2.8.2
2.8.2

References

Frequently Asked Questions

What is CVE-2021-39135?
CVE-2021-39135 is a security vulnerability in @npmcli/arborist involving UNIX Symbolic Link (Symlink) Following in @npmcli/arborist under CWE-59: Improper Link Resolution Before File Access ('Link Following').
Which @npmcli/arborist versions are affected?
Affected versions include releases prior to 2.8.2 across affected packages: @npmcli/arborist.
What version fixes CVE-2021-39135?
Upgrading to 2.8.2 (or the latest patched release for your respective branch) resolves the vulnerability.
Is @npmcli/arborist affected?
Yes, @npmcli/arborist is affected in releases prior to 2.8.2. Upgrade your dependency to 2.8.2 or later.
What is the CVSS score of CVE-2021-39135?
CVE-2021-39135 has a CVSS v3.1 base score of 8.2 (HIGH) with vector string CVSS:3.1/AV:L/AC:L/PR:N/UI:R/S:C/C:H/I:H/A:N.
What CWE is associated with CVE-2021-39135?
CVE-2021-39135 is classified under CWE-59: Improper Link Resolution Before File Access ('Link Following') (The product attempts to access a file based on the filename, but it does not properly prevent that filename from identifying a link or shortcut that resolves to an unintended resource.).
How can I check npm dependencies for CVE-2021-39135?
Run the dependency tree command: 'npm ls @npmcli/arborist'. This command lists direct and transitive dependencies in your build configuration so you can verify if a vulnerable version is resolved.
Machine-readable OSV JSON OSV v1.5 Schema
Normalized schema output
{
  "schema_version" : "1.4.0",
  "id" : "GHSA-gmw6-94gg-2rc2",
  "modified" : "2022-06-17T20:51:19Z",
  "published" : "2021-08-31T16:03:34Z",
  "aliases" : [ "CVE-2021-39135" ],
  "summary" : "UNIX Symbolic Link (Symlink) Following in @npmcli/arborist",
  "details" : "### Impact\n\nArbitrary File Creation, Arbitrary File Overwrite, Arbitrary Code Execution\n\n`@npmcli/arborist`, the library that calculates dependency trees and manages the node_modules folder hierarchy for the npm command line interface, aims to guarantee that package dependency contracts will be met, and the extraction of package contents will always be performed into the expected folder.\n\nThis is accomplished by extracting package contents into a project's `node_modules` folder.\n\nIf the `node_modules` folder of the root project or any of its dependencies is somehow replaced with a symbolic link, it could allow Arborist to write package dependencies to any arbitrary location on the file system.\n\nNote that symbolic links contained within package artifact contents are filtered out, so another means of creating a `node_modules` symbolic link would have to be employed.\n\n1. A `preinstall` script could replace `node_modules` with a symlink.  (This is prevented by using `--ignore-scripts`.)\n2. An attacker could supply the target with a git repository, instructing them to run `npm install --ignore-scripts` in the root.  This may be successful, because `npm install --ignore-scripts` is typically not capable of making changes outside of the project directory, so it may be deemed safe.\n\n### Patches\n\n2.8.2 (included in npm v7.20.7 and above)\n\n### Workarounds\n\nDo not run `npm install` on untrusted codebases, without first ensuring that the `node_modules` directory in the project is not a symbolic link.\n\n### Fix\n\nPrior to extracting any package contents, the `node_modules` folder into which it is extracted is verified to be a real directory.  If it is not, then it is removed.\n\nCaveat: if you are currently relying on creating a symbolic link to the `node_modules` folder in order to share dependencies between projects, then that will no longer be possible.  Please use the `npm link` command, explicit `file:...` dependencies, and/or `workspaces` to share dependencies in a development environment.",
  "severity" : [ {
    "type" : "CVSS_V3",
    "score" : "CVSS:3.1/AV:L/AC:L/PR:N/UI:R/S:C/C:H/I:H/A:N"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "npm",
      "name" : "@npmcli/arborist"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0"
      }, {
        "fixed" : "2.8.2"
      } ]
    } ]
  } ],
  "references" : [ {
    "type" : "WEB",
    "url" : "https://github.com/npm/arborist/security/advisories/GHSA-gmw6-94gg-2rc2"
  }, {
    "type" : "ADVISORY",
    "url" : "https://nvd.nist.gov/vuln/detail/CVE-2021-39135"
  }, {
    "type" : "WEB",
    "url" : "https://cert-portal.siemens.com/productcert/pdf/ssa-389290.pdf"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/npm/arborist"
  }, {
    "type" : "WEB",
    "url" : "https://www.npmjs.com/package/@npmcli/arborist"
  }, {
    "type" : "WEB",
    "url" : "https://www.oracle.com/security-alerts/cpuoct2021.html"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-59", "CWE-61" ],
    "severity" : "HIGH",
    "github_reviewed" : true,
    "github_reviewed_at" : "2021-08-31T16:03:00Z",
    "nvd_published_at" : "2021-08-31T17:15:00Z"
  }
}