Skip to content

fix(digest): never email an address on a reserved domain - #2298

Merged
lilyshen0722 merged 1 commit into
mainfrom
growth/digest-skip-reserved
Oct 17, 2026
Merged

lilyshen0722 merged 1 commit into
mainfrom
growth/digest-skip-reserved

Conversation

@lilyshen0722

Copy link
Copy Markdown
Contributor

From the first real daily-digest run (2026-10-17 06:01Z): of its 3 emails, one went to a verified operator account on @ops.commonly.invalid. Ruled by Cofounder.

Why

RFC 2606 reserves .invalid, .test and .example, and RFC 6761 reserves .localhost. Mail to those domains can never be delivered, so a send buys only a bounce against our sender's reputation, which every real person's email shares.

  • Our QA and operator accounts use these domains on purpose, and some are verified, so the verified-address check let the send through.
  • More would follow as those accounts pass the 20h-away line. Several non-empty .invalid digests were skipped this run only because their owners weren't away yet.

What

isReservedEmailDomain (backend/utils/reservedEmailDomain.ts) matches the address's last label against those four.

  • Ordinary domains still send: invalid.com and test-co.io are ordinary.
  • Not included: the reserved second-level names (example.com/.net/.org), which are a separate RFC 2606 rule. The existing tests send to example.com, and widening to those is its own decision.

The digest email step checks it after the existing verified and opt-out checks, before minting an unsubscribe token or claiming the send:

  • The digest record stays. It gets no emailedAt, and the user gets no lastDigestSent.
  • Each skip logs one line with the user id and never the address, using a constant message string.

Tests

  • Helper: 12 cases, covering the reserved forms (subdomain, upper case, trailing dot), ordinary look-alikes, and non-addresses.
  • Service: a reserved verified address plus an ordinary one in the same run gives sent: 1, skipped: 1, mails only the ordinary address, keeps the digest unstamped, and logs exactly one line naming the user id and not the address.

Mutations:

  • A skip that never fires fails the service test by name.
  • Matching any label instead of the last fails the ordinary-domain cases.

The digest, scheduler and helper suites pass, 39/39.

🤖 Generated with Claude Code

https://claude.ai/code/session_0157AG2wo8mJYqKezXNs48Ya

The first real digest run (2026-10-17 06:01Z) sent one of its three emails
to a verified operator account on @ops.commonly.invalid. RFC 2606 reserves
.invalid, .test and .example (and RFC 6761 .localhost): mail to them can
never be delivered, so the send buys only a bounce against the sender's
reputation, which every real person's email shares. Our QA and operator
accounts use these domains on purpose, and some are verified, so the
verified-address check let it through. More would follow as those accounts
pass the 20h-away line.

The email step now skips such an address before minting an unsubscribe
token or claiming the send. The digest record is kept (no emailedAt, no
lastDigestSent), and one line is logged per skip, naming the user id and
never the address. Matched on the last label only, so invalid.com is an
ordinary domain; the reserved second-level names (example.com etc.) are a
separate rule and not included.

Mutations: the skip never firing reds the service test by name; matching
any label instead of the last reds the ordinary-domain cases.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_0157AG2wo8mJYqKezXNs48Ya

@lilyshen0722 lilyshen0722 left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Written by Sprint Review, a Commonly agent — code gate at 33e2ae298598c14fedb8e4913b823716e21048d2, requested by growth-ops in pod thread 78679.

Both stated claims hold, measured by mutation with asserted needle counts, failures taken by name. BASE and RESTORED both 2 suites / 27 passed (reservedEmailDomain.test.ts + digestEmailService.test.js, node 22).

The two claims

"A skip that never fires turns the service test red." Confirmed. return RESERVED_TOP_LEVEL_DOMAINS.has(labels[labels.length - 1]) → return false (needle ×1, utils/reservedEmailDomain.ts:23) reds 7 by name: the six … is reserved cases and skips a verified address on a reserved domain, keeps the digest, and still sends to an ordinary one.

"Matching any label instead of the last turns the ordinary-domain cases red." Confirmed. labels.some((l) => RESERVED_TOP_LEVEL_DOMAINS.has(l)) reds 10, the named ordinary-domain pair among them: [email protected] is an ordinary domain and [email protected] is an ordinary domain. Worth knowing why the other eight went: the pre-existing fixture address is [email protected], so the service suite is a second, accidental reader of the last-label rule. The new test's ordinary recipient is @gmail.com, so it is not — it stays green under this mutation, correctly.

The wiring, and the ordering claim

  • The guard is reachable, not just correct. Deleting the whole if (isReservedEmailDomain(user.email)) block from the service (needle ×1, util untouched) reds the new test by name. The util passing is not what carries this.
  • "Logs the user id only" is pinned: adding email: user.email to the log object reds the same test on not.toContain('commonly.invalid').
  • "Before the send is claimed" is pinned: moving the guard below the metadata.emailedAt claim reds it.
  • "Before a token is minted" is NOT pinned. Moving the guard to sit after the token-mint block but still before the claim leaves the suite 15/15 green. So a version that mints and user.save()s an unsubscribe token for an address that can never receive it passes today. One assertion closes it — the select already loads +digestUnsubscribeToken, so expect((await User.findById(reserved._id)).digestUnsubscribeToken).toBeUndefined(). Non-blocking: the shipped order is right; only the guard against reordering is missing.

Placement read directly: the block sits after the verified/isBot/preference skip and above both the token mint and the claim. Lint on both changed files: 0 errors (3 max-len warnings pre-exist at :117/:122/:126, outside the diff). schedulerService.digestEmail.test.js — the only other importer — 2/2. merge-tree clean against main 829b65bcb.

CI at this exact head, run 39009066096 (headSha read back as 33e2ae29…): Test & Coverage success, Service Tests (Tier 1 — real DBs) success. Tier 1 is the one that matters here — the suite I ran locally is mongodb-memory-server, and the incident this PR answers was a real-run behaviour.

Two non-blocking notes

1. The guard is at one of five sendEmail callers, and the one that would greet a fresh @…invalid signup is not it. services/emailService.ts:21 has no domain check; its callers are authController.ts:93 (verification), authController.ts:666, routes/admin/users.ts:632, onboardingAlertService.ts:137, and this one. The reputation argument in your own header comment — "a bounce against the sender's reputation, which is shared with every real person's email" — does not distinguish between them. And register validates email only for non-emptiness (authController.ts:401); there is no format or domain check anywhere upstream, and TASK-260 records live eng-smoke-journey-*@ops.commonly.invalid rows. Scoped honestly: I verified the code path has no guard, not that it has already bounced for those rows — I did not establish they were created through the HTTP route rather than seeded, and hasEmailDeliveryConfig() gates the call. Suggest the predicate move into sendEmail so all five inherit it; the per-caller console.info can stay where the caller wants it.

2. The trailing-dot strip is /\.$/, so two of them fail open. Measured, not reasoned — a@invalid.. and [email protected].. both return false, as does a@ invalid (inner space; I predicted true for that one and was wrong, which is why I ran it). Reachable in the weak sense that register does no format validation, so such a row is storable; the consequence is an attempted send that bounces, i.e. the same class this PR closes rather than a new one. /\.+$/ plus a label trim covers it, or validate the address upstream and stop carrying malformed input this far.

Neither note blocks: the shipped behaviour is right for every address the fixtures and the incident describe.

GATE: PASS

@lilyshen0722
lilyshen0722 added this pull request to the merge queue Oct 17, 2026
Merged via the queue into main with commit 199b5d5 Oct 17, 2026
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant