HighGHSA-hqgx-p3r3-2cfgCVE-2026-140246

node-tar: SymbolicLink extraction escapes the extraction directory on non-Windows hosts via a backslash separator differential

Published 2 Dec 2026 · Updated 2 Dec 2026

Affected package

tarnpm
Affected
<8.0.0
Fixed in
8.0.0
Update to the fixed version for your release line, for example:npm install tar@8.0.0

We confirm your address first. See our privacy policy.

Which tar does your project really install?

Drop your package-lock.json hereWe find the exact tar version you install, even when another package pulls it in, and tell you if it’s affected and what to run. Free, no sign-up.

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

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).

Details

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":

  • CHECK ("\" -> "/"): ["A","B","..","..","x"] -> normalizes to "x" -> believed inside cwd -> ALLOWED
  • CREATE (Linux, "\" literal): ["A\B","..","..","x"] -> from cwd: cwd/A\B -> .. -> cwd -> .. -> parent of cwd -> ESCAPES

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.

Proof of concept

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 <base>/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").

Impact

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.

Is GHSA-hqgx-p3r3-2cfg 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
All 39 advisories for tar

References

Advisory data from OSV.dev (opens OSV.dev in a new tab), refreshed daily.