fix: sanitize MSG attachment filenames to prevent path traversal (GHS…#4117
Merged
william-u10d merged 2 commits intomainfrom Nov 6, 2025
Merged
fix: sanitize MSG attachment filenames to prevent path traversal (GHS…#4117william-u10d merged 2 commits intomainfrom
william-u10d merged 2 commits intomainfrom
Conversation
…A-gm8q-m8mv-jj5m) Addresses a security vulnerability where malicious attachment filenames containing path traversal sequences (e.g., "../../../etc/passwd") could write files outside the intended directory when processing MSG files. The fix normalizes both Unix and Windows path separators and sanitizes filenames by removing path components, null bytes, and handling edge cases like "." and ".." filenames. Changes include comprehensive test coverage for various attack vectors and a version bump to 0.18.18. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
william-u10d
approved these changes
Nov 6, 2025
william-u10d
approved these changes
Nov 6, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes path traversal vulnerability in email and MSG attachment filename handling (GHSA-gm8q-m8mv-jj5m).
Changes
Security Fix
Sanitizes attachment filenames in _AttachmentPartitioner for both email.py and msg.py
Uses os.path.basename() to strip path components from filenames
Normalizes backslashes to forward slashes to handle Windows paths on Unix systems
Removes null bytes and other control characters
Handles edge cases (empty strings, ".", "..")
Defaults to "unknown" for invalid or dangerous filenames
Test Coverage
Added 17 comprehensive tests covering:
Path traversal attempts (../../../etc/passwd)
Absolute Unix paths (/etc/passwd)
Absolute Windows paths (C:\Windows\System32\config\sam)
Null byte injection (file\x00.txt)
Dot and dotdot filenames (. and ..)
Missing/empty filenames
Complex mixed path separators
Valid filenames (ensuring they pass through unchanged)
Test Results
✅ All 17 new security tests pass
✅ All 129 existing tests pass
✅ No regressions
Security Impact
Prevents attackers from using malicious attachment filenames to write files outside the intended directory, which could lead to arbitrary file write vulnerabilities.
Changes include comprehensive test coverage for various attack vectors and a version bump to 0.18.18.