Repository navigation
Description
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 codeis read as reply 250 (the code is 2500, or 250 glued to a0— either way not250<SP>);250OK no separatoris read as reply 250;- a multiline reply
250-first line/2500 final lineis 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 a2500multiline final line are each refused; well-formed single-line (250 ok, bare250) 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
developing-today commentedon Nov 1, 2026
CODE-1305
dezren39 commentedon Nov 1, 2026
🤖 Agent note · filed
-continues a multiline reply, anything else (2500 …, 250OK, a 2500 multiline tail) fails the send.11 remaining items
dezren39 commentedon Nov 2, 2026
Implementation is complete and I’m in verification now. The repository-wide
cargo fmt --checkreports pre-existing formatting differences in unrelatedpkgs/idfiles; it did not reportdirectory_mail.rs. I’m running the focusedidlibrary tests with the fleet build lock.dezren39 commentedon Nov 2, 2026
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.
dezren39 commentedon Nov 2, 2026
CI coverage note from inspecting the current checkout:
.github/workflows/id-check.ymldeclarespushtomain,schedule, andworkflow_dispatch, but nopull_requestevent, despite its header/comments describing PR checks. I’m keeping the requested code scope limited todirectory_mail.rs; after opening the PR I’ll inspect the actual checks and report whether CI ran the package tests.dezren39 commentedon Nov 2, 2026
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.dezren39 commentedon Nov 2, 2026
Fix is ready for review in PR #4460 (branch
queue/6046-3417-smtp-reply-terminator, commit3d78b9de8).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.dezren39 commentedon Nov 2, 2026
Agent note — task 6046 resumed (lane code-l)
3d78b9de, MERGEABLE/CLEAN; diff verified against the acceptance criteria (onlypkgs/id/src/directory_mail.rs:expect()finishes a reply only on space/end-of-code,-continues multiline, any other byte fails withthe mail relay replied: ...; trim now strips only CR/LF).3d78b9de, no findings, none unresolved. Checks: opencode-config-guard SUCCESS (id-check.yml has no pull_request trigger; targeted tests run on the laptop instead).expect()signature; its exact-error-message test detail is already incorporated in PR id(directory_mail): enforce strict SMTP reply-code terminator shape #4460's tests; its unrelatedplan.mddeletion is intentionally not carried. Nothing unique to salvage — PR fix(id/directory_mail): enforce strict terminator shape for SMTP reply codes #3708 will be closed as superseded once PR id(directory_mail): enforce strict SMTP reply-code terminator shape #4460 merges.directory_mailtests on the laptop at the PR head, then merge.dezren39 commentedon Nov 2, 2026
Agent note — task 6046 done (lane code-l)
fixed_merged. PR id(directory_mail): enforce strict SMTP reply-code terminator shape #4460 squash-merged to main as12b305e55cc465728aec0bb2b87ca8b2c881dedd; issue 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 by the merge.pkgs/id/src/directory_mail.rs); Codex review completed at head3d78b9dewith no findings; targeted tests re-run on the laptop at that head —cargo test -p id --no-default-features --features world --lib directory_mail::tests: 17 passed, 0 failed (including the new malformed-terminator, valid-reply, and wrong-code regression tests).id-check.ymlhas nopull_requesttrigger, so pkgs/id CI runs on push to main; the pre-existing main compile breakage inreferences.rsis tracked separately as issue id(lib): references.rs does not compile — LocalIndex derives Default over a StoreId with no Default impl, and from_markdown breaks with a borrow of a loop-local String (PR #2756) #4454 and is untouched by this change.