Skip to content

id(directory_mail): SMTP reply reader accepts any non-dash byte as the code terminator — 2500 …, 250OK and a 2500 multiline tail all pass as reply 250 #3417

Closed

Description

@dezren39

id(directory_mail): SMTP reply reader accepts any non-- byte as the code terminator — 2500 …, 250OK and a 2500 multiline tail all pass as reply 250

Problem

pkgs/id/src/directory_mail.rs — SmtpSink's reply reader expect() (lines 233–252) never validates the byte after the 3-digit reply code.

ensure!(
    line.get(..3).and_then(|c| c.parse::<u16>().ok()) == Some(code),
    "the mail relay replied: {line}"
);
if line.as_bytes().get(3) != Some(&b'-') {
    return Ok(());
}

It checks only that the first three bytes parse to the expected code, and that the fourth byte is not - (the multiline continuation marker). Any other fourth byte — a digit, a letter, punctuation — is treated as the end of a successful reply. An SMTP reply code is exactly three digits followed by a space (or end of line for a bare code), per RFC 5321 §4.2; a line whose fourth byte is anything else is not that code at all:

  • 2500 bogus code is read as reply 250 (the code is 2500, or 250 glued to a 0 — either way not 250<SP>);
  • 250OK no separator is read as reply 250;
  • a multiline reply 250-first line / 2500 final line is accepted as a complete 250 reply at its final line.

Every stage of the exchange uses this reader: the greeting (expect(..., 220), :168), EHLO / MAIL FROM / RCPT TO (smtp_command(..., 250), :169–183), DATA (354, :184) and the post-body acceptance (expect(..., 250), :193) — so a malformed reply at any stage is taken as that stage's success, and the sink reports the confirmation mail as sent.

Evidence (verified this run, main 674f7eee)

directory_mail.rs sha256 dc6f7935072687eee55b0a659ed48d1aa2d24b51a8445808719c38688a7da682 — identical on the sandbox clone, the laptop clone, and origin/main.

Laptop probe ~/git/fleet/probe-2026-11-01-laneA-smtpcode/ (the probe crate compiles directory_mail.rs itself as a module — copied from the laptop clone with only the 7 leading //! module-doc lines dropped, since those cannot survive inclusion as a submodule; diff verified every code byte from line 8 on is identical — and drives the real SmtpSink::send against scripted fake relays on loopback):

control-good        => OK
control-wrong-code  => ERR the mail relay replied: 251 not 250   (EHLO answered 251 — the code check itself works)
case-greeting-2200  => OK    (greeting "2200 fake ready" accepted as 220)
case-ehlo-2500      => OK    (EHLO reply "2500 bogus code" accepted as 250)
case-rcpt-250OK     => OK    (RCPT reply "250OK no separator" accepted as 250)
case-multiline-tail => OK    ("250-first line" / "2500 final line" accepted as a complete 250)
control-multiline   => OK    ("250-first line" / "250 final line" — well-formed multiline still works)

So send() returns Ok — the confirmation mail is reported sent — for every malformed-code case, while a genuinely different code (251) is refused as it should be.

Why it matters

The relay is loopback and operator-chosen, but it is a separate process: a wrong service squatting on the configured port, a buggy/misconfigured local daemon, or a spam-filter front-end that speaks a near-SMTP dialect can answer with lines that merely start with the expected digits. Today the sink cannot tell that apart from success at any stage — greeting, envelope, or final acceptance — so a directory confirmation code (the sign-in path this sink serves, world_session awaits sink.send(...)) can be reported delivered when the relay never actually accepted the message with the required reply. Every neighbouring gate in this file is strict about shape (loopback-only relay, ASCII/plain-address checks, control-free subject); the reply code's own shape is the one unchecked piece. This is distinct from #1899 (the same reader's missing deadline/line bound — a hang, not a misread code) and #2637 (the address-shape gate).

Acceptance criteria

  • expect() accepts a line as the final line of the expected reply only when the code is exactly three digits and the fourth byte is a space or the line ends there (bare code); a fourth byte of - continues a multiline reply, and anything else fails the send with the existing "the mail relay replied: …" error.
  • The rule applies uniformly to every stage (greeting 220, EHLO/MAIL/RCPT 250, DATA 354, post-body 250, QUIT 221).
  • Regression tests with the fake-relay harness already in directory_mail.rs's tests (or equivalent): 2500 …, 250OK, and a 2500 multiline final line are each refused; well-formed single-line (250 ok, bare 250) and multiline (250-… / 250 …) replies still pass; a wrong code (251 for 250) still fails.
  • No change to the timeout behaviour tracked in id(directory_mail): SmtpSink's reply reader has no total deadline and no line bound — a trickling or never-terminating relay reply hangs the directory request forever #1899, and no change to what a successful send means.

