GHSA-HQGX-P3R3-2CFG

Vulnerability from github – Published: 2026-12-02 01:09 – Updated: 2026-12-02 01:09
VLAI
Summary
node-tar: SymbolicLink extraction escapes the extraction directory on non-Windows hosts via a backslash separator differential
Details

Summary

On a non-Windows host, extracting a crafted tar with default options makes node-tar (<= 7.5.22, current latest) create a SymbolicLink whose target resolves OUTSIDE the extraction directory, breaking the documented guarantee that "Link and SymbolicLink entries are not allowed to target locations outside of the extraction folder". This allows arbitrary file read / extraction-containment escape (CWE-22 / CWE-59). Confirmed end-to-end on tar@7.5.22 with default tar.x() (async and sync), including reading /etc/passwd. It is distinct from, and survives, the drive-relative fixes (GHSA-9ppj-qmqm-q256 / CVE-2026-31802, GHSA-qffp-2rhf-9h96).

Details

Root cause is a separator-handling difference between the containment CHECK and the symlink CREATE.

In Unpack[STRIPABSOLUTEPATH] (src/unpack.ts), the symlink linkpath is split for the ".." containment check AFTER stripped.replaceAll(/\/g, '/') — i.e. "\" is treated as a path separator when counting segments.

But on non-Windows, normalizeWindowsPath (src/normalize-windows-path.ts) is the identity function, and the symlink is created with the RAW linkpath: SYMLINK -> LINK calls fs.symlink(entry.linkpath, entry.absolute) (src/unpack.ts, ~lines 640-660 and 866-881), where "\" is an ordinary filename character.

So a segment like "A\B" counts as TWO segments to the check but ONE to the kernel. Backslash padding inflates the check's segment count, so a ".." run that the check believes stays inside cwd actually escapes it at creation/resolution time.

Walkthrough for entry.linkpath = "A\B/../../x": - CHECK ("\" -> "/"): ["A","B","..","..","x"] -> normalizes to "x" -> believed inside cwd -> ALLOWED - CREATE (Linux, "\" literal): ["A\B","..","..","x"] -> from cwd: cwd/A\B -> .. -> cwd -> .. -> parent of cwd -> ESCAPES

The escape depth equals the number of backslashes in the padding segment (overshooting saturates at "/"), so any path on the same filesystem is reachable regardless of cwd depth.

Why the other guards do not catch it: ENSURE_NO_SYMLINK (src/unpack.ts, ~lines 679-698) only rejects EXISTING symlinks found in the target path, not cwd-escape; and CHECKPATH's defense-in-depth validates entry.path (the entry's own path), not the linkpath.

Scope note (per README "Security Information"): this breaks the stated protection "Link and SymbolicLink entries are not allowed to target locations outside of the extraction folder", so it is reportable under "not properly enforcing the intended security protections". It is NOT the out-of-scope case in warning #1 (extracting into an attacker-controlled folder / TOCTOU symlink-swap): this is deterministic, driven solely by the archive's own contents, into a normal folder, with no race and no second actor. It is the same class as the accepted/fixed GHSA-9ppj-qmqm-q256, via a different mechanism (backslash separator differential vs. drive-relative prefix).

Suggested fix: make the containment check use the same separator semantics as creation — when platform !== 'win32', do NOT treat "\" as a separator (skip the replaceAll(/\/g,'/')) so segment counting matches the kernel. Better still, decide containment from the single resolved absolute target that creation actually uses — require path.resolve(path.dirname(entry.absolute), entry.linkpath) to be within cwd — instead of a separate path.posix lexical model that can diverge from it.

Proof of concept

Non-Windows host (Linux/macOS), default options. Benign: reads a marker file placed in the PARENT of the extraction dir.

Steps: npm i tar@7.5.22 tar-stream node poc.js

poc.js:

const tar = require('tar'), { pack } = require('tar-stream');
const fs = require('fs'), path = require('path'), os = require('os');
const base = fs.mkdtempSync(path.join(os.tmpdir(), 'poc-'));
const cwd = path.join(base, 'extract'); fs.mkdirSync(cwd);
fs.writeFileSync(path.join(base, 'SENTINEL.txt'), 'OUT-OF-TREE'); // in the PARENT of cwd
const p = pack();
p.entry({ name: 'A\\B', type: 'directory', mode: 0o755 });        // one on-disk segment "A\B"
p.entry({ name: 'escape', type: 'symlink', linkname: 'A\\B/../../SENTINEL.txt', mode: 0o777 });
p.finalize();
const chunks = []; p.on('data', c => chunks.push(c)); p.on('end', async () => {
  const tf = path.join(base, 'e.tar'); fs.writeFileSync(tf, Buffer.concat(chunks));
  await tar.x({ file: tf, cwd });                                  // DEFAULT options
  console.log('realpath:', fs.realpathSync(path.join(cwd, 'escape')));
  console.log('read    :', fs.readFileSync(path.join(cwd, 'escape'), 'utf8'));
});

