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

CVE-2026-140248: CVE-2026-140248: Symlink Target Path Traversal and Arbitrary File Access in node-tar

CVE-2026-140248: Symlink Target Path Traversal and Arbitrary File Access in node-tar Vulnerability ID: CVE-2026-140248 CVSS Score: 7.2 Published: 2026-12-02 CVE-2026-140248 is a High-severity path traversal and symb

CVE-2026-140248: Symlink Target Path Traversal and Arbitrary File Access in node-tar

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

CVE-2026-140248 is a High-severity path traversal and symbolic link resolution vulnerability (CWE-59) in the npm package tar (node-tar) affecting versions 7.5.22 through 7.5.24. When extracting archives under default security configurations (preservePaths: false), node-tar validates symbolic link targets using purely lexical path normalization via path.posix functions without accounting for intermediate symbolic link resolution on the host filesystem. By crafting an archive containing chained symbolic links, paths ending in trailing '/.' segments, or POSIX directory names containing backslashes, an attacker can plant a symbolic link inside the extraction directory that resolves to arbitrary locations outside the destination root. Downstream processes reading or writing through the extracted symlink can consequently disclose or overwrite arbitrary files on the host system.

TL;DR

A lexical path validation flaw in node-tar versions 7.5.22 to 7.5.24 allows crafted tar archives to bypass symlink extraction restrictions and create symbolic links pointing outside the target extraction directory.

⚠️ Exploit Status: POC

Technical Details

  • CVE / Advisory ID: CVE-2026-140248 / GHSA-6wwr-g865-f46r
  • Weakness Class: CWE-59: Improper Link Resolution Before File Access ('Link Following')
  • CVSS v4.0 Score: 7.2 High (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: tar (node-tar) on npm (>= 7.5.22, < 8.0.0)
  • Patched Version: 8.0.0 (Commit 23b368128b6cf7d4c26f2e302c0e4a82f70a6e3d)
  • Attack Vector: Network / Crafted Tar Archive Extraction with Chained or Unnormalized Symlinks
  • Primary Impact: Symlink Escape from Extraction Root Leading to Arbitrary File Overwrite or Read
  • CISA KEV Status: Not Listed

Affected Systems

  • node-tar (npm package 'tar') >= 7.5.22, < 8.0.0 (versions 7.5.22, 7.5.23, 7.5.24)
  • tar (node-tar): >= 7.5.22, < 8.0.0 (Fixed in: 8.0.0)

Code Analysis

Commit: 23b3681

Reject symlink targets containing '..' after a path portion and normalize entry.path before computing entryDir.

diff --git a/src/unpack.ts b/src/unpack.ts
index e5a3fc5..5fc7cb5 100644
--- 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: Official security commit containing regression test cases (test/symlink-linkpath-escape.test.ts) demonstrating 7 symlink escape payloads.

Mitigation Strategies

  • Upgrade node-tar (npm package 'tar') to version 8.0.0 or later to enforce strict symbolic link target validation.
  • Implement a custom extraction filter callback (filter option in tar.x / tar.extract) to block SymbolicLink and Link entries when extracting untrusted archives.
  • Backport the v8.0.0 linkpath validation logic into a custom extraction filter if running on Node.js versions prior to v22 where tar v8.0.0 is unsupported.
  • Verify canonical filesystem paths using fs.realpath() or fs.realpathSync() before reading or writing files inside an extracted archive directory.

Remediation Steps:

  1. Audit project dependencies and lockfiles (package-lock.json, yarn.lock, pnpm-lock.yaml) using 'npm ls tar' to identify any direct or transitive usage of tar versions 7.5.22, 7.5.23, or 7.5.24.
  2. Upgrade the tar package to version 8.0.0 or higher via 'npm install tar@^8.0.0' and update application code to accommodate v8.0.0 API changes (Node.js >= 22 requirement and Promise/ReadableStream APIs).
  3. If upgrading to 8.0.0 is blocked by Node.js runtime constraints, add a filter function to all tar.x / tar.extract invocations that normalizes entry.path with path.posix.normalize() and rejects any SymbolicLink entry where linkpath contains '..' after a named path segment.
  4. Configure extraction options with 'preservePaths: false' (the default) and 'strict: true' so that any TAR_ENTRY_ERROR warnings abort the extraction operation immediately.

References

Read the full report for CVE-2026-140248 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.