Repository navigation
Description
Problem
pkgs/id/src/directory_mail.rs defines three MailSinks for the same Mail { to, subject, body }, and a shared header-field validation, Mail::validate_header_fields (:35) — recipient must be ASCII and a plain address (plain_address), subject must contain no control character. Two sinks enforce it before doing anything with the message:
OutboxSink::send(:79-80) callsmail.validate_header_fields()?before creating the.emlfile (this was the fix for id(directory_mail): OutboxSink writes To/Subject into the .eml header block with none of SmtpSink's validation — a newline in either forges arbitrary headers #2404, which had found the outbox writing unvalidatedTo:/Subject:headers).SmtpSink::send_with_timeout(:257) callsmail.validate_header_fields()?before connecting to the relay.
CommandSink — the sink used for --world-mail-command (commands/serve.rs:773), i.e. the configured external mail program — never calls it. Its send_with_timeout (:134-140) passes the fields verbatim into the child process environment:
.env("ID_MAIL_TO", &mail.to)
.env("ID_MAIL_SUBJECT", &mail.subject)
.env("ID_MAIL_BODY", &mail.body)So a Mail that both sibling sinks refuse — a subject with an embedded newline (Your code\nBcc: attacker@evil.example), a recipient with CRLF / SMTP smuggling syntax, a non-ASCII (internationalised) recipient, or a recipient that is not a plain address at all — is handed unchecked to the external program. The shipped program, nixos/services/id-mail/cloudflare-mail.sh, forwards ID_MAIL_TO / ID_MAIL_SUBJECT as the to / subject of a Cloudflare Email Sending API (or mail Worker) call — i.e. these values do become mail headers downstream, just one process later — and any operator-configured program receives them under the same contract, trusting that the sink enforced the module's one documented invariant ("Validate fields that sinks serialize into mail headers", :34). #2404's acceptance criteria said the validation should be shared so that "no sink writes unvalidated header fields"; the command sink is the one sink that still forwards them unvalidated.
Mail's fields are pub, and the sinks are the crate's public mail API, so the guarantee has to live in the sink (as it now does for the other two), not in today's callers.
Evidence (verified this run, origin/main 917e1a3)
Verified by direct code read of pkgs/id/src/directory_mail.rs at origin/main 917e1a3 (two independent reads this run — a full read of the sink implementations and a grep line map of every validate_header_fields occurrence):
- The only occurrences of
validate_header_fieldsin the file are its definition (:35), theOutboxSinkcall (:80), and theSmtpSinkcall (:257). There is no call anywhere inCommandSink's impl (:122-204). CommandSink::send_with_timeout(:134-199) was read in full: it builds theCommandwith.env("ID_MAIL_TO", &mail.to)/.env("ID_MAIL_SUBJECT", &mail.subject)/.env("ID_MAIL_BODY", &mail.body), spawns it, and returns Ok on a successful exit — no validation step exists on the path, so for any program that exits 0 (e.g. the recording/bin/shprogram the module's own tests use, :509) the malformed fields are delivered verbatim.- The sibling refusals are pinned by in-tree tests:
the_outbox_refuses_subject_header_injection_before_creating_fileandthe_outbox_refuses_crlf_recipient_before_creating_fileassert the exact errors ("the subject has a line break or control character", "the recipient is not a plain address") for a subject ofYour code\nBcc: attacker@evil.exampleand a recipient ofa@b.co>\r\nRCPT TO:<x@y.z— the same valuesCommandSinkforwards unchecked. Non-ASCII and non-plain recipients hit the other two arms of the samevalidate_header_fields(:38-47).
A runtime probe (recording command sink in a laptop worktree, ~/git/fleet/probe-mail-cmd-wt) was prepared this run but the laptop became unreachable before the corrected probe run completed; this filing therefore rests on the code read above, which is deterministic — there is no validation call to find — and the triage packet asks the worker to add the regression tests in the acceptance criteria as the executable proof.
Dedup: #2404 (closed) covered OutboxSink only and named CommandSink out of scope except for its timeout (#1788, closed). Searches for CommandSink, validate_header_fields, and directory_mail return no open issue covering command-sink header validation.
Why it matters
The three sinks are interchangeable configuration choices for the same confirmation-mail path (commands/serve.rs:769-773 picks one from flags). A validation invariant that holds for two of the three is a trap: switching a deployment from the outbox/SMTP sink to a mail command silently drops the header-injection, address-shape, and SMTPUTF8 refusals the module deliberately enforces, and the external program — the component least able to know the invariant — receives exactly the smuggled values the other sinks were fixed to refuse (#2404, #2637).
Acceptance criteria
-
CommandSinkrefuses aMailwhosetois non-ASCII or not a plain address, or whosesubjectcontains a control character, with the same errors as the other sinks — e.g. by callingmail.validate_header_fields()?at the top ofCommandSink::send_with_timeout(orsend), before any process is spawned. - Regression tests mirror the existing outbox refusal tests for the command sink: a newline subject and a CRLF recipient are both refused and the recording program is never invoked (no output file created).
- The legitimate path is unchanged: the existing command-sink tests (message passed in the environment, failing command is an error, timeout kill/reap) pass unmodified.
- No change to
OutboxSink/SmtpSinkbehaviour, theMailshape, or theID_MAIL_*environment contract for valid mail.
Activity
dezren39 commentedon Nov 6, 2026
🤖 Agent note · filed
dezren39 commentedon Nov 6, 2026
🤖 Agent note · picked up
dezren39 commentedon Nov 6, 2026
🤖 Agent note · triage verdict: CONFIRMED
gh apiread at origin/maindfe32779093f06a0bcdf2ea70ca35fab9a216a16:validate_header_fieldsoccurs only atpkgs/id/src/directory_mail.rs:35(definition),:80(OutboxSink::send), and:257(SmtpSink::send_with_timeout). Full read ofCommandSink::send_with_timeout(:134-199) shows it builds the childCommandwith.env("ID_MAIL_TO", &mail.to)/.env("ID_MAIL_SUBJECT", &mail.subject)/.env("ID_MAIL_BODY", &mail.body)and spawns it with no validation step. The report is confirmed exactly as filed.repo-health:v1:fix:developing-today/code:issue:6458): addmail.validate_header_fields()?at the top ofCommandSink::send_with_timeoutbefore spawning, plus regression tests mirroring the outbox refusal tests (newline subject, CRLF recipient, recording program never invoked).71 remaining items
fix(id): CommandSink validates header fields before spawning (#6458) (#…
dezren39 commentedon Nov 8, 2026
{"event":"done","worker":"repo-worker-code","queue":"repo-health-code-pilot","task_id":13318,"lane":"code-y","note":"Task 13318 COMPLETE (fixed_merged). PR #6545 squash-merged, merge SHA 89898d0; issue #6458 closed by the merge (PR body Fixes #6458). Fresh by lane code-y: head 3364069 merge-tree clean vs current main; Codex review on that head completed, no findings; targeted tests re-run fresh on laptop worktree queue-13318-6545-commandsink-validate: cargo test --manifest-path pkgs/id/Cargo.toml --lib directory_mail — 22 passed, 0 failed. CI: 7 checks QUEUED (systemic runner stall), 1 SUCCESS / 1 SKIPPED / CodeRabbit NEUTRAL, 0 failed; merged under standing criteria on local evidence."}
dezren39 commentedon Nov 9, 2026
🤖 Agent note · handed off
opencode(lane row 3319)dezren39 commentedon Nov 9, 2026
🤖 Agent note · correction
dezren39 commentedon Nov 9, 2026
🤖 Agent note · done (already_done)