Summary
node-tar versions 7.5.7 and below allow attacker-controlled tar archives to create hardlinks that point to files outside the intended extraction directory.
When extracted with default options, this can bypass path protections and give an attacker arbitrary file read and write capabilities as the extracting user.
Affected context
This vulnerability affects applications and tools that:
- Use node-tar (≤ 7.5.7) to extract untrusted or semi-trusted tar archives
- Rely on node-tar's default extraction options for safety
- Run the extraction as a user account with access to sensitive files on the same filesystem
The problem manifests when an archive contains hardlink entries that, once materialized in the extraction directory, reference files located outside the extraction root. Environments that process archives from external users, CI/CD pipelines, package managers, or automated importers are particularly exposed.
Exploit preconditions
- Attack surface: Any service, CLI, or background job that extracts attacker-supplied tar archives using node-tar with default options.
- Required access: Ability to provide or influence the tar file being extracted (e.g., file upload, package submission, repository contribution).
- Trigger point: Invoking node-tar extraction on the crafted archive without additional path or link sanitization.
- Why exploitation is possible: node-tar's default handling of hardlink entries allows creation of links inside the extraction directory that resolve to files outside the extraction root, effectively bypassing path normalization and traversal defenses.
Why this happens
The core issue is insufficient validation of file targets when processing hardlink entries during tar extraction.
While typical path traversal protections focus on relative paths (e.g., ../ segments), hardlinks can reference files elsewhere on the filesystem via inodes, not just string paths. In vulnerable versions, node-tar allows a hardlink to be created in the extraction tree that points to a target outside the intended root, thereby violating directory confinement assumptions.
This maps to CWE-22: Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal') because the library fails to effectively constrain filesystem operations to the extraction root when interpreting archive metadata.
Potential impact
- An attacker may read sensitive files accessible to the extracting user (configuration files, API keys, SSH keys, environment files).
- An attacker may overwrite or corrupt files outside the extraction directory, potentially altering application behavior or configurations.
- An attacker could plant or modify scripts and binaries that the system later executes, enabling privilege escalation or code execution in follow-up steps.
- An attacker can use archive extraction as a generalized filesystem access primitive within the permissions of the extracting process.
General mitigation guidance
Mitigation focuses on strictly constraining where archive contents can land and how link entries are handled:
- Treat all archives from external sources as untrusted and avoid relying solely on default extraction behaviors for safety.
- Enforce a strict extraction root policy that rejects or neutralizes files and links resolving outside the designated directory, including hardlinks and symlinks.
- Consider disabling the creation of hardlinks and symbolic links during extraction, or mapping them to regular files where appropriate.
- Run extraction under a least-privilege account with minimal access to sensitive parts of the filesystem, isolating temporary extraction locations from critical data.
- Introduce additional validation layers around archive processing (e.g., pre-scan entries, apply allowlists for paths and file types) rather than trusting library defaults.
How teams detect issues like this
Effective detection combines code-level inspection with operational monitoring:
- Static analysis / code review:
- Identify uses of node-tar that extract archives originating from user input or external sources.
- Look for extraction calls that rely on defaults without explicit options for link handling, path normalization, or root confinement.
- Flag patterns where extraction paths are assumed to be safe solely because a library is "tar-aware," without additional checks.
- Security testing:
- Incorporate crafted archives with hardlink and symlink entries into test suites and CI pipelines to validate extraction behavior.
- Perform fuzzing or property-based testing around archive extraction to reveal unexpected file placement.
- Runtime and policy enforcement:
- Use filesystem monitoring (e.g., audit logs, container security tools) to detect archive extraction processes writing or linking files outside their designated directories.
- Apply sandboxing or containerization policies that restrict filesystem access for archive-handling components, and alert on violations.

