Summary
A path traversal vulnerability in rubyzip allows crafted archive entries to escape the intended extraction directory and write files into nearby filesystem locations.
The issue becomes risky when an application extracts attacker-controlled ZIP archives and relies on an incomplete destination-prefix check.
Affected context
The vulnerability occurs in rubyzip extraction workflows that use Zip::Entry#extract and process archive entry names without fully validating their canonical destination paths. It may affect applications that extract archives supplied by untrusted users or external services, particularly when the extraction directory has writable sibling paths sharing the same textual prefix.
Exploit preconditions
- Attack surface: ZIP archive extraction through
Zip::Entry#extract - Required access: Ability to provide or influence an archive processed by the application
- Trigger point: Extraction of an archive entry containing traversal-oriented path components
- Why exploitation is possible: Destination validation relies on prefix comparison without requiring a trailing path separator, allowing paths outside the intended directory to appear valid when they share its textual prefix
Why this happens
The underlying bug is insufficient canonical path validation, mapping to CWE-22: Improper Limitation of a Pathname to a Restricted Directory.
A simple string-prefix comparison does not establish that a resolved target remains within the intended extraction directory. Without canonicalization and boundary-aware comparison, an entry can reference a sibling location whose name begins with the destination directory's prefix.
Potential impact
- An attacker may write or overwrite files outside the intended extraction directory
- Application configuration or executable files could be modified
- Extracted content could be placed in sibling upload or backup directories
- The application or other users may consume attacker-controlled files
- Local privilege escalation or broader compromise could occur if sensitive writable paths are affected
General mitigation guidance
Mitigation generally focuses on enforcing a real filesystem containment boundary during archive extraction.
Common defensive patterns include:
- Canonicalizing the extraction root and candidate destination before comparison
- Requiring a path-separator boundary rather than accepting a textual prefix match
- Rejecting absolute paths, traversal components, and entries that resolve outside the extraction root
- Using extraction APIs or libraries that provide safe path handling by default
- Extracting into isolated, least-privileged directories with minimal write permissions
- Applying resource limits and treating archive contents as untrusted input
- Avoiding execution or automatic processing of newly extracted files
How teams detect issues like this
Organizations can detect this class of issue through:
- Static analysis rules identifying prefix-only path containment checks
- Code review searches for archive extraction without canonicalization or separator-aware validation
- Tests using traversal components, absolute paths, encoded separators, and sibling directories with shared prefixes
- Runtime monitoring for file creation outside approved extraction roots
- Policy enforcement requiring approved safe-extraction helpers for archive handling
Automated security review tools may help identify unsafe path construction and archive-processing patterns, but focused behavioral tests remain important.

