CVE-2026-140246: node-tar SymbolicLink Extraction Escapes The Extraction Vulnerability

HIGH
Advisory Identifier: GHSA-hqgx-p3r3-2cfg
CWE-59 CWE-22
Published
Advisory Summary

CVE-2026-140246 is a HIGH symboliclink extraction 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 symboliclink extraction escapes the extraction directory on non-windows hosts via a backslash separator differential. Remediation is available by upgrading affected packages to version 8.0.0.

CVE-2026-140246 at a Glance

CVE Identifier CVE-2026-140246
GHSA Identifier GHSA-hqgx-p3r3-2cfg
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-140246

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-140246, 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 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: ```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 <base>/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.

CVE-2026-140246 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-140246?
CVE-2026-140246 is a security vulnerability in node-tar involving SymbolicLink extraction escapes the extraction directory on non-Windows hosts via a backslash separator differential 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-140246?
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-140246?
CVE-2026-140246 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-140246?
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-hqgx-p3r3-2cfg",
  "modified" : "2026-12-02T01:09:07Z",
  "published" : "2026-12-02T01:09:07Z",
  "aliases" : [ "CVE-2026-140246" ],
  "summary" : "node-tar: SymbolicLink extraction escapes the extraction directory on non-Windows hosts via a backslash separator differential",
  "details" : "### Summary\n\nOn 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). \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, '/') — 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 -> 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's 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 (\"\\\" -> \"/\"): [\"A\",\"B\",\"..\",\"..\",\"x\"] -> normalizes to \"x\" -> believed inside cwd -> ALLOWED\n- CREATE (Linux, \"\\\" literal): [\"A\\B\",\"..\",\"..\",\"x\"] -> from cwd: cwd/A\\B -> .. -> cwd -> .. -> parent of cwd -> 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's defense-in-depth validates entry.path (the entry's 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'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).\n\nSuggested 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.\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('tar'), { pack } = require('tar-stream');\nconst fs = require('fs'), path = require('path'), os = require('os');\nconst base = fs.mkdtempSync(path.join(os.tmpdir(), 'poc-'));\nconst cwd = path.join(base, 'extract'); fs.mkdirSync(cwd);\nfs.writeFileSync(path.join(base, 'SENTINEL.txt'), 'OUT-OF-TREE'); // in the PARENT of cwd\nconst p = pack();\np.entry({ name: 'A\\\\B', type: 'directory', mode: 0o755 });        // one on-disk segment \"A\\B\"\np.entry({ name: 'escape', type: 'symlink', linkname: 'A\\\\B/../../SENTINEL.txt', mode: 0o777 });\np.finalize();\nconst chunks = []; p.on('data', c => chunks.push(c)); p.on('end', async () => {\n  const tf = path.join(base, 'e.tar'); fs.writeFileSync(tf, Buffer.concat(chunks));\n  await tar.x({ file: tf, cwd });                                  // DEFAULT options\n  console.log('realpath:', fs.realpathSync(path.join(cwd, 'escape')));\n  console.log('read    :', fs.readFileSync(path.join(cwd, 'escape'), 'utf8'));\n});\n```\n\nExpected output: cwd/escape resolves to <base>/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'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.",
  "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-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"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-22", "CWE-59" ],
    "severity" : "HIGH",
    "github_reviewed" : true,
    "github_reviewed_at" : "2026-12-02T01:09:07Z",
    "nvd_published_at" : "2026-12-01T18:17:28Z"
  }
}