Summary
node-tar, a TAR processing library for Node.js, contains a vulnerability where hardlink path validation uses different path resolution semantics than the logic that actually creates the hardlink.
An attacker can craft a malicious TAR archive that bypasses the intended path traversal protections and creates hardlinks to arbitrary files outside the extraction directory, potentially exposing or modifying sensitive files on the host system.
Affected context
This vulnerability affects applications that:
- Use node-tar in versions prior to 7.5.7
- Allow processing of TAR archives from untrusted or semi-trusted sources
- Extract archives onto a filesystem where sensitive files are reachable via the node-tar process' privileges
The issue is specifically triggered when archives contain hardlink entries whose paths are validated differently from the paths ultimately used during hardlink creation, enabling traversal outside the designated extraction directory under certain path layouts.
Exploit preconditions
- Attack surface: Any service, CLI tool, or background job that accepts TAR input and extracts it using vulnerable versions of node-tar.
- Required access: Ability to supply or influence the TAR archive being processed (e.g., file upload, package ingestion, CI artifacts, backup/restore flows).
- Trigger point: Extraction of a crafted TAR containing hardlink entries with paths designed to bypass validation.
- Why exploitation is possible: The security check and the actual hardlink creation routine rely on different path resolution semantics. A path that appears safe to the validator can resolve to a different, potentially external, location when the hardlink is created, enabling path traversal via hardlinks.
Why this happens
The core issue stems from inconsistent path normalization and resolution between the security check and the hardlink creation logic.
While node-tar attempts to prevent path traversal by validating hardlink targets, it uses a different interpretation of paths than the code that ultimately creates the hardlinks.
This divergence leads to a classic CWE-22: Improper Limitation of a Pathname to a Restricted Directory scenario, combined with CWE-59: Improper Link Resolution Before File Access ('Link Following'), where link-based file operations are not subject to the same constraints as the validation step.
Abstractly, the pattern is: validate a path (or link target) using one normalization/semantics, then perform file system operations with another, leaving a gap that attacker-controlled paths can exploit.
Potential impact
- Creation of hardlinks pointing to files outside the intended extraction directory
- Indirect read access to sensitive files via hardlinks exposed in application-controlled directories
- Facilitation of data modification or corruption when linked files are writable by the process
- Escalation of impact in combination with other vulnerabilities (e.g., if subsequent code operates on all extracted files with elevated trust)
- Potential interference with security or configuration files depending on deployment layout and permissions
General mitigation guidance
Effective mitigation focuses on aligning validation with actual filesystem behavior and tightening trust boundaries around archive extraction:
- Ensure that any path validation uses the same canonicalization and resolution logic as the final filesystem operation, including handling of
.., symlinks, hardlinks, and platform-specific path rules. - Treat all paths within archives as untrusted; enforce a strict policy that all resolved paths must remain under a designated extraction root after full resolution.
- Consider disabling or rejecting hardlink (and optionally symlink) entries from untrusted archives, or only allowing them when they resolve to already-validated locations within the extraction directory.
- Run archive extraction with least-privilege accounts that have limited access to sensitive directories and files, reducing blast radius if traversal occurs.
- Isolate extraction into dedicated, minimal, and disposable directories, and avoid extracting directly into locations that contain application binaries, configuration, or secrets.
How teams detect issues like this
Detection typically combines code-level review with behavioral monitoring:
- Static analysis / code review: Look for uses of node-tar where:
- Archive contents originate from user-controlled or external sources.
- Hardlink and symlink entries are not explicitly restricted, filtered, or normalized.
- Custom validation or path-joining logic exists and may differ from the underlying filesystem operations.
- Security testing: Perform archive extraction tests with malicious TAR files containing:
- Hardlink paths using
../sequences or mixed absolute/relative references. - Platform-specific path constructs intended to escape the extraction directory.
- Runtime monitoring: Use audit logs or filesystem monitoring to detect creation of links or files outside the expected extraction root during archive processing.
- Automated SAST or dependency review tools can be configured to flag the use of vulnerable archive libraries and highlight untrusted archive extraction flows.

