CVE-2021-37712 is a high-severity (CVSS 8.6) Path Traversal vulnerability in tar. A fix is available for tar — see the affected versions and patch details below.
Arbitrary File Creation/Overwrite via insufficient symlink protection due to directory cache poisoning using symbolic links
EPSS Exploitation Probability
Probability of exploitation in the next 30 days, from FIRST.org EPSS.
How urgent is this, really
CVE-2021-37712 by exploitation likelihood (EPSS) against impact (CVSS). Outside the shaded patch-first corner.
Where this sits among everything scored
Of 385,987 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 two directories and a symlink with names containing unicode values that normalized to the same value. Additionally, on Windows systems, long path portions would resolve to the same file system entities as their 8.3 "short path" counterparts. A specially crafted tar archive could thus include directories with two forms of the path that resolve to the same file system entity, followed by a symbolic link with a name in the first form, lastly followed by a file using the second form. It led to bypassing 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.
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
6.1.9 || 5.0.10 || 4.4.18
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, when comparing paths in the directory cache and path reservation systems:
- The
String.normalize('NFKD')method is used to first normalize all unicode to its maximally compatible and multi-code-point form. - All slashes are normalized to
/on Windows systems (on posix systems,\is a valid filename character, and thus left intact). - When a symbolic link is encountered on Windows systems, the entire directory cache is cleared. Collisions related to use of 8.3 short names to replace directories with other (non-symlink) types of entries may make archives fail to extract properly, but will not result in arbitrary file writes.
Affected Packages
| Ecosystem | Package | Vulnerable range | Fix |
|---|---|---|---|
| 📦npm | tar | ≥ 3.0.0&&< 4.4.18 | 4.4.18npm install tar@4.4.18 |
| 📦npm | tar | ≥ 5.0.0&&< 5.0.10 | 5.0.10npm install tar@5.0.10 |
| 📦npm | tar | ≥ 6.0.0&&< 6.1.9 | 6.1.9npm install tar@6.1.9 |
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.18 or later, then make sure no transitive (indirect) dependency still pins the vulnerable range — O3 confirms CVE-2021-37712 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 CVE-2021-37712 in your dependencies?
Find it across npm, including transitive dependencies.