CVE-2021-39135
JSON

8.2high

UNIX Symbolic Link (Symlink) Following in @npmcli/arborist

Severity
8.2high CVSS:3.1 by GitHub_M
Exploit likelihood
0.57% (higher than 48% of CVEs; EPSS, by FIRST)
Published
Last changed
Assigned by
GitHub_M
Also known as
GHSA-gmw6-94gg-2rc2

Description

`@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. This is patched in @npmcli/arborist 2.8.2 which is included in npm v7.20.7 and above. For more information including workarounds please see the referenced GHSA-gmw6-94gg-2rc2.

Affected

Product or packageVersionsReported by
npm arborist< 2.8.2CVE List
@npmcli/arborist (npm)before 2.8.2GitHub Advisory Database
npmjs arboristbefore 2.8.2NVD
oracle graalvm20.3.3, 21.2.0NVD
siemens sinec_infrastructure_network_servicesbefore 1.0.1.1NVD

All scores

GitHub_M8.2high CVSS:3.1CVSS:3.1/AV:L/AC:L/PR:N/UI:R/S:C/C:H/I:H/A:N
GitHub8.2high CVSS:3.1CVSS:3.1/AV:L/AC:L/PR:N/UI:R/S:C/C:H/I:H/A:N
NVD7.8high CVSS:3.1CVSS:3.1/AV:L/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:H
NVD4.4medium CVSS:2.0AV:L/AC:M/Au:N/C:P/I:P/A:P

Classification

What each source says

CVE List

`@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. This is patched in @npmcli/arborist 2.8.2 which is included in npm v7.20.7 and above. For more information including workarounds please see the referenced GHSA-gmw6-94gg-2rc2.

GitHub Advisory Database
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.

NVD (es)

"@npmcli/arborist", la biblioteca que calcula los árboles de dependencia y maneja la jerarquía de carpetas node_modules para la interfaz de línea de comandos de npm, tiene como objetivo garantizar que se cumplan los contratos de dependencia de los paquetes, y que la extracción del contenido de los paquetes sea llevada a cabo siempre en la carpeta esperada. Esto es conseguido extrayendo el contenido de los paquetes en la carpeta "node_modules" de un proyecto. Si la carpeta "node_modules" del proyecto root o cualquiera de sus dependencias se sustituye de algún modo por un enlace simbólico, podría permitir a Arborist escribir las dependencias de los paquetes en cualquier ubicación arbitraria del sistema de archivos. Tenga en cuenta que los enlaces simbólicos contenidos en los artefactos de los paquetes se filtran, por lo que habría que emplear otro medio para crear un enlace simbólico "node_modules". 1. Un script "preinstall" podría sustituir "node_modules" por un enlace simbólico. (Esto es impedido usando "--ignore-scripts".) 2. Un atacante podría suministrar al objetivo un repositorio git, indicándole que ejecute "npm install --ignore-scripts" en root. Esto podría tener éxito, porque "npm install --ignore-scripts" no suele ser capaz de realizar cambios fuera del directorio del proyecto, por lo que podría considerarse seguro. Esto está parcheado en @npmcli/arborist versión 2.8.2 que se incluye en npm versiones v7.20.7 y superiores. Para más información, incluyendo soluciones, consulte la referencia documento GHSA-gmw6-94gg-2rc2

References

Sources

SourceRecordLicence
CVE ListCVE-2021-39135 changed 2024-08-04CVE Terms of Use
GitHub Advisory DatabaseGHSA-gmw6-94gg-2rc2 changed 2026-07-08CC-BY-4.0
NVDCVE-2021-39135 changed 2026-06-17Public domain