CVE-2026-140238: CVE-2026-140238: PAX Extended Header Newline Injection and File Overwrite in node-tar
CVE-2026-140238: PAX Extended Header Newline Injection and File Overwrite in node-tar Vulnerability ID: CVE-2026-140238 CVSS Score: 7.2 Published: 2026-12-02 CVE-2026-140238 (GHSA-mpg7-vg3p-wc3m) is a high-severity
CVE-2026-140238: PAX Extended Header Newline Injection and File Overwrite in node-tar
Vulnerability ID: CVE-2026-140238
CVSS Score: 7.2
Published: 2026-12-02
CVE-2026-140238 (GHSA-mpg7-vg3p-wc3m) is a high-severity parsing vulnerability in node-tar versions prior to 8.0.0. By splitting POSIX.1-2001 PAX extended header blocks on raw newline characters instead of enforcing byte-length framing prefixes, the parser allows unescaped newlines within metadata fields to inject forged PAX records. Attackers can override entry attributes such as file paths during extraction, enabling arbitrary file overwrites inside the destination directory and remote code execution on Windows via npm lifecycle script injection.
TL;DR
An improper record framing flaw in node-tar (< 8.0.0) allows newline characters inside PAX extended header values to inject arbitrary metadata attributes like 'path'. This enables arbitrary file overwrites during archive extraction and can lead to Remote Code Execution on Windows systems during npm package installation by overwriting package.json postinstall scripts.
⚠️ Exploit Status: POC
Technical Details
- CVE / Advisory ID: CVE-2026-140238 / GHSA-mpg7-vg3p-wc3m
- CWE Classification: CWE-22 (Path Traversal) / CWE-93 (CRLF Injection)
- CVSS v4.0 Score: 7.2 High (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 Component: node-tar (tar) < 8.0.0 (src/pax.ts, src/read-entry.ts)
- Patched Version: 8.0.0 (Commit f351e5b4a8916bc8c8f821d0ad926a17d26ea237)
- Primary Impact: Arbitrary File Overwrite & Windows npm Postinstall RCE
- Exploit / KEV Status: PoC in Regression Tests / Not in CISA KEV
Affected Systems
- node-tar (npm package: tar) < 8.0.0
- Node.js applications extracting untrusted TAR/TGZ archives via node-tar
- npm CLI package extraction pipelines on Windows platforms using vulnerable node-tar versions
-
node-tar (tar): < 8.0.0 (Fixed in:
8.0.0)
Code Analysis
Commit: f351e5b
Enforce byte-length framing in PAX extended header parser, fix global/local extended header precedence, and add dotAll (/s) flag to null-byte truncation regexes.
diff --git a/src/pax.ts b/src/pax.ts
index d528ae77..e8dd0920 100644
--- a/src/pax.ts
+++ b/src/pax.ts
@@ -148,25 +148,36 @@ const merge = (a: HeaderData, b?: HeaderData) =>
b ? Object.assign({}, b, a) : a
-const parseKV = (str: string) =>
- str
- .replace(/\n$/, '')
- .split('\n')
- .reduce(parseKVLine, Object.create(null))
+// Each record is "<len> <key>=<value>\n". <len> is the byte length of
+// the whole record. A value can contain a newline, so use the length
+// to find the end of the record. Stop at the first malformed record.
+const parseKV = (str: string) => {
+ const set: Record<string, string | number | Date> = Object.create(null)
+ const buf = Buffer.from(str)
+ let pos = 0
+ while (pos < buf.length) {
+ let sp = pos
+ while (
+ sp < buf.length &&
+ (buf[sp] as number) >= 0x30 &&
+ (buf[sp] as number) <= 0x39
+ ) {
+ sp++
+ }
+ if (sp === pos || buf[sp] !== 0x20) break
+ const n = Number(buf.toString('ascii', pos, sp))
+ const end = pos + n
+ if (end <= sp + 1 || end > buf.length || buf[end - 1] !== 0x0a) break
+ parseKVLine(set, buf.toString('utf8', sp + 1, end - 1))
+ pos = end
+ }
+ return set
+}
Exploit Details
- GitHub (Official Regression Test Suite): Regression tests in test/parse-differential.test.ts demonstrating PAX record newline injection overriding entry paths (e.g., 'x\n24 path=forged-name.txt' and 'é\n21 path=package.json\n').
Mitigation Strategies
- Upgrade node-tar (tar on npm) to version 8.0.0 or later to enforce strict byte-length framing on POSIX PAX extended header records.
- Enforce transitive dependency upgrades across Node.js projects using package.json 'overrides' or 'resolutions'.
- Disable automated lifecycle script execution (--ignore-scripts) in npm environments when installing untrusted packages, especially on Windows runners.
- Pre-validate uploaded tar archives at ingestion points to reject PAX extended header records containing embedded newline (0x0A) characters inside field values.
Remediation Steps:
- Audit project dependency trees using 'npm ls tar' to identify all direct and transitive instances of tar < 8.0.0.
- Verify that the target Node.js runtime environment is running Node.js >= 22, as required by tar v8.0.0.
- Update direct dependencies by executing 'npm install tar@^8.0.0'.
- Add '"overrides": { "tar": "^8.0.0" }' to package.json if transitive dependencies pull in tar 6.x or 7.x.
- Run 'npm audit' and execute unit/integration test suites to verify archive extraction behavior.
References
- GitHub Security Advisory: GHSA-mpg7-vg3p-wc3m
- node-tar Repository Advisory: GHSA-mpg7-vg3p-wc3m
- Fix Commit f351e5b4a8916bc8c8f821d0ad926a17d26ea237 in isaacs/node-tar
- node-tar Release v8.0.0
- CVE.org Record: CVE-2026-140238
- NVD Vulnerability Detail: CVE-2026-140238
- CVEProject cvelistV5 Record for CVE-2026-140238
Read the full report for CVE-2026-140238 on our website for more details including interactive diagrams and full exploit analysis.
Originally published by Dev.to Security. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.