Dev.to Security ๐Ÿ” Cybersecurity ๐Ÿ‘ 0 ๐Ÿ“– 4 min read

CVE-2026-140244: CVE-2026-140244: Symlink Containment Bypass and Arbitrary File Read in node-tar

CVE-2026-140244: Symlink Containment Bypass and Arbitrary File Read in node-tar Vulnerability ID: CVE-2026-140244 CVSS Score: 7.2 Published: 2026-12-02 CVE-2026-140244 (GHSA-mhqm-9wj8-w7r4) is a symlink containment

CVE-2026-140244: Symlink Containment Bypass and Arbitrary File Read in node-tar

Vulnerability ID: CVE-2026-140244
CVSS Score: 7.2
Published: 2026-12-02

CVE-2026-140244 (GHSA-mhqm-9wj8-w7r4) is a symlink containment bypass vulnerability in node-tar prior to version 8.0.0. Because the archive unpacker validates symbolic link targets using purely lexical path normalization without accounting for intermediate archive-created symlinks, an attacker can craft a tar archive containing chained symlinks that resolve outside the extraction directory on the physical filesystem. Downstream applications that read, copy, serve, or re-archive the extracted directory tree follow these planted symlinks, resulting in arbitrary file read and information disclosure.

TL;DR

Versions of node-tar prior to 8.0.0 rely on lexical path normalization (path.posix.normalize) to check if symlink targets remain within the extraction root. An attacker can bypass this check by chaining an initial in-scope symlink (e.g., s1 -> .) with a second symlink traversing through it (e.g., s2 -> s1/../secret.txt). While lexical normalization cancels 's1/..', the OS kernel dereferences 's1' before applying '..', allowing the planted symlink to point outside the extraction root and exposing sensitive files to downstream consumers.

โš ๏ธ Exploit Status: POC

Technical Details

  • CVE / Advisory ID: CVE-2026-140244 / GHSA-mhqm-9wj8-w7r4
  • Affected Component: node-tar (npm: tar) < 8.0.0 (src/unpack.ts [STRIPABSOLUTEPATH])
  • Weakness Class: CWE-59 (Improper Link Resolution) / CWE-22 (Path Traversal)
  • CVSS Score: 7.2 High (CVSS v4.0) / 5.9 Medium (CVSS v3.1)
  • Attack Vector: Network (Crafted .tar archive with chained symlinks or '/.' entry paths)
  • Security Impact: Symlink Sandbox Escape leading to Arbitrary File Read via downstream consumers
  • Exploit & KEV Status: Public PoC Available / Not in CISA KEV
  • Patched Version: tar v8.0.0 (Commit 23b368128b6cf7d4c26f2e302c0e4a82f70a6e3d)

Affected Systems

  • node-tar (npm package: tar) < 8.0.0
  • Node.js applications, CI/CD pipelines, and package installers extracting untrusted tar archives via node-tar < 8.0.0
  • tar (node-tar): < 8.0.0 (Fixed in: 8.0.0)

Code Analysis

Commit: 23b3681

Reject linkpaths containing '..' after a named path segment and normalize entry.path before computing dirname in unpack.ts.

--- a/src/unpack.ts
+++ b/src/unpack.ts
@@ -279,7 +279,23 @@ export class Unpack extends Parser {
       // Resolve linkpath relative to the entry's directory.
       // `path.posix` is safe to use because we're operating on
       // tar paths, not a filesystem.
-      const entryDir = path.posix.dirname(entry.path)
+      // A '..' is only safe at the start of the target. Any named
+      // part before it can be a symlink, and then the '..' goes to
+      // the parent of that symlink's target.
+      const firstName = parts.findIndex(
+        part => part !== '..' && part !== '.' && part !== '',
+      )
+      if (firstName !== -1 && parts.includes('..', firstName)) {
+        this.warn(
+          'TAR_ENTRY_ERROR',
+          `${field} contains '..' after a path portion`,
+          { entry, [field]: p },
+        )
+        return false
+      }
+      // Normalize the path, so that the directory is the one where
+      // the link is created. The path 'x/.' creates the link 'x'.
+      const entryDir = path.posix.dirname(path.posix.normalize(entry.path))
       const resolved = path.posix.normalize(
         path.posix.join(entryDir, parts.join('/')),
       )

Exploit Details

  • GitHub Security Advisory: Official GitHub Security Advisory containing reproduction script and technical explanation of the nested symlink containment bypass.
  • GitHub Commit Test Suite: Official fix commit including test/symlink-linkpath-escape.test.ts with 7 distinct symlink escape payloads.

Mitigation Strategies

  • Upgrade the 'tar' npm dependency to version 8.0.0 or later to enforce strict symlink component ordering and entry.path normalization.
  • Implement a custom 'filter' callback in tar.x() / tar.extract() to disallow SymbolicLink entries or reject any linkpath containing '..' after a named segment.
  • Perform a post-extraction filesystem traversal using fs.realpathSync() on all extracted symbolic links to confirm their canonical targets reside within the extraction root before allowing downstream processing.
  • Execute archive extraction of untrusted inputs inside isolated, ephemeral sandboxes or rootless containers without access to sensitive host filesystem paths.

Remediation Steps:

  1. Audit project dependency trees using 'npm ls tar' to identify direct and transitive usages of node-tar < 8.0.0.
  2. Verify the runtime environment runs Node.js >= 22, which is required by [email protected].
  3. Update package.json to require 'tar': '^8.0.0' and migrate stream/sync calls to the v8 Promise and 'tar/node' APIs.
  4. If locked to Node.js < 22, configure the 'filter' option in all tar.x() / tar.extract() calls to block SymbolicLink entries or reject linkpaths where '..' follows a named component, and normalize entry.path prior to checking containment.

References

Read the full report for CVE-2026-140244 on our website for more details including interactive diagrams and full exploit analysis.

๐Ÿ“ฐ Read the original article on Dev.to Security

Originally published by Dev.to Security. Aggregated on AIWithGhost for educational purposes โ€” full credit and traffic to the original publisher.