CVE-2021-32804
JSON

8.2high

Arbitrary File Creation/Overwrite due to insufficient absolute path sanitization

Severity
8.2high CVSS:3.1 by GitHub_M
Exploit likelihood
15.1% (higher than 97% of CVEs)
Published
Last changed
Assigned by
GitHub_M
Also known as
GHSA-3jfq-g458-7qm9

Description

The npm package "tar" (aka node-tar) before versions 6.1.1, 5.0.6, 4.4.14, and 3.3.2 has a arbitrary File Creation/Overwrite vulnerability due to insufficient absolute path sanitization. node-tar aims to prevent extraction of absolute file paths by turning absolute paths into relative paths when the `preservePaths` flag is not set to `true`. This is achieved by stripping the absolute path root from any absolute file paths contained in a tar file. For example `/home/user/.bashrc` would turn into `home/user/.bashrc`. This logic was insufficient when file paths contained repeated path roots such as `////home/user/.bashrc`. `node-tar` would only strip a single path root from such paths. When given an absolute file path with repeating path roots, the resulting path (e.g. `///home/user/.bashrc`) would still resolve to an absolute path, thus allowing arbitrary file creation and overwrite. This issue was addressed in releases 3.2.2, 4.4.14, 5.0.6 and 6.1.1. Users may work around this vulnerability without upgrading by creating a custom `onentry` method which sanitizes the `entry.path` or a `filter` method which removes entries with absolute paths. See referenced GitHub Advisory for details. Be aware of CVE-2021-32803 which fixes a similar bug in later versions of tar.

Affected

Product or packageVersionsReported by
npm node-tar< 3.2.2, >= 4.0.0, < 4.4.14, >= 5.0.0, < 5.0.6, >= 6.0.0, < 6.1.1CVE List
tar (npm)before 3.2.2, from 4.0.0 before 4.4.14, from 5.0.0 before 5.0.6, from 6.0.0 before 6.1.1GitHub Advisory Database
tar_project tarbefore 3.2.2, from 4.0.0 before 4.4.14, from 5.0.0 before 5.0.6, from 6.0.0 before 6.1.1NVD
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
NVD8.1high CVSS:3.1CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:U/C:N/I:H/A:H
NVD5.8medium CVSS:2.0AV:N/AC:M/Au:N/C:N/I:P/A:P

Classification

What each source says

CVE List

The npm package "tar" (aka node-tar) before versions 6.1.1, 5.0.6, 4.4.14, and 3.3.2 has a arbitrary File Creation/Overwrite vulnerability due to insufficient absolute path sanitization. node-tar aims to prevent extraction of absolute file paths by turning absolute paths into relative paths when the `preservePaths` flag is not set to `true`. This is achieved by stripping the absolute path root from any absolute file paths contained in a tar file. For example `/home/user/.bashrc` would turn into `home/user/.bashrc`. This logic was insufficient when file paths contained repeated path roots such as `////home/user/.bashrc`. `node-tar` would only strip a single path root from such paths. When given an absolute file path with repeating path roots, the resulting path (e.g. `///home/user/.bashrc`) would still resolve to an absolute path, thus allowing arbitrary file creation and overwrite. This issue was addressed in releases 3.2.2, 4.4.14, 5.0.6 and 6.1.1. Users may work around this vulnerability without upgrading by creating a custom `onentry` method which sanitizes the `entry.path` or a `filter` method which removes entries with absolute paths. See referenced GitHub Advisory for details. Be aware of CVE-2021-32803 which fixes a similar bug in later versions of tar.

GitHub Advisory Database
Impact

Arbitrary File Creation, Arbitrary File Overwrite, Arbitrary Code Execution

node-tar aims to prevent extraction of absolute file paths by turning absolute paths into relative paths when the preservePaths flag is not set to true. This is achieved by stripping the absolute path root from any absolute file paths contained in a tar file. For example /home/user/.bashrc would turn into home/user/.bashrc.

This logic was insufficient when file paths contained repeated path roots such as ////home/user/.bashrc. node-tar would only strip a single path root from such paths. When given an absolute file path with repeating path roots, the resulting path (e.g. ///home/user/.bashrc) would still resolve to an absolute path, thus allowing arbitrary file creation and overwrite.

Patches

3.2.2 || 4.4.14 || 5.0.6 || 6.1.1

NOTE: an adjacent issue CVE-2021-32803 affects this release level. Please ensure you update to the latest patch levels that address CVE-2021-32803 as well if this adjacent issue affects your node-tar use case.

Workarounds

Users may work around this vulnerability without upgrading by creating a custom onentry method which sanitizes the entry.path or a filter method which removes entries with absolute paths.

const path = require('path')
const tar = require('tar')

tar.x({
  file: 'archive.tgz',
  // either add this function...
  onentry: (entry) => {
    if (path.isAbsolute(entry.path)) {
      entry.path = sanitizeAbsolutePathSomehow(entry.path)
      entry.absolute = path.resolve(entry.path)
    }
  },

  // or this one
  filter: (file, entry) => {
    if (path.isAbsolute(entry.path)) {
      return false
    } else {
      return true
    }
  }
})

Users are encouraged to upgrade to the latest patch versions, rather than attempt to sanitize tar input themselves.

NVD (es)

El paquete npm "tar" (también se conoce como node-tar) versiones anteriores a 6.1.1, 5.0.6, 4.4.14 y 3.3.2, presenta una vulnerabilidad de Creación y Sobrescritura de archivos arbitraria debido a un saneo insuficiente de rutas absolutas. node-tar pretende impedir la extracción de rutas absolutas de archivos al convertir las rutas absolutas en relativas cuando el flag "preservePaths" no está establecido en "true". Esto se consigue eliminando el root de la ruta absoluta de cualquier ruta de archivo absoluta contenida en un archivo tar. Por ejemplo, "home/user/.bashrc" se convertiría en "home/user/.bashrc". Esta lógica era insuficiente cuando las rutas de los archivos contenían roots de ruta repetidas, como "////home/user/.bashrc". "node-tar" sólo eliminaba un único root de esas rutas. Cuando se daba una ruta de archivo absoluta con raíces de ruta repetidas, la ruta resultante (por ejemplo, "///home/user/.bashrc") seguía resolviéndose como una ruta absoluta, permitiendo así la creación y sobrescritura de archivos arbitraria. Este problema se ha solucionado en las versiones 3.2.2, 4.4.14, 5.0.6 y 6.1.1. Los usuarios pueden solucionar esta vulnerabilidad sin necesidad de actualizar al crear un método personalizado "onentry" que sanee "entry.path" o un método "filter" que elimine las entradas con rutas absolutas. Consulte el aviso de GitHub mencionado para obtener más detalles. Tenga en cuenta CVE-2021-32803 que corrige un error similar en versiones posteriores de tar

References

Sources

SourceRecordLicence
CVE ListCVE-2021-32804 changed 2024-08-03CVE Terms of Use
GitHub Advisory DatabaseGHSA-3jfq-g458-7qm9 changed 2026-07-08CC-BY-4.0
NVDCVE-2021-32804 changed 2026-06-17Public domain