ciso.diy
Build Your Own Email Security Platform on Cloudflare, with Claude Code preview
Security Program Pillars email securityCloudflareClaude CodeDMARC

Build Your Own Email Security Platform on Cloudflare, with Claude Code

A DIY guide to a guarded inbound path, a lane console and an outbound relay with DLP that replaces per-app transactional-mail keys, built on Cloudflare with Claude Code. Copy-paste prompts and a verify list for every step, a compliance mapping, and an honest cost comparison.

What this actually gives you

  • Two Workers and a console: an inbound gate that records before it blocks, an outbound relay that holds the only send binding, and a read-mostly lane console behind Cloudflare Access.
  • Every build step has a copy-paste Claude Code prompt and a verify list, including the 128-byte executable named invoice.pdf that proves attachments are checked by content, not by name.
  • The gate fails open for mail and the relay fails closed for attachments; databases hold metadata and hashes, never bodies or file names.
  • Controls are mapped to MITRE ATT&CK and to SOC 2 and ISO/IEC 27001 control areas as evidence, not certification, with a cost comparison whose assumptions are stated.

Build the email security you cannot afford to buy, and keep it. A guarded inbound path, a lane console, and an outbound relay with data-loss prevention, built on Cloudflare with Claude Code as your pair engineer. The guide describes a production reference build and generalises it for your own domains: every step has a copy-paste prompt, and a verify list that proves it worked.

Who it is for. A security lead, IT generalist or founder who owns several domains and has no mail-security budget; an MSP or fractional CISO who wants a repeatable, auditable email control for small clients; a developer with a dozen applications each holding its own sending key. It is not a mailbox replacement, and it says so before you buy.

What you end up with. MX to Email Routing to a gate Worker, which reads sender authentication from the one trusted header, scores impersonation, look-alike domains, hidden text, injection phrasing and risky attachments, stores a private raw copy and a metadata-only audit row, and delivers, quarantines, or rejects only certainties. A lane console behind Cloudflare Access with a one-click Flag for tuning. And an outbound relay Worker: applications call it over a service binding with no API key, every message passes a per-application sender allow-list and DLP, and every decision is logged and alerted.

Built in shadow mode first. The gate records verdicts for a week before it blocks anything, so your first data is review material rather than a lost-mail incident. If the gate fails, mail still reaches a human; if an attachment check fails, the file does not leave.

Ten build steps, each with prompts. Inbound route and shadow mode. The gate: SPF, DKIM and DMARC from the trusted Authentication-Results header, impersonation, look-alikes, injection, attachment type-sniffing by magic bytes and hash reputation. Lanes and the console. A classifier that learns from labels, in two explainable steps rather than a black box. The outbound relay with DLP for secrets, cards, bank and government ids, bulk personal data, internal hosts and echoed payloads, an attachment allowlist, and caps. Migrating applications off a third-party sender, with a per-app recipe, test sends, and key and DNS cleanup. Auto-acknowledgement behind ten gates. A silent-sender and failed-send health alert. DMARC, SPF and report records. Then enforcement.

A compliance mapping chapter. The controls mapped to MITRE ATT&CK (phishing, spoofing and impersonation, exfiltration over email) and to SOC 2 and ISO/IEC 27001 control areas, framed as evidence you can produce. It is mapping, not certification, and says so.

A cost chapter with its assumptions shown. The Cloudflare components at small-business volume against per-seat suites and a privacy mailbox provider, using public list prices where verifiable and labelled estimates elsewhere, plus why the comparison is not like for like and when a hybrid is the better answer.

Honest limits. No IMAP or mobile client. Replies need a console feature you build. Bulk mail is separate. MTA-STS and TLS-RPT are not built here. No sandbox detonation. DLP covers the relay only. Email Sending was in beta at the time of writing. Then the operating playbook: daily checks, a weekly tuning review, and a kill switch for every layer.

Everything is generalised: no real domains, no secrets, example.com throughout. It sits beside Build Your Own Security Department on Cloudflare and Claude Code, the platform guide underneath it, and Pillar 04, the AI-SOC Operating System, which consumes the alerts.

What's included

  • PDF — fully editable
  • Instant download after purchase
  • Free updates — re-download when we release new versions
  • Practitioner License: unlimited client use (vCISO / MSP)

Choose your license:

  • Secure checkout via Stripe
  • All major cards accepted
  • 30-day satisfaction guarantee
Version 1.0
Last updated 2026-11-22
Pages 28