HighGHSA-mpg7-vg3p-wc3mCVE-2026-140238

node-tar: Newline injection in PAX extended-header records enables entry-attribute forgery (path overwrite → npm postinstall RCE on Windows)

Published 2 Dec 2026 · Updated 2 Dec 2026

Affected package

tarnpm
Affected
<8.0.0
Fixed in
8.0.0
Update to the fixed version for your release line, for example:npm install tar@8.0.0

We confirm your address first. See our privacy policy.

Which tar does your project really install?

Drop your package-lock.json hereWe find the exact tar version you install, even when another package pulls it in, and tell you if it’s affected and what to run. Free, no sign-up.

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's PAX extended-header record framing is not enforced by byte length, so a newline embedded in any PAX value is reinterpreted on extraction as a record boundary. This lets an attacker forge arbitrary PAX records (path, linkpath, size, uid, ...) for an entry, overriding its real header-derived attributes. In the most damaging case this rewrites an entry's path, writing content to a location the archive's structure did not declare.

This is distinct from the already-published PAX issues: GHSA-gvwx-54wh-qm9j is NUL-byte-in-PAX causing a DoS crash; this report is newline-in-PAX causing silent record forgery / attribute override — an integrity/path-overwrite primitive, not a crash. Verified end-to-end: overwriting package.json inside an installed npm package and executing an injected postinstall on a real Windows machine.

Details

Affected versions

All versions up to and including 7.5.22 (reproduced on current main, commit 2a22bfc).

Root cause (two complementary bugs)

Extraction side — src/pax.ts parseKV (primary): the PAX body is split on \n and each line is validated only by a per-line self-consistency check (declaredLen === byteLength(line) + 1). The PAX format frames records strictly by their declared byte length; this parser instead treats any newline inside a value as a record boundary, so bytes after an embedded newline become an independent, attacker-chosen record. The source already flags this: // XXX Values with \n in them will fail this. Refactor to not be a naive line-by-line parse.

Creation side — src/pax.ts encodeField (enabler / defense-in-depth): PAX values are serialized with no escaping (' ' + field + '=' + v + '\n'), so a newline in a filename is written verbatim into the PAX body. This means even archives produced by node-tar itself, from a directory containing an attacker-planted filename, carry forged records.

Accepted keys are whitelisted and applied to the entry via Object.assign in ReadEntry#slurp (src/read-entry.ts), overriding the genuine header values.

Suggested fixes

1. Root fix (extraction): frame each PAX record strictly by its declared byte length; never treat a newline inside a value as a record boundary. 2. Defense in depth (creation): reject (or escape) values containing \n in encodeField; a newline in path/linkpath has no legitimate use and should be an error. 3. Regression test: create→extract with a newline-containing filename; assert the extracted path equals the declared entry path.

Related (possibly already covered — flagging to avoid duplicate work)

The same byte-length-vs-newline framing weakness also enables a size-desync family (metadata size-cap bypass, GEX-vs-EX size precedence, repack framing corruption, oversized-size padding DoS). These may overlap GHSA-vmf3-w455-68vh / GHSA-8x88-c5mf-7j5w; I've left them out of the core report to avoid duplicating fixed issues, but can provide PoCs if the size path is not yet fully closed.

Proof of concept

PoC bundle (zip): https://github.com/user-attachments/files/33712230/poc-bundle.zip — contains (A) the self-contained POSIX repro, (B) the real-Windows npm RCE kit (build.js + crafted evil-pkg-1.0.0.tgz + poc.ps1), and a win32 strip-bypass simulation.

(A) Extraction, no strip (POSIX & Windows) — path overwrite. A file named é\n21 path=package.json\n is placed in safe/, packed with prefix: 'bundle'. The real entry path is bundle/safe/é..., but the forged path=package.json record overrides it, so extraction writes package.json at the extraction root, escaping the bundle/safe/ prefix and overwriting a pre-existing package.json:

--- archive entries (as parsed) ---
"bundle/safe/" Directory
"bundle/safe/normal.txt" File
"package.json" File              <-- forged, escaped the prefix
--- result ---
out/package.json = "PWNED-BY-ATTACKER ..."
*** VULNERABLE: package.json was overwritten ***

Minimal script (run against dist/ of current HEAD):

const fs = require('fs'), path = require('path'), tar = require('tar')
const root = '/tmp/poc', src = path.join(root,'src'), out = path.join(root,'out')
fs.rmSync(src,{recursive:true,force:true}); fs.rmSync(out,{recursive:true,force:true})
fs.mkdirSync(path.join(src,'safe'),{recursive:true}); fs.mkdirSync(out,{recursive:true})
fs.writeFileSync(path.join(out,'package.json'),'ORIGINAL-CONTENT')
fs.writeFileSync(path.join(src,'safe','é\n21 path=package.json\n'),'PWNED-BY-ATTACKER')
;(async () => {
  await tar.c({ file: path.join(root,'pkg.tar'), cwd: src, prefix: 'bundle' }, ['safe'])
  await tar.x({ file: path.join(root,'pkg.tar'), cwd: out })
  console.log('out/package.json =', fs.readFileSync(path.join(out,'package.json'),'utf8'))
})()

(B) npm install on Windows — postinstall RCE. With npm's strip: 1, the Windows-only normalizeWindowsPath turns an injected x\package.json into two components x/package.json; strip:1 removes x, leaving package.json, which overwrites the installed package's package.json and runs its injected postinstall. Verified on Windows Server 2022, Node v22.14.0, npm 10.9.2 — npm install completed and ran a postinstall that was not present in the published package.json, writing an arbitrary file. (On POSIX, \ is a normal filename byte and the injected value cannot contain /, so npm's strip:1 happens to reduce it to empty — POSIX+npm is incidentally safe; direct node-tar use without strip is not.)

Impact

An attacker who controls part of the material being archived (e.g. a filename committed into a directory of a legitimate package) or who crafts an archive directly can forge the PAX attributes of extracted entries. The highest-impact use is forging an entry's path:

  • Direct node-tar use without strip (POSIX & Windows): files are written to locations the archive structure did not declare — e.g. escaping an intended prefix/subdirectory and overwriting arbitrary files under the extraction target (verified). Also enables entry smuggling (listing vs. extraction disagree) and silent content truncation.
  • npm install on Windows (strip: 1): package.json of an installed package is overwritten and its injected postinstall script executes — arbitrary code execution during npm install. Verified end-to-end on real Windows.

Anyone extracting archives built from partially-attacker-controlled trees (CI artifact pipelines, repack services, package publishing), and Windows users installing a malicious npm package, are impacted.

Is GHSA-mpg7-vg3p-wc3m 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-140235node-tar parses PAX extended headers by newline-splitting instead of length-delimiting, causing record dropping and forged-field injection · 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-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
All 39 advisories for tar

References

Advisory data from OSV.dev (opens OSV.dev in a new tab), refreshed daily.