Repository navigation
fix(backend): authenticate the inbound From before trusting it (WI-2362) - #566
stefan-ernst wants to merge 2 commits into
Conversation
Inbound email attributed every message to a portal customer and admitted replies to a private thread based on the attacker-controlled From header. Neither the customer match nor the thread-participant guard consulted Authentication-Results, Received-SPF, DKIM, or DMARC, so anyone able to deliver a spoofed From could post into a private thread, become a persistent participant, or create a request as a customer. Evaluate the receiving MTA's Authentication-Results (falling back to Received-SPF) against the From domain and require an aligned SPF, DKIM, or DMARC pass. Only headers above the first Received header are trusted, so a sender-injected Authentication-Results below the receiving MTA's Received header is ignored. Under the default strict policy, mail whose sender cannot be authenticated is held: no item or comment is created, no portal customer is matched or created under the claimed identity, and the outcome is recorded on the tracking row for the admin diagnostics view and channel email log. Mailbox and intake policies can be set to strict or off for providers that do not add authentication headers. - internal/email/sender_auth.go: parser, alignment, and policy resolution - parser records header order so injected results can be rejected - email_message_tracking.sender_auth and intakes.sender_authentication - mailbox and per-intake sender-authentication controls in the UI
|
Size Change: 0 B 🆕 Total Size: 0 B |
|
Request changes. Strict mode can trust the wrong authentication result, and it can permanently delete legitimate mail that the UI describes as “held.”
I ran the companion PR’s |
- Trust only results above a mailbox-specific receiver boundary: the first Received hop whose host matches the mailbox's trusted authserv-ids (explicit config, provider defaults, or the mail host). A result from an untrusted authserv-id is rejected, and a message with no trusted hop fails closed instead of trusting an arbitrary header. An internal delivery hop above a genuine result no longer discards it. - Parse Authentication-Results per RFC 8601: clauses split outside quoted strings and comments, and a method is accepted only as the first token of a clause, so a quoted diagnostic can never be read as a verdict. - Reject Received-SPF passes without an envelope-from; a HELO pass authenticates the sending host, not the sender. - Use organizational-domain comparison for SPF and DKIM alignment, and compare a DMARC header.from to the actual From domain directly, so sibling subdomains under one organizational domain align. - Give authentication holds a distinct action: the scheduler leaves the original in the mailbox (never delete or mark read) and reports the hold, including on a deduplicated retry. - Preserve an explicit per-intake strict override when editing an intake; it is no longer collapsed into inherit. - Return and display skipped_reason in the channel email log so a held message is identified instead of showing a raw spf=pass summary. - Read header order line by line instead of splitting the whole body.
|
All eight findings are addressed in 57b9b7a, with companion tests in Windshiftapp/core-tests-internal#74. P1 — trusted receiver boundary. P1 — RFC 8601 parser. P1 — Received-SPF identity. A pass without P1 — hold disposition. New P1 — intake override. Removed the normalization that collapsed every non- P2 — alignment. SPF/DKIM now use organizational-domain (public suffix list) alignment; DMARC compares the reported P2 — email log. P2 — header order allocation. Re-ran the email, scheduler, database, repository, handlers, and services suites plus the email/intake integration tests, |
|
Closing without merge. WI-2365 supersedes WI-2362: we will authorize private replies using a Windshift-issued, recipient-bound outbound Message-ID and keep ordinary email intake compatible with mailboxes that provide no authentication verdict. Mail filtering stays with the receiving provider. The underlying authorization fix remains open in WI-2365. |
Summary
Fixes WI-2362. Inbound email attributed every message to a portal customer and admitted replies to a private thread based on the attacker-controlled
Fromheader. NeitherfindOrCreatePortalCustomernor thesenderIsThreadParticipantguard consultedAuthentication-Results,Received-SPF, DKIM, or DMARC, so anyone who could deliver a spoofedFromcould:What changed
internal/email/sender_auth.go). Parse the receiving MTA'sAuthentication-Results(falling back toReceived-SPF) and require an alignedspf=pass,dkim=pass, ordmarc=passfor theFromdomain. Relaxed DMARC alignment (parent/child domains) is accepted; a DMARC pass is checked againstheader.fromwhen present.Authentication-Results/Received-SPFvalues above the firstReceivedheader are considered, so a sender-injected result below the MTA'sReceivedheader is ignored.email_sender_authentication) and per-intake (sender_authentication) policy can bestrictoroff; an empty value resolves to strict. In strict mode, unauthenticated mail is held: no item or comment is created, no portal customer is matched or created under the claimed identity, and the outcome (sender_auth) is recorded for the admin diagnostics view and channel email log.email_message_tracking.sender_authandintakes.sender_authentication(migration20261204_email_sender_authentication). No backfill: existing intakes stay strict.Migration note
Strict is the default for new and existing intakes. If a mailbox provider does not add
Authentication-Results/Received-SPFheaders, operators must set Sender authentication to Off on the mailbox or the affected intake, or legitimate mail will be held. Held mail is visible under Admin → Diagnostics → Email intake and in the channel email log.Testing
./overlay.sh ../core -- -tags=test -count=1 ./internal/email/..../overlay.sh ../core -- -tags=test -count=1 ./internal/scheduler/..../overlay.sh ../core -- -tags=test -count=1 ./internal/database/..../overlay.sh ../core -- -tags=test -count=1 ./internal/repository/... ./internal/handlers/..../overlay.sh ../core -- -tags=test -count=1 ./internal/services/..../overlay.sh ../core -- -tags=test -count=1 -run 'Channel|Diagnostic|Email|Intake' ./tests/...golangci-lint runon the changed packagesnpm run checkandnpm run typecheckinfrontendNew tests cover SPF/DKIM/DMARC pass, fail, and absent-header cases, aligned and misaligned domains, on both the new-request and reply paths, plus the forged-header ordering guard and the strict/off policies.
Companion PR
Tests live in the private repo: Windshiftapp/core-tests-internal#74