Summary
A path traversal and symlink-handling flaw in extract-zip can allow archive contents to escape the intended extraction directory. When an archive places a symlink outside the destination before a regular file with the same name, extraction may write through the symlink and modify an arbitrary file.
Affected context
The issue occurs in applications that use extract-zip to unpack archives and rely on its containment checks to keep extracted files within a destination directory. Risk increases when an attacker can provide or influence an archive containing duplicate entry names, including a symlink followed by a regular file, and when the extraction process has permissions to write outside the intended directory through filesystem links.
Exploit preconditions
- Attack surface: Archive extraction performed through extract-zip
- Required access: Ability to supply, replace, or influence an archive being extracted
- Trigger point: Processing archive entries, particularly a symlink followed by a regular file with the same name
- Filesystem condition: The extraction process can create or follow symlinks and has write access to the targeted location
- Why exploitation is possible: The containment check evaluates only the parent directory and does not sufficiently validate the entry's final path component
Why this happens
The underlying flaw is incomplete path containment validation combined with unsafe symlink handling. The extractor checks whether an entry's parent directory remains within the destination, but does not fully validate the resolved final path before writing. A previously created symlink can therefore redirect a later file write outside the extraction root. This maps primarily to CWE-22: Improper Limitation of a Pathname to a Restricted Directory, with CWE-59: Improper Link Resolution Before File Access describing the unsafe filesystem-link behavior.
Potential impact
- An attacker may overwrite or create files outside the intended extraction directory
- Application configuration, scripts, or other sensitive files could be modified
- The affected process may experience code execution if a writable target is later executed or loaded
- Data integrity, service availability, or system isolation could be compromised
General mitigation guidance
Mitigation generally focuses on treating archive contents as untrusted filesystem operations rather than ordinary file copies.
Common defensive patterns include:
- Resolve and validate the complete destination path, including the final component, before writing
- Reject symlink and hard-link entries unless there is a well-defined, safe requirement for them
- Prevent writes through links by using link-safe filesystem operations and appropriate no-follow controls
- Extract into an isolated, least-privileged workspace with narrowly scoped permissions
- Apply resource limits and restrict archive entry types, duplicate names, and unusual paths
- Avoid allowing extracted content to overwrite existing application or system files
How teams detect issues like this
Organizations commonly identify this class of issue through:
- Static analysis and code review checks for archive extraction without complete canonical-path validation
- Review signals involving symlink creation, duplicate archive entries, path normalization, and filesystem writes
- Dynamic tests using traversal paths, symlink entries, hard links, duplicate names, and destination-boundary assertions
- Security policies requiring extraction into isolated directories with no-follow or link-restriction controls
- Dependency and software composition analysis for archive libraries with known path or link-resolution weaknesses

