feat(guard): check every API email, pause any team for clear phishing or scams
What
The Guard now checks every email sent through the API, not just campaigns, and can pause any team for clear phishing or a scam.
Why: Motionstack (#373, a customer for a year) sent about 900 phishing emails in October through one leaked API key: "E-ZPass" toll invoices and "American Express" account warnings from a cleaning company's domain. Nothing caught it.
GET /api/admin/guard/emails?cursor=: a feed of new non-campaign emails across all teams, oldest first. CursorcreatedAt|id, narrowed by date first so it always usesEmail_createdAt_idx(checked with EXPLAIN on prod). Recipients are reduced to domains.- Pausing older teams:
recordTeamActionPAUSE acceptsabuse: "phishing" | "scam"plusemailIds, which must all be that team's emails. Without them, the old rule holds: only teams in their first 14 days. - On an abuse pause, the team is emailed with a fixed template. It quotes up to 3 of the evidence subjects (single line, links stripped), says their API key has probably leaked, and how to fix it. The AI's wording never goes to the customer.
- Every Guard pause posts to Discord from useSend itself, with the reason and how long they've been a customer.
- Bounces to addresses on our SES suppression list (
OnAccountSuppressionList) no longer count as hard bounces. SES never tried to deliver them, and AWS doesn't count them toward the bounce rate. This was behind today's false "would pause Motionstack, 31% bounces" alert: one address bounced 6 times. Also fixes a stray tab in that type literal.
The Guard side (usesend/guard): Jev (TypeSafe's decision model, about $0.03 per 1k) checks every email; GPT-6 Luna double-checks only what Jev flags and pauses for clear phishing or scams. Each agent task is scoped to its own team, so customer content can't redirect it.
Migration
None.
Verification
pnpm test:web: 560 passed. New tests cover the feed cursor (ties, empty start), abuse pauses (evidence, another team's emails, the customer email, Discord), and suppressed bounces.- Production build passes.
- Dry run on the real October emails: Jev scored the phishing 0.97 and a normal email 0.11. Luna then chose a pause, as phishing, citing the 3 email ids, and cleared the normal email. Nothing in production changed.
- Astra review: 4 blocking issues on the first pass (empty cursor, a poison email blocking the feed, losing flagged reviews on restart, cross-team prompt injection) and 1 on the second (unbounded retries). All fixed.
Ask Polylane for an impact assessment of this pull request:
Summary by cubic
The Guard now checks every email sent through the API, not just campaigns, and can pause any team for a clear break of the terms, closing the gap that let a leaked API key send phishing emails for a month.
- Adds
GET /api/admin/guard/emailsto feed the Guard new non-campaign emails, oldest first, with recipients reduced to domains. The cursor rejects impossible dates, and the feed skips rows newer than 30 seconds old so nothing uncommitted appears behind it. - PAUSE actions now accept
abuseandemailIdsfor teams past their first 14 days; the emails must belong to that team. abusecovers phishing, scams, cold outreach, gambling, adult content, money schemes, and pharma.- The team gets a fixed email naming the rule, quoting up to 3 cleaned subjects; only phishing or scams suggest a leaked API key. The email never throws, so a member lookup failure just logs and skips. Every Guard pause posts to Discord.
- Bounces to addresses on the SES suppression list (
OnAccountSuppressionList) no longer count as hard bounces, matching AWS behavior, and each one is counted at most once.
Summary by CodeRabbit
- New Features
- Guard administrators can review recent non-campaign emails in paginated results, including recipient domains and team status. Results default to the last 10 minutes.
- Older teams can be paused for phishing or scams when supported by emails linked to that team. Successful pauses trigger a Discord notice, and abuse-related pauses include sanitized evidence subjects and category-specific guidance in an email. Phishing and scam notices include steps for handling a potentially leaked API key.
- Bug Fixes
- Emails suppressed by the account-level bounce list no longer count toward hard-bounce metrics or sending-health checks, while remaining visible in dashboard bounce counts.