CVE-2026-140236 — Tar — CWE-436
### Summary The GHSA-vmf3 fix (7.5.16, commit 21a8220) stopped `Header.decode` from applying extended-header values to non-file blocks. `ReadEntry`, however, still copies the PAX `size` onto meta entries (GNU long-name/long-link and PAX headers), and the parser uses that value to decide how many bytes belong to the meta entry. node-tar can therefore frame an archive differently from other tar implementations. Three related places in the same code take sizes or precedence from inconsistent sources. ### Details | # | Issue | Location | Default options | |---|---|---|---| | VULN-001 | `ReadEntry` applies `ex`/`gex` `size` to meta entries, and the parser uses it to frame the meta body. This is what GHSA-vmf3 meant to prevent, through a different code path | `src/read-entry.ts:105-110` → `src/parse.ts:241,246` | Yes (`x`, `t`, `Parser`, `Unpack`, `UnpackSync`) | | VULN-004 | `maxMetaEntrySize` is checked against the PAX-overridden `entry.size`, but the meta buffer accumulates `header.size` bytes, so the limit can be exceeded | `src/parse.ts:241` (check) vs `:248` (accumulation) | Yes | | VULN-005 | `ReadEntry` applies the global header after the local one, so global values override local ones (the reverse of PAX semantics), and it applies a global `linkpath`, which `Header` excludes. Commit af04392 fixed this order in `Header` only | `src/read-entry.ts:105-110`, `:145` | Yes | | VULN-003 | When re-packing (`c`/`r`/`u` with `@archive`, or `Pack.add(ReadEntry)`), the written h
### Summary The GHSA-vmf3 fix (7.5.16, commit 21a8220) stopped `Header.decode` from applying extended-header values to non-file blocks. `ReadEntry`, however, still copies the PAX `size` onto meta entries (GNU long-name/long-link and PAX headers), and the parser uses that value to decide how many bytes belong to the meta entry. node-tar can therefore frame an archive differently from other tar implementations. Three related places in the same code take sizes or precedence from inconsistent sources. ### Details | # | Issue | Location | Default options | |---|---|---|---| | VULN-001 | `ReadEntry` applies `ex`/`gex` `size` to meta entries, and the parser uses it to frame the meta body. This is what GHSA-vmf3 meant to prevent, through a different code path | `src/read-entry.ts:105-110` → `src/parse.ts:241,246` | Yes (`x`, `t`, `Parser`, `Unpack`, `UnpackSync`) | | VULN-004 | `maxMetaEntrySize` is checked against the PAX-overridden `entry.size`, but the meta buffer accumulates `header.size` bytes, so the limit can be exceeded | `src/parse.ts:241` (check) vs `:248` (accumulation) | Yes | | VULN-005 | `ReadEntry` applies the global header after the local one, so global values override local ones (the reverse of PAX semantics), and it applies a global `linkpath`, which `Header` excludes. Commit af04392 fixed this order in `Header` only | `src/read-entry.ts:105-110`, `:145` | Yes | | VULN-003 | When re-packing (`c`/`r`/`u` with `@archive`, or `Pack.add(ReadEntry)`), the written h
🎯 What is this vulnerability?
CVE-2026-140236 is a Path Traversal / Archive Manipulation vulnerability (CWE-436: Import of Untrusted Code into Software) in the node-tar library, specifically affecting versions prior to 8.0.0.
The core technical flaw lies in the inconsistent handling of PAX (POSIX.1-2001) extended headers versus GNU tar headers when reading archive entries. Specifically:
1. Metadata Framing Inconsistency: The ReadEntry class incorrectly applies PAX size values to entries that are identified as GNU or PAX metadata entries. This causes node-tar to calculate the length of the archive body differently than standard tar implementations (like GNU tar or Python's tarfile).
2. Bypass of maxMetaEntrySize: Due to the framing mismatch, an attacker can craft an archive where the declared metadata size is small (passing the maxMetaEntrySize check), but the actual bytes consumed from the stream are larger, or vice versa. This desynchronization allows the parser to misinterpret the boundary between the metadata header and the actual file data.
3. PAX Precedence Reversal: The vulnerability allows for a reversal of local-versus-global PAX precedence. In standard tar, local PAX headers override global ones. This flaw allows an attacker to manipulate which size or path value is applied, potentially forcing the library to write data to an unintended location or to create additional, unexpected members in the output archive.
4. Output Archive Injection: When using the repacking feature (Pack.add(ReadEntry)), the mismatch between the declared header size and the copied body bytes can result in "extra" bytes being interpreted as new archive members. This can lead to the creation of files outside the intended extraction directory (path traversal) or the injection of malicious files into a generated archive.
Critical Distinction: This vulnerability does not affect ordinary tar creation from filesystem inputs. It specifically requires the archive-file input repacking feature or the use of Pack.add(ReadEntry) with a maliciously crafted input archive.
⚡ Attack Chain
1. Discovery & Reconnaissance
- Target Identification: The attacker identifies a Node.js application that uses
node-tarfor processing user-uploaded archives (e.g., a plugin installer, a backup restoration service, or a CI/CD pipeline that unpacks artifacts). - Version Fingerprinting: * Check
- Attack Surface Validation: Confirm that the application uses the repacking or streaming read/write functionality of
node-tar(e.g.,tar.x()withreadablestreams ortar.c()withPack.add).
package.json or package-lock.json if exposed (e.g., via a public repository or misconfigured static hosting).
* Use tools like npm audit if the application exposes its dependency tree.
* Behavioral testing: Upload a benign tar file with specific PAX headers and observe error messages or processing delays that might indicate version-specific parsing behavior.
2. Exploitation
The attacker crafts a malicious tar archive that exploits the PAX/GNU header framing inconsistency.Illustrative PoC Concept (Node.js):
Note: The following code is an illustrative example of how an attacker might construct the malicious payload. The exact byte-level manipulation depends on the specific version of node-tar and the implementation details of the PAX header parsing.
const tar = require('tar');
const fs = require('fs');
const path = require('path');
// Step 1: Create a malicious tar file
// The goal is to create a tar entry where the PAX header declares a size
// that causes the parser to misframe the subsequent data.
const maliciousEntry = {
type: 'File',
name: '../../etc/cron.d/malicious', // Path traversal target
mode: 0o755,
uid: 0,
gid: 0,
size: 100, // Declared size
// PAX headers are used to override or extend metadata
pax: {
'size': '1000' // Mismatched or manipulated PAX size
}
};
// In a real exploit, the attacker would manually construct the tar bytes
// to ensure the PAX header length calculation in node-tar < 8.0.0
// results in a misalignment. This often involves:
// 1. A PAX header that claims a certain length.
// 2. Actual data that is shorter/longer, causing the next header
// to be read from the wrong offset.
// 3. This misalignment can cause the 'name' field of the next entry
// to be interpreted as part of the data, or vice versa, allowing
// path traversal or file injection.
// For demonstration, we assume the attacker has crafted a binary blob
// 'malicious.tar' that triggers the flaw.
// const maliciousTarBuffer = fs.readFileSync('./malicious.tar');
// Step 2: Simulate the vulnerable application's behavior
// The application likely does something like:
// tar.x({
// file: 'malicious.tar',
// cwd: '/tmp/safe_dir',
// maxMetaEntrySize: 1024 // This check is bypassed due to framing error
// });
// OR, for output archive injection:
// const pack = new tar.Pack();
// const readEntry = tar.ReadEntry.from(maliciousTarBuffer);
// pack.add(readEntry); // This triggers the repacking flaw
// pack.pipe(fs.createWriteStream('/tmp/output.tar'));Key Exploitation Mechanics:
1. Crafting the Archive: The attacker creates a tar file with a PAX extended header. The PAX header contains a size field that is inconsistent with the actual data block size or the GNU header size.
2. Triggering the Flaw: When node-tar reads this entry, it applies the PAX size to the metadata entry. This causes the internal state machine to miscalculate the end of the current entry.
3. Bypassing maxMetaEntrySize: The check for maxMetaEntrySize is performed on the declared size, not the actual bytes consumed. Due to the framing error, the actual bytes consumed can exceed the limit without triggering the check.
4. Path Traversal/Injection: The misframing allows the parser to interpret subsequent bytes as a new header. If the attacker controls the content of these bytes, they can define a new entry with a path like ../../etc/cron.d/malicious or inject a new file into the output archive.
3. Post-Exploitation
/etc/cron.d/, /var/www/html/, or a Node.js require path), the attacker can achieve RCE./etc/passwd, .env files).🌍 Real World Impact
Based on the CVSS:4.0 vector 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:
Practical Consequences:
node-tar, an attacker can inject malicious code into the build process, leading to supply chain attacks.node-tar to unpack archives, an attacker can corrupt the backup or inject malicious files during restoration.🛡️ Remediation & Mitigation
1. Upgrade
node-tar < 8.0.0node-tar 8.0.0node-tar to version 8.0.0 or later.npm install [email protected]2. Workarounds
Pack.add(ReadEntry) or streaming extraction features with untrusted input. Use only the standard tar.x() with a trusted, pre-validated archive.3. Detection
auditd logs showing writes to /etc/cron.d/ or /var/www/html/ by the Node.js process.
AIDE or Tripwire to detect unauthorized changes to critical system files.4. WAF/ModSecurity Rules
# Example ModSecurity rule to block tar uploads (illustrative)
SecRule REQUEST_HEADERS:Content-Type "tar" \
"id:100001,phase:2,deny,status:403,msg:'Blocked tar upload'"⚠️ Urgency
node-tar < 8.0.0 should be patched immediately. The requirement for user interaction (UI:P) slightly reduces the urgency compared to fully unauthenticated RCE vulnerabilities, but it is still a significant risk, especially in environments where users are expected to upload archives (e.g., CI/CD, plugin systems).[🤖 CVE Professor AI Security Engine]