node-tar: Symlink linkpath containment bypass via entry paths ending in '/.'
Published 2 Dec 2026 · Updated 2 Dec 2026
Affected package
- Affected
- >=7.5.5 <8.0.0
- Fixed in
- 8.0.0
npm install tar@8.0.0Which tar does your project really install?
Works for private projects: the file is read in memory to run the scan and then dropped. Also reads yarn.lock, pnpm-lock.yaml or package.json.
Public repo?
Look after several JavaScript apps? Indie watches up to 15 repos, private ones too, for $5 a month. See Indie
Details
Summary
A relative symlink linkpath is validated against path.posix.dirname(entry.path) but created at path.resolve(cwd, entry.path). An entry named 'x/.' shifts the check's base one level shallower, so one '..' is absorbed by the check and the link still escapes the extraction directory, with default options and no warning. Regression in 7.5.5-7.5.22 (introduced by the #450 fix).
Details
Mechanism
[STRIPABSOLUTEPATH] resolves a relative linkpath against path.posix.dirname(entry.path) (src/unpack.ts:286), but the link is created at path.resolve(cwd, entry.path) (src/unpack.ts:359).
For an entry name ending in /., dirname returns a base one level shallower than the directory the link is actually created in. The check therefore normalises x/../outside/secret.txt to outside/secret.txt, which passes startsWith('../') at :291, while the kernel resolves the link from cwd and lands outside the destination.
Affected
>= 7.5.5, <= 7.5.22. The regression was introduced by e9a1ddb (the #450 relative-linkpath fix). 7.5.4 rejects the entry with linkpath contains '..'.
Fix
const base = path.posix.dirname(normalize(entry.path))
Using the same base the filesystem will use makes the check and the write agree. Verified against a 1,464-pair property corpus: 300 buggy pairs rejected, 0 legitimate pairs rejected, 0 new accepts; 677 existing tests pass.
Notes
Distinct from GHSA-9ppj-qmqm-q256: that finding is a malicious *linkpath* string (C:..); here the linkpath is ordinary and the defect is the entry-path base computation. #450 introduced this code, so it is the regression rather than a duplicate.
Proof of concept
Reproduced against the npm-published tar@7.5.22 (not only a source checkout), with one archive entry and default options:
{ path: 'x/.', type: 'SymbolicLink', linkpath: '../outside/secret.txt' }pad x -> ../outside/secret.txt realpath resolves outside dest warnings: [] ctrl path 'x' (no '/.') rejected: "linkpath escapes extraction directory" strip strip:1 (pacote/npm path) x -> ../outside/secret.txt warnings: [] 7.5.4 baseline rejected: "linkpath contains '..'"
The x/. entry is created with the escaped target, with default options, and emits no warning. It also works with strip: 1, PAX path and GNU L.
PoC and controls: poc-linkpath-pad.mjs plus a version-regression script (7.5.2 vs 7.5.22).
Impact
A crafted archive can create a symlink pointing outside the extraction directory using default options and without any warning.
node-tar's own subsequent entries cannot follow the link — mkdir refuses symlink parents and file writes use O_NOFOLLOW — so the outside write is consumer-mediated: a caller that later writes through the extracted path writes outside the destination. This is the same impact model as the accepted GHSA-9ppj-qmqm-q256 / CVE-2026-31802, and it is not claimed to be an in-library write or npm RCE.
Is GHSA-jmj2-9c5q-vw73 in any of your client repos?
Checking one package by hand is fine. Checking it across forty client projects is not. NPMscan reads the lockfiles in every GitHub repo you pick, finds each project with an affected tar, and gives you the command that fixes it.
More advisories for tar
- HighCVE-2026-140234node-tar: Incomplete NUL-byte truncation in ustar, GNU, and PAX names causes name differentials and async crashes · 2 Dec 2026
- HighCVE-2026-140235node-tar parses PAX extended headers by newline-splitting instead of length-delimiting, causing record dropping and forged-field injection · 2 Dec 2026
- HighCVE-2026-140236node-tar: Archive framing differential from PAX size still being applied to GNU/PAX meta entries via ReadEntry and related size/precedence inconsistencies · 2 Dec 2026
- MediumCVE-2026-140237node-tar: ReadEntry pending PAX size reapplication permits metadata-body file smuggling · 2 Dec 2026
- HighCVE-2026-140238node-tar: Newline injection in PAX extended-header records enables entry-attribute forgery (path overwrite → npm postinstall RCE on Windows) · 2 Dec 2026
- HighCVE-2026-140239node-tar: Global PAX extended header injects attacker-controlled linkpath into tar.Parser entries, bypassing strict-mode validation · 2 Dec 2026
References
Advisory data from OSV.dev (opens OSV.dev in a new tab), refreshed daily.