Skip to content

id(directory_mail): CommandSink never calls validate_header_fields — header values both sibling sinks refuse are forwarded verbatim to the external mail program #6458

Closed

Description

@dezren39

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:

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_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: attacker@evil.example and a recipient of a@b.co>\r\nRCPT TO:<x@y.z — 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.

Activity

  1. added
    kind/bugSomething isn't working (prefixed form of the classic bug label)
    task/small-fixQueue packet kind: bounded fix with reproduction and targeted tests
    source/creatorFiled by the new-issue-creator job
    priority/normalOrdinary priority (the default)
    app/idPackage/app: id (pkgs/ or apps/ in this repo)
    on Nov 6, 2026
  2. dezren39 commented on Nov 6, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · filed

  3. added
    work/assignedQueue worker lifecycle state
    queue/claimedQueue worker lifecycle state
    and removed on Nov 6, 2026
  4. dezren39 commented on Nov 6, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · picked up

  5. dezren39 commented on Nov 6, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · triage verdict: CONFIRMED

  6. 71 remaining items

  7. dezren39 commented on Nov 8, 2026

    @dezren39
    MemberAuthor

    {"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."}

  8. removed
    queue/parkedQueue task is parked (waiting on CI, time, or an event)
    status/parkedDeliberately paused with a recorded resume condition
    work/assignedQueue worker lifecycle state
    on Nov 8, 2026
  9. dezren39 commented on Nov 9, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · handed off

  10. added
    work/assignedQueue worker lifecycle state
    queue/parkedQueue task is parked (waiting on CI, time, or an event)
    status/parkedDeliberately paused with a recorded resume condition
    on Nov 9, 2026
  11. dezren39 commented on Nov 9, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · correction

  12. removed
    status/parkedDeliberately paused with a recorded resume condition
    queue/parkedQueue task is parked (waiting on CI, time, or an event)
    work/assignedQueue worker lifecycle state
    on Nov 9, 2026
  13. dezren39 commented on Nov 9, 2026

    @dezren39
    MemberAuthor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions