CVE-2026-140235: CVE-2026-140235: PAX Extended Header Forged-Field Injection and Record Dropping in node-tar
CVE-2026-140235: PAX Extended Header Forged-Field Injection and Record Dropping in node-tar Vulnerability ID: CVE-2026-140235 CVSS Score: 7.2 Published: 2026-12-02 A parsing vulnerability in the node-tar archive man
CVE-2026-140235: PAX Extended Header Forged-Field Injection and Record Dropping in node-tar
Vulnerability ID: CVE-2026-140235
CVSS Score: 7.2
Published: 2026-12-02
A parsing vulnerability in the node-tar archive manipulation library for Node.js (versions 7.5.0 through 7.5.24) allows attackers to drop legitimate metadata fields and inject forged entry attributes into tar archives. By splitting POSIX.1-2001 PAX extended headers on newline characters rather than respecting explicit byte-length framing, the parser misinterprets embedded newlines inside attribute values as record delimiters. This enables arbitrary file overwrite within the extraction directory, metadata tampering, archive desynchronization, and arbitrary path traversal when non-default path preservation settings are enabled.
TL;DR
node-tar versions 7.5.0 to 7.5.24 improperly parse PAX extended headers by splitting on newline characters instead of using byte-length framing. Attackers can embed newlines within benign PAX attributes to drop records and inject forged path, size, or linkpath attributes, leading to arbitrary file overwrites and potential directory traversal.
β οΈ Exploit Status: POC
Technical Details
- CVE / Advisory ID: CVE-2026-140235 / GHSA-rgjp-p5j7-w36x
- Affected Package: npm:tar (node-tar) >= 7.5.0, < 8.0.0
- Patched Version: 8.0.0
- Weakness Class: CWE-20 (Improper Input Validation) / CWE-436 (Interpretation Conflict)
- 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)
- Attack Vector: Network (Untrusted Tar Archive Ingestion)
- Primary Impact: PAX Record Dropping, Forged Attribute Injection (path, size, linkpath, mode), Arbitrary File Overwrite
- Exploit / KEV Status: PoC Available (Unit Test Fixtures) / Not in CISA KEV
Affected Systems
- node-tar (npm package: tar) >= 7.5.0, < 8.0.0
-
tar (node-tar): >= 7.5.0, < 8.0.0 (7.5.0 through 7.5.24) (Fixed in:
8.0.0)
Code Analysis
Commit: f351e5b
Replace newline-splitting PAX extended header parser with byte-length cursor scanning and tighten numeric attribute validation.
--- a/src/pax.ts
+++ b/src/pax.ts
@@ -2,7 +2,7 @@ import { basename } from 'node:path'
import type { HeaderData } from './header.js'
import { Header } from './header.js'
-const SIMPLE_NUMBER = /^(?:0|[1-9]\d*)$/
+const SIMPLE_NUMBER = /^\d+$/
export class Pax implements HeaderData {
atime?: Date
@@ -148,25 +148,36 @@ export class Pax implements HeaderData {
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
+}
const parseKVLine = (
set: Record<string, string | number | Date>,
line: string,
) => {
- 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
- }
-
- line = line.slice((n + ' ').length)
const kv = line.split('=')
const r = kv.shift()
@@ -176,7 +187,7 @@ const parseKVLine = (
const k = r.replace(/^SCHILY\.(dev|ino|nlink)/, '$1')
- const v = kv.join('=').replace(/\0.*/, '')
+ const v = kv.join('=').replace(/\0.*/s, '')
switch (k) {
case 'path':
case 'linkpath':
@@ -190,23 +201,21 @@ const parseKVLine = (
case 'ctime':
case 'atime':
case 'mtime':
- set[k] = new Date(Number(v) * 1000)
+ const d = new Date(Number(v) * 1000)
+ if (!isNaN(d.getTime())) set[k] = d
break
case 'size':
- // value must be a string of digits with no negative sign
- if (!SIMPLE_NUMBER.test(v.trim())) break
- const s = +v
- // must be a finite, non-negative integer, like the binary header path
- if (!Number.isSafeInteger(s)) break
- set[k] = s
- break
case 'gid':
case 'uid':
case 'dev':
case 'ino':
case 'nlink':
case 'mode':
- set[k] = +v
+ // value must be a string of decimal digits
+ if (!SIMPLE_NUMBER.test(v.trim())) break
+ const s = +v
+ if (!Number.isSafeInteger(s)) break
+ set[k] = s
break
}
return set
Exploit Details
- GitHub: Official patch commit containing regression test cases demonstrating PAX record dropping and forged-field injection via embedded newlines.
Mitigation Strategies
- Upgrade node-tar (npm package 'tar') to version 8.0.0 or later to ensure byte-length framed PAX extended header parsing.
- Ensure 'preservePaths' is set to false (the default) across all tar extraction calls handling untrusted archives to confine any forged path attributes to the extraction root.
- Pre-validate or sanitize untrusted tar archives at ingestion boundaries by checking PAX header blocks (typeflags 'x' and 'g') for internal newline characters inside record values.
Remediation Steps:
- Identify all direct and transitive dependencies on 'tar' within the project using 'npm ls tar'.
- Update direct dependencies to version 8.0.0 or higher by running 'npm install tar@^8.0.0'.
- If 'tar' >= 7.5.0 < 8.0.0 is required by a transitive dependency, configure an npm 'overrides' or Yarn 'resolutions' entry pinning 'tar' to '^8.0.0' after verifying API compatibility.
- Audit application source code for any occurrences of 'preservePaths: true' in tar extraction options and remove or disable them when processing untrusted inputs.
References
- GitHub Security Advisory GHSA-rgjp-p5j7-w36x
- GitHub Fix Commit f351e5b4a8916bc8c8f821d0ad926a17d26ea237
- node-tar v8.0.0 Release
- Official CVE.org Record for CVE-2026-140235
- National Vulnerability Database (NVD) - CVE-2026-140235
- CVEProject cvelistV5 Record: CVE-2026-140235.json
- CWE-20: Improper Input Validation
- CWE-436: Interpretation Conflict
Read the full report for CVE-2026-140235 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.