Dedup: searched open + closed issues for directory_mail / SMTP reply / expect on 2026-11-01 — #1899 (reply-reader deadline + line bound), #1788 (CommandSink timeout), #2637 (plain_address shape), #2404 (OutboxSink headers) are the neighbours; none covers the reply-code terminator shape.

Activity

  1. developing-today commented on Nov 1, 2026

    @developing-today
    Contributor
  2. added
    kind/bugSomething isn't working (prefixed form of the classic bug label)
    task/triageQueue packet kind: verify, reproduce, and route this item
    source/creatorFiled by the new-issue-creator job
    priority/lowNice to have; do when convenient
    effort/sSmall: expected under 2 hours of work
    app/idPackage/app: id (pkgs/ or apps/ in this repo)
    on Nov 1, 2026
  3. dezren39 commented on Nov 1, 2026

    @dezren39
    MemberAuthor

    🤖 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-01 02:05 CST
    • Found via: filed this run
    • Task: Make SmtpSink's reply reader (directory_mail.rs expect()) validate the byte after the 3-digit SMTP reply code — only a space or end-of-line ends a reply, - continues a multiline reply, anything else (2500 …, 250OK, a 2500 multiline tail) fails the send.
    • Expectation: effort/s — done when the acceptance criteria on this issue pass, including fake-relay regression tests for the malformed-code shapes plus well-formed single-line/bare/multiline controls.
    • Links: evidence in the issue body; laptop probe at ~/git/fleet/probe-2026-11-01-laneA-smtpcode/ (real directory_mail.rs code, sha dc6f7935… at main 674f7ee, driven against scripted fake relays: controls OK/ERR as expected, all three malformed-code shapes accepted as success).
  4. 11 remaining items

  5. dezren39 commented on Nov 2, 2026

    @dezren39
    MemberAuthor

    Implementation is complete and I’m in verification now. The repository-wide cargo fmt --check reports pre-existing formatting differences in unrelated pkgs/id files; it did not report directory_mail.rs. I’m running the focused id library tests with the fleet build lock.

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

    @dezren39
    MemberAuthor

    I reviewed the stale draft PR #3708. Its unique test detail is asserting the complete relay error text (not just the common prefix); the malformed shapes, bare/single-line/multiline controls, and wrong-code cases are otherwise covered by the new fake-relay tests. I’m incorporating exact error-message assertions while keeping the send()-level harness coverage.

  8. dezren39 commented on Nov 2, 2026

    @dezren39
    MemberAuthor

    CI coverage note from inspecting the current checkout: .github/workflows/id-check.yml declares push to main, schedule, and workflow_dispatch, but no pull_request event, despite its header/comments describing PR checks. I’m keeping the requested code scope limited to directory_mail.rs; after opening the PR I’ll inspect the actual checks and report whether CI ran the package tests.

  9. dezren39 commented on Nov 2, 2026

    @dezren39
    MemberAuthor

    Focused local verification passed on the laptop under ~/tools/fleet-build-lock: cargo test --manifest-path pkgs/id/Cargo.toml -p id --no-default-features --features world --lib directory_mail::tests — 17 passed, 0 failed. The malformed reply tests, valid bare/single-line/multiline controls, wrong-code case, and existing timeout tests all passed. I’m preparing the scoped commit now; CI trigger coverage will be checked on the PR.

  10. dezren39 commented on Nov 2, 2026

    @dezren39
    MemberAuthor

    Fix is ready for review in PR #4460 (branch queue/6046-3417-smtp-reply-terminator, commit 3d78b9de8). expect() now finishes only on space or end-of-code, continues on -, and rejects other separators with the existing relay error; regression tests cover malformed, valid, and wrong-code replies. Local focused tests passed (17 passed, 0 failed). This PR supersedes stale draft #3708. I’m not merging; CI/package checks still need to run on the PR.

  11. dezren39 commented on Nov 2, 2026

    @dezren39
    MemberAuthor

    Agent note — task 6046 resumed (lane code-l)

  12. dezren39 commented on Nov 2, 2026

    @dezren39
    MemberAuthor

    Agent note — task 6046 done (lane code-l)

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

Metadata

Metadata

Assignees

Labels

app/idPackage/app: id (pkgs/ or apps/ in this repo)effort/sSmall: expected under 2 hours of workkind/bugSomething isn't working (prefixed form of the classic bug label)priority/lowNice to have; do when convenientsource/creatorFiled by the new-issue-creator jobtask/triageQueue packet kind: verify, reproduce, and route this item

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions