Harden IMAP hook against symlink-followed attachment writes - #67075
Closed
Lougarou wants to merge 1 commit into
Closed
Harden IMAP hook against symlink-followed attachment writes#67075Lougarou wants to merge 1 commit into
Lougarou wants to merge 1 commit into
Conversation
potiuk
marked this pull request as draft
June 18, 2026 13:59
Member
|
Note 🗑️ Closing stale draft · by This draft has been inactive for ~13 days. Closing to keep the queue tidy — no judgment on the change itself. Please reopen (or open a fresh PR) whenever you pick it back up, and a maintainer will be glad to take a look. Automated triage — may be imperfect. |
1 task
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.
ImapHook._create_filewrote downloaded attachments with a plainopen(file_path, "wb"), which follows a symlink at the destination. Theexisting
_is_symlinkguard in_create_filesonly inspects the bareattachment
namerelative to the current working directory — not the realjoined output path (
file_path) that is actually written to.This hardens
_create_file:os.path.islinkon the real joined target and refuses to writethrough a symlink there, matching the existing
_is_symlinkrejection style;os.openwithO_NOFOLLOW(feature-gated withgetattr(os, "O_NOFOLLOW", 0), so it is a no-op on Windows, which lacks theflag) to also close the check-to-open TOCTOU window.
The open flags are
O_WRONLY | O_CREAT | O_TRUNC— deliberately withoutO_EXCL— so the hook's existing overwrite-on-redownload behaviour ispreserved; the file mode is
0o600. Legitimate downloads (includingredownload/overwrite) behave exactly as before; only writes that would pass
through a symlink are now refused.
test_imap.pyis updated: thedownload_mail_attachmentstests now patchos.open/os.fdopeninstead of the builtinopen, the symlink test'sislinkcall-count expectation is relaxed (it is now legitimately consulted intwo places), and two tests are added — one pinning that a symlink at the real
joined target blocks the write, one pinning the
O_NOFOLLOW/ no-O_EXCLflags.Was generative AI tooling used to co-author this PR?
Generated-by: Anthropic Claude (Claude Code) following the guidelines
{pr_number}.significant.rst, in airflow-core/newsfragments. You can add this file in a follow-up commit after the PR is created so you know the PR number.Important
🛠️ Maintainer triage note for @Lougarou · by
@potiuk· 2026-06-18 13:57 UTCPaused pending your next update — this PR has been inactive for ~30 days, so it's been moved to draft to keep the review queue clear:
main, address any new failures, and mark it Ready for review when you pick it back up — no rush.The ball is in your court — you've been assigned to this PR.
Automated triage — may be imperfect; a maintainer takes the next look.