Skip to content

Conversation

th555555
Copy link

This commit fixes a critical Zip Slip vulnerability in the unzip() method that could allow malicious zip files to write files outside the intended extraction directory, potentially overwriting critical system files.

Vulnerability Details

The previous implementation directly used zip entry names without validation, allowing malicious zip files with entries like '../../../etc/passwd' or '........\windows\system32\config\sam' to escape the extraction directory and overwrite system files.

Security Improvements

  • Directory Traversal Prevention: Added checks for '..' patterns and absolute paths
  • Canonical Path Validation: Ensures extracted files stay within destination directory
  • Attack Detection: Throws clear error messages when malicious entries are detected
  • Defense in Depth: Multiple validation layers to prevent bypass attempts

Technical Changes

  • Added canonical path validation for destination directory
  • Implemented path traversal detection for zip entry names
  • Added canonical path verification for resolved file paths
  • Enhanced error handling with descriptive security exceptions
  • Fixed missing ZipFile instantiation and duplicate mkdir() call

Impact

  • Security: Eliminates Zip Slip vulnerability (CWE-22: Path Traversal)
  • Compatibility: Maintains existing functionality for legitimate zip files
  • Error Handling: Provides clear feedback when malicious content is detected

Fixes: CWE-22 (Path Traversal), CVE-2018-1002207 pattern
Priority: High - Critical security vulnerability

References:
JATOS/JATOS@2b42519
https://cwe.mitre.org/data/definitions/22.html

This commit fixes a critical Zip Slip vulnerability in the unzip() method that could allow malicious zip files to write files outside the intended extraction directory, potentially overwriting critical system files.

## Vulnerability Details
The previous implementation directly used zip entry names without validation, allowing malicious zip files with entries like '../../../etc/passwd' or '..\..\..\..\windows\system32\config\sam' to escape the extraction directory and overwrite system files.

## Security Improvements
- **Directory Traversal Prevention**: Added checks for '..' patterns and absolute paths
- **Canonical Path Validation**: Ensures extracted files stay within destination directory
- **Attack Detection**: Throws clear error messages when malicious entries are detected
- **Defense in Depth**: Multiple validation layers to prevent bypass attempts

## Technical Changes
- Added canonical path validation for destination directory
- Implemented path traversal detection for zip entry names
- Added canonical path verification for resolved file paths
- Enhanced error handling with descriptive security exceptions
- Fixed missing ZipFile instantiation and duplicate mkdir() call

## Impact
- **Security**: Eliminates Zip Slip vulnerability (CWE-22: Path Traversal)
- **Compatibility**: Maintains existing functionality for legitimate zip files
- **Error Handling**: Provides clear feedback when malicious content is detected

Fixes: CWE-22 (Path Traversal), CVE-2018-1002207 pattern
Priority: High - Critical security vulnerability
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant