GeezerVison is showing github.com — id(directory_mail): CommandSink never calls validate_header_fields — header values both sibling sinks refuse are forwarded verbatim to the external mail program · Issue #6458 · developing-today/code
id(directory_mail): CommandSink never calls validate_header_fields — header values both sibling sinks refuse are forwarded verbatim to the external mail program #6458Labels app/idPackage/app: id (pkgs/ or apps/ in this repo)kind/bugSomething isn't working (prefixed form of the classic bug label)priority/normalOrdinary priority (the default)source/creatorFiled by the new-issue-creator jobtask/small-fixQueue packet kind: bounded fix with reproduction and targeted tests DescriptionProblem
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:
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: [email protected]), 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_fields in the file are its definition (:35), the OutboxSink call (:80), and the SmtpSink call (:257). There is no call anywhere in CommandSink's impl (:122-204).
CommandSink::send_with_timeout (:134-199) was read in full: it builds the Command with .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/sh program 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_file and the_outbox_refuses_crlf_recipient_before_creating_file assert the exact errors ("the subject has a line break or control character", "the recipient is not a plain address") for a subject of Your code\nBcc: [email protected] and a recipient of [email protected]>\r\nRCPT TO:<[email protected] — the same values CommandSink forwards unchecked. Non-ASCII and non-plain recipients hit the other two arms of the same validate_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
-
CommandSink refuses a Mail whose to is non-ASCII or not a plain address, or whose subject contains a control character, with the same errors as the other sinks — e.g. by calling mail.validate_header_fields()? at the top of CommandSink::send_with_timeout (or send), 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 / SmtpSink behaviour, the Mail shape, or the ID_MAIL_* environment contract for valid mail.
Activityadded kind/bugSomething isn't working (prefixed form of the classic bug label) task/small-fixQueue packet kind: bounded fix with reproduction and targeted tests app/idPackage/app: id (pkgs/ or apps/ in this repo) on Nov 6, 2026dezren39 commented on Nov 6, 2026 🤖 Agent note · filed
- Agent: new-issue-creator job (new-issue-creator-code-a)
- Session / ID: cron job new-issue-creator-code-a, run 2026-11-06T06:35Z
- Found via: filed this run
- Task: Filed after verifying by direct code read at origin/main 917e1a3 that CommandSink is the only MailSink that never calls Mail::validate_header_fields (occurrences only at directory_mail.rs:35 def, :80 OutboxSink, :257 SmtpSink), while its send_with_timeout (:134) forwards to/subject/body verbatim as ID_MAIL_* env vars to the external mail program. Sibling refusals are pinned by in-tree outbox tests. A runtime probe worktree was prepared on the laptop (~/git/fleet/probe-mail-cmd-wt) but the laptop became unreachable before the corrected probe run completed; the issue body states this and rests on the deterministic code read.
- Expectation: effort xs/s — one validate_header_fields call at the top of CommandSink's send path plus regression tests mirroring the outbox refusal tests; done when malformed mail is refused before any process is spawned and existing command-sink tests stay green.
- Links: issue id(directory_mail): CommandSink never calls validate_header_fields — header values both sibling sinks refuse are forwarded verbatim to the external mail program #6458; related 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 (closed, OutboxSink half), id(directory_mail): CommandSink has no timeout — a mail program that never exits hangs the directory request forever #1788 (closed, CommandSink timeout), id(directory_mail): plain_address accepts '@', 'a@', '@b' and 'a@@b.c' — SmtpSink's only address-shape gate never counts the @ or checks either side is non-empty #2637 (closed, plain_address)
dezren39 commented on Nov 6, 2026 dezren39 commented on Nov 6, 2026 🤖 Agent note · triage verdict: CONFIRMED
- Agent: repo queue worker, lane code-j
- Session / ID: task 10927, shift 2026-11-06T08:30Z
- Found via: triage task 10927
- Task: Verified issue id(directory_mail): CommandSink never calls validate_header_fields — header values both sibling sinks refuse are forwarded verbatim to the external mail program #6458 against current main.
- Evidence: Fresh
gh api read at origin/main dfe32779093f06a0bcdf2ea70ca35fab9a216a16: validate_header_fields occurs only at pkgs/id/src/directory_mail.rs:35 (definition), :80 (OutboxSink::send), and :257 (SmtpSink::send_with_timeout). Full read of CommandSink::send_with_timeout (:134-199) shows it builds the child Command with .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.
- Verdict: CONFIRMED — a real header-validation gap in the one sink that forwards to an external program.
- Routing: Follow-up fix enqueued as task 10931 (small_fix, dedupe
repo-health:v1:fix:developing-today/code:issue:6458): add mail.validate_header_fields()? at the top of CommandSink::send_with_timeout before spawning, plus regression tests mirroring the outbox refusal tests (newline subject, CRLF recipient, recording program never invoked).
- Links: issue id(directory_mail): CommandSink never calls validate_header_fields — header values both sibling sinks refuse are forwarded verbatim to the external mail program #6458; task 10927 (triage); task 10931 (fix); related 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
dezren39 commented on 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 commented on Nov 9, 2026 🤖 Agent note · handed off
dezren39 commented on Nov 9, 2026 🤖 Agent note · correction
dezren39 commented on Nov 9, 2026 🤖 Agent note · done (already_done)
MetadataMetadataapp/idPackage/app: id (pkgs/ or apps/ in this repo)kind/bugSomething isn't working (prefixed form of the classic bug label)priority/normalOrdinary priority (the default)source/creatorFiled by the new-issue-creator jobtask/small-fixQueue packet kind: bounded fix with reproduction and targeted tests DevelopmentNo branches or pull requestsIssue actions
|