On a non-Windows host, extracting a crafted tar with default options makes node-tar (<= 7.5.22, current latest) create a SymbolicLink whose target resolves OUTSIDE the extraction directory, breaking the documented guarantee that "Link and SymbolicLink entries are not allowed to target locations outside of the extraction folder". This allows arbitrary file read / extraction-containment escape (CWE-22 / CWE-59). Confirmed end-to-end on tar@7.5.22 with default tar.x() (async and sync), including reading /etc/passwd. It is distinct from, and survives, the drive-relative fixes (GHSA-9ppj-qmqm-q256 / CVE-2026-31802, GHSA-qffp-2rhf-9h96).
Root cause is a separator-handling difference between the containment CHECK and the symlink CREATE.
In Unpack[STRIPABSOLUTEPATH] (src/unpack.ts), the symlink linkpath is split for the ".." containment check AFTER stripped.replaceAll(/\/g, '/') — i.e. "" is treated as a path separator when counting segments.
But on non-Windows, normalizeWindowsPath (src/normalize-windows-path.ts) is the identity function, and the symlink is created with the RAW linkpath: SYMLINK -> LINK calls fs.symlink(entry.linkpath, entry.absolute) (src/unpack.ts, ~lines 640-660 and 866-881), where "" is an ordinary filename character.
So a segment like "A\B" counts as TWO segments to the check but ONE to the kernel. Backslash padding inflates the check's segment count, so a ".." run that the check believes stays inside cwd actually escapes it at creation/resolution time.
Walkthrough for entry.linkpath = "A\B/../../x":
The escape depth equals the number of backslashes in the padding segment (overshooting saturates at "/"), so any path on the same filesystem is reachable regardless of cwd depth.
Why the other guards do not catch it: ENSURE_NO_SYMLINK (src/unpack.ts, ~lines 679-698) only rejects EXISTING symlinks found in the target path, not cwd-escape; and CHECKPATH's defense-in-depth validates entry.path (the entry's own path), not the linkpath.
Scope note (per README "Security Information"): this breaks the stated protection "Link and SymbolicLink entries are not allowed to target locations outside of the extraction folder", so it is reportable under "not properly enforcing the intended security protections". It is NOT the out-of-scope case in warning #1 (extracting into an attacker-controlled folder / TOCTOU symlink-swap): this is deterministic, driven solely by the archive's own contents, into a normal folder, with no race and no second actor. It is the same class as the accepted/fixed GHSA-9ppj-qmqm-q256, via a different mechanism (backslash separator differential vs. drive-relative prefix).
Suggested fix: make the containment check use the same separator semantics as creation — when platform !== 'win32', do NOT treat "" as a separator (skip the replaceAll(/\/g,'/')) so segment counting matches the kernel. Better still, decide containment from the single resolved absolute target that creation actually uses — require path.resolve(path.dirname(entry.absolute), entry.linkpath) to be within cwd — instead of a separate path.posix lexical model that can diverge from it.
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").
Arbitrary file read / extraction-containment escape (CWE-22 / CWE-59). A malicious tarball (for example an npm package, or any user-uploaded or third-party archive) extracted with default options plants a symlink that resolves to an arbitrary host path on the same filesystem. Any consumer that then reads, copies, or serves files from the "contained" extraction directory is induced to read arbitrary host files. node-tar is a dependency of npm itself and of a large fraction of the ecosystem, so the exposure is broad.
Arbitrary WRITE is NOT achieved: mkdir rejects symlinked parent components (SymlinkError, src/mkdir.ts), a file written at the symlink's own path unlinks the symlink first, and hardlink entries reject any "..". So node-tar does not itself write outside the extraction target; the impact is the escaping symlink / arbitrary read.
{
"cwe_ids": [
"CWE-22",
"CWE-59"
],
"github_reviewed": true,
"github_reviewed_at": "2026-12-02T01:09:07Z",
"nvd_published_at": "2026-12-01T18:17:28Z",
"severity": "HIGH"
}