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 package | Versions | Reported by |
|---|---|---|
| npm node-tar | < 3.2.2, >= 4.0.0, < 4.4.14, >= 5.0.0, < 5.0.6, >= 6.0.0, < 6.1.1 | CVE 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.1 | GitHub Advisory Database |
| tar_project tar | 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.1 | NVD |
| oracle graalvm | 20.3.3, 21.2.0 | NVD |
| siemens sinec_infrastructure_network_services | before 1.0.1.1 | NVD |
All scores
| GitHub_M | 8.2high CVSS:3.1 | CVSS:3.1/AV:L/AC:L/PR:N/UI:R/S:C/C:H/I:H/A:N |
| GitHub | 8.2high CVSS:3.1 | CVSS:3.1/AV:L/AC:L/PR:N/UI:R/S:C/C:H/I:H/A:N |
| NVD | 8.1high CVSS:3.1 | CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:U/C:N/I:H/A:H |
| NVD | 5.8medium CVSS:2.0 | AV: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
| https://www.npmjs.com/package/tar | product, third-party-advisory, web | |
| https://github.com/npm/node-tar/security/advisories/GHSA-3jfq-g458-7qm9 | mitigation, third-party-advisory, web | |
| https://github.com/npm/node-tar/commit/1f036ca23f64a547bdd6c79c1a44bc62e8115da4 | patch, third-party-advisory, web | |
| https://www.npmjs.com/advisories/1770 | mitigation, third-party-advisory, web | |
| https://www.oracle.com/security-alerts/cpuoct2021.html | patch, third-party-advisory, web | |
| https://cert-portal.siemens.com/productcert/pdf/ssa-389290.pdf | patch, third-party-advisory, web | |
| https://nvd.nist.gov/vuln/detail/CVE-2021-32804 | advisory | |
| https://github.com/npm/node-tar | package | |
Sources
| Source | Record | Licence |
|---|---|---|
| CVE List | CVE-2021-32804 changed 2024-08-03 | CVE Terms of Use |
| GitHub Advisory Database | GHSA-3jfq-g458-7qm9 changed 2026-07-08 | CC-BY-4.0 |
| NVD | CVE-2021-32804 changed 2026-06-17 | Public domain |