reject mixed-separator path traversal in imap attachment names - #70665
Open
Samin061 wants to merge 2 commits into
Open
reject mixed-separator path traversal in imap attachment names#70665Samin061 wants to merge 2 commits into
Samin061 wants to merge 2 commits into
Conversation
uranusjr
reviewed
Jul 29, 2026
Comment on lines
+325
to
+329
| # Windows also accepts "/" as a path separator, so a "../" attachment name | ||
| # traverses there even though os.sep is a backslash and the old | ||
| # f"..{os.sep}" check missed it. Normalise both separators and reject any | ||
| # ".." path component. | ||
| return any(part == ".." for part in name.replace("\\", "/").split("/")) |
Member
There was a problem hiding this comment.
Non-Windows platforms treat backslashes differently, so this unconditional replacement is wrong. Use os.altsep and os.sep instead.
Contributor
Author
There was a problem hiding this comment.
Good point, backslashes are legal in POSIX filenames so the unconditional replace was wrong. Switched to splitting on os.sep plus os.altsep, so backslashes stay ordinary chars on POSIX and both separators get caught on Windows. Added separate POSIX and Windows parametrized tests to lock in the platform difference.
Signed-off-by: bibi samina <sam@bugqore.com>
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.
_is_escaping_current_directoryin the imap hook rejects a traversing attachment name withf"..{os.sep}" in name, which is tied to the host separator. On Windowsos.sepis a backslash but a forward slash is also a valid path separator, so an attachment named../../evilslips past the check and, once joined onto the output directory in_correct_path, resolves outside it, letting whoever sent the mail write an arbitrary file. This normalises both separators and rejects any..path component instead.Was generative AI tooling used to co-author this PR?