Arbitrary File Creation/Overwrite via insufficient symlink protection due to directory cache poisoning using symbolic linksGHSA-9r2w-394v-53qc
HIGHGHSA-9r2w-394v-53qc is a high-severity (CVSS 8.2) Path Traversal vulnerability in tar. A fix is available for tar — see the affected versions and patch details below.
EPSS Exploitation Probability
Probability of exploitation in the next 30 days, from FIRST.org EPSS.
How urgent is this, really
GHSA-9r2w-394v-53qc by exploitation likelihood (EPSS) against impact (CVSS). Outside the shaded patch-first corner.
Where this sits among everything scored
Of 385,738 CVEs with a current EPSS score, this one falls in the < 10% band (highlighted). Counts from FIRST.org, log-scaled.
Real-World Exposure
How broadly this vulnerability is actually deployed: weekly install volume shows current usage, and reverse-dependency count shows how many other packages break if it stays unpatched.
tarnpmDescription
Impact
Arbitrary File Creation, Arbitrary File Overwrite, Arbitrary Code Execution
node-tar aims to guarantee that any file whose location would be modified by a symbolic link is not extracted. This is, in part, achieved by ensuring that extracted directories are not symlinks. Additionally, in order to prevent unnecessary stat calls to determine whether a given path is a directory, paths are cached when directories are created.
This logic was insufficient when extracting tar files that contained both a directory and a symlink with the same name as the directory, where the symlink and directory names in the archive entry used backslashes as a path separator on posix systems. The cache checking logic used both \ and / characters as path separators, however \ is a valid filename character on posix systems.
By first creating a directory, and then replacing that directory with a symlink, it was thus possible to bypass node-tar symlink checks on directories, essentially allowing an untrusted tar file to symlink into an arbitrary location and subsequently extracting arbitrary files into that location, thus allowing arbitrary file creation and overwrite.
Additionally, a similar confusion could arise on case-insensitive filesystems. If a tar archive contained a directory at FOO, followed by a symbolic link named foo, then on case-insensitive file systems, the creation of the symbolic link would remove the directory from the filesystem, but not from the internal directory cache, as it would not be treated as a cache hit. A subsequent file entry within the FOO directory would then be placed in the target of the symbolic link, thinking that the directory had already been created.
These issues were addressed in releases 4.4.16, 5.0.8 and 6.1.7.
The v3 branch of node-tar has been deprecated and did not receive patches for these issues. If you are still using a v3 release we recommend you update to a more recent version of node-tar. If this is not possible, a workaround is available below.
Patches
4.4.16 || 5.0.8 || 6.1.7
Workarounds
Users may work around this vulnerability without upgrading by creating a custom filter method which prevents the extraction of symbolic links.
const tar = require('tar')
tar.x({
file: 'archive.tgz',
filter: (file, entry) => {
if (entry.type === 'SymbolicLink') {
return false
} else {
return true
}
}
})
Users are encouraged to upgrade to the latest patched versions, rather than attempt to sanitize tar input themselves.
Fix
The problem is addressed in the following ways:
- All paths are normalized to use
/as a path separator, replacing\with/on Windows systems, and leaving\intact in the path on posix systems. This is performed in depth, at every level of the program where paths are consumed. - Directory cache pruning is performed case-insensitively. This may result in undue cache misses on case-sensitive file systems, but the performance impact is negligible.
Caveat
Note that this means that the entry objects exposed in various parts of tar's API will now always use / as a path separator, even on Windows systems. This is not expected to cause problems, as / is a valid path separator on Windows systems, but may result in issues if entry.path is compared against a path string coming from some other API such as fs.realpath() or path.resolve().
Users are encouraged to always normalize paths using a well-tested method such as path.resolve() before comparing paths to one another.
Affected Packages
| Ecosystem | Package | Vulnerable range | Fix |
|---|---|---|---|
| 📦npm | tar | ≥ 3.0.0&&< 4.4.16 | 4.4.16npm install tar@4.4.16 |
| 📦npm | tar | ≥ 5.0.0&&< 5.0.8 | 5.0.8npm install tar@5.0.8 |
| 📦npm | tar | ≥ 6.0.0&&< 6.1.7 | 6.1.7npm install tar@6.1.7 |
Affected Products
debian linuxdebiantarnpmjsgraalvmoraclesinec infrastructure network servicessiemensDetection & mitigation playbook
Open-source dependencyDetect
Scan your dependency tree (package-lock.json, pnpm-lock.yaml, requirements.txt, go.sum, etc.) for tar, including transitive dependencies — a direct dependency you never call can still pull in a vulnerable version.
Fix
Update tar to 4.4.16 or later, then make sure no transitive (indirect) dependency still pins the vulnerable range — O3 confirms GHSA-9r2w-394v-53qc is resolved across your whole dependency graph.
Workarounds
Resolve every user-supplied path to its canonical form and reject anything that escapes the intended directory, and run the component under an account that has no read or write access outside the directory it legitimately serves.
Fixing This On Your OS
If you run this on a Linux distribution, patch through your package manager against the distro's own security advisory below — it tracks the exact backported fix for your release, which can ship on a different timeline (and sometimes a different severity) than the upstream project.
Red Hat Enterprise Linux version 8 and Red Hat Software Collection both embed `node-tar` in the npm command. However, npm explicitly prevents the extraction of symlink via a filter. npm might still be affected via node-gyp, if the attacker is able to control the target URL.
| Product | Fixed in | Advisory |
|---|---|---|
| Red Hat Enterprise Linux 8 | nodejs:12-8060020220523160029.ad008a3a | RHEA-2022:5139 |
| Red Hat Enterprise Linux 8 | nodejs:14-8050020211213115342.c5368500 | RHSA-2022:0350 |
| Red Hat Enterprise Linux 8.1 Update Services for SAP Solutions | nodejs:12-8010020220518102644.c27ad7f8 | RHEA-2022:4925 |
| Red Hat Enterprise Linux 8.2 Extended Update Support | nodejs:12-8020020220523154454.4cda2c84 | RHEA-2022:5221 |
| Red Hat Enterprise Linux 8.4 Extended Update Support | nodejs:12-8040020220523155137.522a0ee4 | RHEA-2022:5615 |
| Red Hat Enterprise Linux 8.4 Extended Update Support | nodejs:14-8040020211213111158.522a0ee4 | RHSA-2022:0246 |
| Red Hat OpenShift Data Foundation 4.9.0 on RHEL-8 | odf4/cephcsi-rhel8:4.9-164.57484e3.release_4.9 | RHSA-2021:5086 |
| Red Hat Software Collections for Red Hat Enterprise Linux 7 | rh-nodejs14-nodejs-0:14.18.2-1.el7 | RHSA-2022:0041 |
Frequently Asked Questions
Is GHSA-9r2w-394v-53qc in your dependencies?
Find it across npm, including transitive dependencies.