Summary
The Node.js decompress package contains multiple extraction flaws that allow archives to create or access files and links outside the intended target directory.
Crafted archives can traverse paths, abuse symlinks and hardlinks, and retain unsafe permission bits, enabling attackers to read, overwrite, or plant privileged files wherever the extracting process can reach.
Affected context
This vulnerability appears in applications that rely on the decompress package to unpack user-supplied or otherwise untrusted archives to a local directory.
It becomes relevant whenever archive contents are assumed to be safely confined to a target path, yet the application does not implement additional filesystem safety checks beyond what decompress provides.
Systems that run the extraction process with elevated privileges, broad filesystem access, or sensitive configuration directories nearby are more exposed to impact.
Exploit preconditions
- Attack surface: Any feature or service that uses
decompressto extract archives, especially uploads, imports, backups, or plug‑in bundles. - Required access: Ability to supply or influence the archive being extracted (e.g., authenticated upload, API call, or intercepted download).
- Trigger point: Invocation of
decompressto unpack the crafted archive into a chosen target directory. - Why exploitation is possible:
- Path containment relies on a naive string prefix comparison that can be bypassed with traversal sequences or crafted names.
- Symlink and hardlink entries are created without validating that link targets remain inside the intended directory.
- File mode handling does not strip setuid, setgid, or sticky bits, allowing archives to install files with potentially dangerous permissions.
Why this happens
The core issue is improper validation and normalization of file paths and link targets during archive extraction, combined with insufficient permission sanitization.
Instead of resolving and checking canonical paths, the code uses simple string prefix checks to enforce containment, which is fragile and easily bypassed with ../ sequences or edge cases in path encoding (CWE-22: Improper Limitation of a Pathname to a Restricted Directory).
Additionally, link entries (symlinks and hardlinks) are created without validating that their resolved targets stay within the extraction root, enabling link‑based redirection to arbitrary filesystem locations (CWE-59: Improper Link Resolution Before File Access).
Finally, extracted file modes preserve setuid, setgid, or sticky bits from the archive, contrary to secure defaults, which can allow privilege abuse when those files are placed in sensitive directories (CWE-732: Incorrect Permission Assignment for Critical Resource).
Potential impact
- An attacker may write arbitrary files outside the intended extraction directory, including application configuration or system files reachable by the process.
- An attacker may read sensitive files by creating links that point to protected paths and then causing the application to process or expose their contents.
- An attacker could plant or replace executable files or scripts with malicious versions in locations used by the application.
- An attacker may create files with setuid or setgid bits that can lead to elevated privileges when executed in permissive environments.
- Archive extraction can be used as a stepping stone to persistent compromise, configuration tampering, or data exfiltration.
General mitigation guidance
Mitigation typically focuses on enforcing strict filesystem containment and reducing trust in archive metadata.
Recommended defensive patterns include:
- Canonicalize and resolve extraction paths before writing, ensuring all outputs remain under an expected root using robust path normalization and checks against the real filesystem (e.g., comparing resolved absolute paths to the allowed base directory).
- Reject or safely handle symlink and hardlink entries from untrusted archives; for many applications, the safest pattern is to ignore link entries entirely or only allow them when their targets are verifiably under the same root.
- Sanitize file permissions on extracted content by stripping setuid, setgid, and sticky bits and applying conservative, application-defined default modes.
- Run extraction logic with least privilege, limiting filesystem access to a dedicated working directory and avoiding execution under accounts that have broad system write permission.
- Treat archive content as untrusted input, applying validation rules on file names, allowed extensions, and directory structure rather than trusting the archive's layout.
How teams detect issues like this
Detection can leverage both code-focused and operational controls:
- Static analysis and manual code review can flag uses of archive-extraction utilities that do not enforce canonical path checks, ignore symlink and hardlink validation, or fail to sanitize permissions.
- Review patterns where user-supplied archives are unpacked directly into application or system directories, or where extraction occurs with elevated privileges.
- Implement policy checks or CI guards to require safe extraction helpers (e.g., utilities that reject links and enforce directory confinement) and to prohibit direct writes to sensitive locations during decompression.
- Runtime monitoring can watch for unexpected file creation or modification outside designated working directories immediately following archive extraction operations.
- Automated security tools that specialize in dependency behavior or configuration scanning can help identify libraries with unsafe extraction semantics and highlight misuse patterns.