Expected output: cwd/escape resolves to /SENTINEL.txt (the PARENT of the extraction directory) and reads "OUT-OF-TREE".

To show arbitrary read of a real file: use a padding segment of ~50 backslashes plus the matching number of ".." and then "/etc/passwd" as the linkname (and a directory entry named the same padding segment). The resulting symlink resolves to /etc/passwd (verified: first line "root:x:0:0:root:/root:/bin/bash").

Impact

Arbitrary file read / extraction-containment escape (CWE-22 / CWE-59). A malicious tarball (for example an npm package, or any user-uploaded or third-party archive) extracted with default options plants a symlink that resolves to an arbitrary host path on the same filesystem. Any consumer that then reads, copies, or serves files from the "contained" extraction directory is induced to read arbitrary host files. node-tar is a dependency of npm itself and of a large fraction of the ecosystem, so the exposure is broad.

Arbitrary WRITE is NOT achieved: mkdir rejects symlinked parent components (SymlinkError, src/mkdir.ts), a file written at the symlink's own path unlinks the symlink first, and hardlink entries reject any "..". So node-tar does not itself write outside the extraction target; the impact is the escaping symlink / arbitrary read.

Show details on source website

{
  "affected": [
    {
      "package": {
        "ecosystem": "npm",
        "name": "tar"
      },
      "ranges": [
        {
          "events": [
            {
              "introduced": "0"
            },
            {
              "fixed": "8.0.0"
            }
          ],
          "type": "ECOSYSTEM"
        }
      ]
    }
  ],
  "aliases": [
    "CVE-2026-140246"
  ],
  "database_specific": {
    "cwe_ids": [
      "CWE-22",
      "CWE-59"
    ],
    "github_reviewed": true,
    "github_reviewed_at": "2026-12-02T01:09:07Z",
    "nvd_published_at": "2026-12-01T18:17:28Z",
    "severity": "HIGH"
  },
  "details": "### Summary\n\nOn a non-Windows host, extracting a crafted tar with default options makes node-tar (\u003c= 7.5.22, current latest) create a SymbolicLink whose target resolves OUTSIDE the extraction directory, breaking the documented guarantee that \"Link and SymbolicLink entries are not allowed to target locations outside of the extraction folder\". This allows arbitrary file read / extraction-containment escape (CWE-22 / CWE-59). \nConfirmed end-to-end on tar@7.5.22 with default tar.x() (async and sync), including reading /etc/passwd. It is distinct from, and survives, the drive-relative fixes (GHSA-9ppj-qmqm-q256 / CVE-2026-31802, GHSA-qffp-2rhf-9h96).\n\n### Details\n\nRoot cause is a separator-handling difference between the containment CHECK and the symlink CREATE.\n\nIn Unpack[STRIPABSOLUTEPATH] (src/unpack.ts), the symlink linkpath is split for the \"..\" containment check AFTER stripped.replaceAll(/\\\\/g, \u0027/\u0027) \u2014 i.e. \"\\\" is treated as a path separator when counting segments.\n\nBut on non-Windows, normalizeWindowsPath (src/normalize-windows-path.ts) is the identity function, and the symlink is created with the RAW linkpath: SYMLINK -\u003e LINK calls fs.symlink(entry.linkpath, entry.absolute) (src/unpack.ts, ~lines 640-660 and 866-881), where \"\\\" is an ordinary filename character.\n\nSo a segment like \"A\\B\" counts as TWO segments to the check but ONE to the kernel. Backslash padding inflates the check\u0027s segment count, so a \"..\" run that the check believes stays inside cwd actually escapes it at creation/resolution time.\n\nWalkthrough for entry.linkpath = \"A\\B/../../x\":\n- CHECK (\"\\\" -\u003e \"/\"): [\"A\",\"B\",\"..\",\"..\",\"x\"] -\u003e normalizes to \"x\" -\u003e believed inside cwd -\u003e ALLOWED\n- CREATE (Linux, \"\\\" literal): [\"A\\B\",\"..\",\"..\",\"x\"] -\u003e from cwd: cwd/A\\B -\u003e .. -\u003e cwd -\u003e .. -\u003e parent of cwd -\u003e ESCAPES\n\nThe escape depth equals the number of backslashes in the padding segment (overshooting saturates at \"/\"), so any path on the same filesystem is reachable regardless of cwd depth.\n\nWhy the other guards do not catch it: ENSURE_NO_SYMLINK (src/unpack.ts, ~lines 679-698) only rejects EXISTING symlinks found in the target path, not cwd-escape; and CHECKPATH\u0027s defense-in-depth validates entry.path (the entry\u0027s own path), not the linkpath.\n\nScope note (per README \"Security Information\"): this breaks the stated protection \"Link and SymbolicLink entries are not allowed to target locations outside of the extraction folder\", so it is reportable under \"not properly enforcing the intended security protections\". It is NOT the out-of-scope case in warning #1 (extracting into an attacker-controlled folder / TOCTOU symlink-swap): this is deterministic, driven solely by the archive\u0027s own contents, into a normal folder, with no race and no second actor. It is the same class as the accepted/fixed GHSA-9ppj-qmqm-q256, via a different mechanism (backslash separator differential vs. drive-relative prefix).\n\nSuggested fix: make the containment check use the same separator semantics as creation \u2014 when platform !== \u0027win32\u0027, do NOT treat \"\\\" as a separator (skip the replaceAll(/\\\\/g,\u0027/\u0027)) so segment counting matches the kernel. Better still, decide containment from the single resolved absolute target that creation actually uses \u2014 require path.resolve(path.dirname(entry.absolute), entry.linkpath) to be within cwd \u2014 instead of a separate path.posix lexical model that can diverge from it.\n\n### Proof of concept\n\nNon-Windows host (Linux/macOS), default options. Benign: reads a marker file placed in the PARENT of the extraction dir.\n\nSteps:\n  npm i tar@7.5.22 tar-stream\n  node poc.js\n\npoc.js:\n```js\nconst tar = require(\u0027tar\u0027), { pack } = require(\u0027tar-stream\u0027);\nconst fs = require(\u0027fs\u0027), path = require(\u0027path\u0027), os = require(\u0027os\u0027);\nconst base = fs.mkdtempSync(path.join(os.tmpdir(), \u0027poc-\u0027));\nconst cwd = path.join(base, \u0027extract\u0027); fs.mkdirSync(cwd);\nfs.writeFileSync(path.join(base, \u0027SENTINEL.txt\u0027), \u0027OUT-OF-TREE\u0027); // in the PARENT of cwd\nconst p = pack();\np.entry({ name: \u0027A\\\\B\u0027, type: \u0027directory\u0027, mode: 0o755 });        // one on-disk segment \"A\\B\"\np.entry({ name: \u0027escape\u0027, type: \u0027symlink\u0027, linkname: \u0027A\\\\B/../../SENTINEL.txt\u0027, mode: 0o777 });\np.finalize();\nconst chunks = []; p.on(\u0027data\u0027, c =\u003e chunks.push(c)); p.on(\u0027end\u0027, async () =\u003e {\n  const tf = path.join(base, \u0027e.tar\u0027); fs.writeFileSync(tf, Buffer.concat(chunks));\n  await tar.x({ file: tf, cwd });                                  // DEFAULT options\n  console.log(\u0027realpath:\u0027, fs.realpathSync(path.join(cwd, \u0027escape\u0027)));\n  console.log(\u0027read    :\u0027, fs.readFileSync(path.join(cwd, \u0027escape\u0027), \u0027utf8\u0027));\n});\n```\n\nExpected output: cwd/escape resolves to \u003cbase\u003e/SENTINEL.txt (the PARENT of the extraction directory) and reads \"OUT-OF-TREE\".\n\nTo show arbitrary read of a real file: use a padding segment of ~50 backslashes plus the matching number of \"..\" and then \"/etc/passwd\" as the linkname (and a directory entry named the same padding segment). The resulting symlink resolves to /etc/passwd (verified: first line \"root:x:0:0:root:/root:/bin/bash\").\n\n### Impact\n\nArbitrary file read / extraction-containment escape (CWE-22 / CWE-59). A malicious tarball (for example an npm package, or any user-uploaded or third-party archive) extracted with default options plants a symlink that resolves to an arbitrary host path on the same filesystem. Any consumer that then reads, copies, or serves files from the \"contained\" extraction directory is induced to read arbitrary host files. node-tar is a dependency of npm itself and of a large fraction of the ecosystem, so the exposure is broad.\n\nArbitrary WRITE is NOT achieved: mkdir rejects symlinked parent components (SymlinkError, src/mkdir.ts), a file written at the symlink\u0027s own path unlinks the symlink first, and hardlink entries reject any \"..\". So node-tar does not itself write outside the extraction target; the impact is the escaping symlink / arbitrary read.",
  "id": "GHSA-hqgx-p3r3-2cfg",
  "modified": "2026-12-02T01:09:07Z",
  "published": "2026-12-02T01:09:07Z",
  "references": [
    {
      "type": "WEB",
      "url": "https://github.com/isaacs/node-tar/security/advisories/GHSA-hqgx-p3r3-2cfg"
    },
    {
      "type": "ADVISORY",
      "url": "https://nvd.nist.gov/vuln/detail/CVE-2026-140246"
    },
    {
      "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: SymbolicLink extraction escapes the extraction directory on non-Windows hosts via a backslash separator differential"
}



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.