Skip to content

Harden sending, add mail stats, open the MCP to all staff - #1

Merged
frahlg merged 1 commit into
mainfrom
1-hardening-stats-members
Nov 3, 2026
Merged

frahlg merged 1 commit into
mainfrom
1-hardening-stats-members

Conversation

@frahlg

@frahlg frahlg commented Nov 3, 2026

Copy link
Copy Markdown
Member

Gets Utskick ready for the first live send and for use by everyone at the company.

Sending

  • Records each recipient as soon as SES answers, so a database error mid-batch cannot mail anyone twice.
  • Stops a send, and puts its rows back, when SES refuses a whole batch the same way (sandbox, unverified sender, daily quota). Before, the whole list failed.
  • Refuses a live send without an *|UNSUB|* link. A dry run warns about leftover merge tags and about mail Gmail would clip.
  • A reminder skips everyone an earlier reminder reached.

Bounces and complaints

  • Suppresses only the address that got the mail.
  • A complaint suppresses even after the reader unsubscribed.
  • A soft bounce suppresses only for a full mailbox seen twice in 30 days.

Stats

  • Opens and clicks by people are counted apart from those by link scanners and Apple's privacy proxy. Only a flag is kept, no IP address or user agent.
  • Rates per send, 30-day sending health against the SES limits, list growth per month. On the dashboard and as MCP tools.

Company-wide MCP

  • members in the config: everyone at the listed domains may connect an assistant, draft, test to themselves, read stats and ask for sends. Admins still approve each send.
  • Lists a colleague makes through an assistant: addresses go in but never come back out. Only the owner or an admin can change a list, replies go to the owner, and there is no public web version.
  • Admins get approval requests by mail. A link stays open 24 hours. Each person may ask for at most 10 sends an hour.
  • A token stops working when its owner is no longer a member.

Before deploying

  1. Apply migrations/0005_stats_lists.sql.
  2. Confirm the sender addresses in config/sourceful.json.
  3. Go through step 7 of docs/setup.md (SNS topic policy, the SES simulator test).
  4. Add both member domains to the Cloudflare Access policy.

Tests

206 pass. npm run typecheck and cf build pass.

🤖 Generated with Claude Code

Sending
- Record each recipient as soon as SES answers, so a database error mid-batch cannot mail anyone twice.
- Stop a send, and put its rows back, when SES refuses a whole batch the same way (sandbox, unverified sender, daily quota) instead of failing the list.
- Refuse a live send without an *|UNSUB|* link; warn about leftover merge tags and mail Gmail would clip.
- A reminder (resend) skips everyone an earlier reminder reached.

Bounces and complaints
- Suppress only the address that got the mail, never other addresses a report names.
- A complaint suppresses even after the reader unsubscribed.
- A soft bounce suppresses only for a full mailbox seen twice in 30 days (events.detail).

Stats
- Split opens and clicks made by people from those made by link scanners and Apple's privacy proxy (events.machine; no IP or user agent kept).
- Rates per send, 30-day sending health against SES limits, list growth per month, on the dashboard and as MCP tools.

Company-wide MCP
- config.members: everyone at the listed domains may connect an assistant, draft, test to themselves, read stats and ask for sends. Admins still approve each send.
- Lists a colleague makes through an assistant (list_create, list_add, list_remove, list_delete): addresses go in but never come back out, only the owner or an admin changes a list, replies go to the owner, no public web version.
- Approval requests are mailed to admins and stay open 24 hours; at most 10 requests an hour per person.
- Tokens stop working when their owner is no longer a member.

Schema: migrations/0005_stats_lists.sql. Apply it before deploying.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@frahlg
frahlg merged commit 4d2e3e6 into main Nov 3, 2026
1 check passed
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 3, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-03T08:18:04.901466Z 2d06b4c PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@frahlg
frahlg deleted the 1-hardening-stats-members branch November 3, 2026 08:14

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 2d06b4ce1f

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/app.ts
if (!send) return notFound(env.CONFIG);
.bind(key).first<{ html: string; list: string; fname_fallback: string }>();
// A mailing to people a colleague named (an event's guests) is theirs, not the public's.
if (!send || env.CONFIG.lists[send.list]?.adhoc) return notFound(env.CONFIG);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Fail closed when an archive's list metadata is unavailable

If the lists query fails, withLists() catches the error and returns the config-only environment. An ad hoc list is then absent from env.CONFIG.lists, so this condition allows its private mailing to be served publicly, with a public cache header. I reproduced this by making the lists table unreadable after creating an ad hoc send: its archive changed from 404 to 200 and exposed the message body. Require a positively identified public newsletter list, or propagate metadata-loading failures, rather than treating missing metadata as permission to publish.

Useful? React with 👍 / 👎.

Comment thread src/render.ts

// A mail to a list needs a link a reader can use to leave it, not just the tag in a comment or in text.
export function hasUnsubscribeLink(html: string): boolean {
return /\shref\s*=\s*["']?\*\|UNSUB\|\*/i.test(stripComments(html));

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Match unsubscribe tags with the renderer's case sensitivity

For HTML containing <a href="*|unsub|*">Unsubscribe</a>, this case-insensitive check returns true, but render() only replaces the exact uppercase *|UNSUB|* tag. Consequently, createSend() and requestSend() accept a live mailing whose body unsubscribe link does not work; mailWarnings() also returns no warning for this example. Keep tag validation consistent with rendering so this input is either rejected or correctly expanded.

Useful? React with 👍 / 👎.

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