Signup abuse protection
Public signup and account flows on platform.lovely-home.co.uk are exposed without Cloudflare Access. Layer controls as follows.
Turnstile (bot check)
Signup, account OTP, and the contact form verify a Turnstile token when both keys are set on platform Pages (TURNSTILE_SITE_KEY, TURNSTILE_SECRET_KEY from Terraform turnstile_site_key / turnstile_secret_key).
The widget renders with data-appearance="interaction-only" (#1429): it takes no room on the page and only appears when Cloudflare needs the visitor to tick the box. Most visitors never see it.
Nothing about the request skips the check: not the Origin header, not a preview or localhost origin (#1168). A script can send any Origin it likes. Marketing previews and local runs that call a platform with real keys need a real challenge. Point them at the sandbox platform, which uses Cloudflare's always-pass test keys (see e2e/README.md).
Create keys
- Dashboard: Turnstile → Add widget → Managed → hostnames
lovely-home.co.ukandplatform.lovely-home.co.uk. - CLI:
node scripts/create-turnstile-widget.mjs(token needs Turnstile Edit on the account;platform_cf_api_tokenoften does not).
Add to terraform/environments/hub.tfvars (never commit):
turnstile_site_key = "0x4AAA..."
turnstile_secret_key = "0x4AAA..."For GitHub Actions platform applies:
gh secret set TURNSTILE_SITE_KEY
gh secret set TURNSTILE_SECRET_KEYPush Turnstile keys to platform Pages (see Minimal Terraform apply below — do not run a blind full terraform apply on a stale hub.tfvars).
Confirm: open signup — a Turnstile widget appears; GET /api/public/signup/status includes turnstileSiteKey.
Minimal Terraform apply (Turnstile + rate limits only)
A full platform apply also reconciles every sites { … } entry on *.lovely-home.co.uk, marketing Access, queues, and drift from old deprovisions. That is unrelated to Turnstile.
Before any apply:
- Align
terraform/environments/hub.tfvarssiteswithplatform/sites.yaml(runnode scripts/validate-local-hub-tfvars-sites.mjs). - If you are live, set
marketing_site_access_protected = falseunless you intend to OTP-gate the marketing site again. - Remove deprovisioned internal hubs (
sandbox,test,dev, …) fromsitesso Terraform does not recreate empty D1/Pages stacks.
Then apply only platform admin (Turnstile env vars + optional rate-limit ruleset):
cd terraform
terraform init -backend-config=environments/backend.hcl # if not already
terraform plan \
-var-file=environments/hub.tfvars \
-var=terraform_stack=platform \
-target=module.platform_admin[0]
terraform apply \
-var-file=environments/hub.tfvars \
-var=terraform_stack=platform \
-target=module.platform_admin[0]Review the targeted plan: expect Pages env var updates and cloudflare_ruleset.public_signup_rate_limit (if enabled). It should not recreate module.hub_site["sandbox"] etc. If the plan still lists hub sites, fix sites in tfvars first.
To clean state after intentional deprovisions (resources already gone in Cloudflare), remove stale modules from state (example):
terraform state rm 'module.hub_site["sandbox"]' # only when the site is gone and removed from tfvarsUse terraform state rm only when you understand what is being dropped from state — never on live demo / customer hubs you still use.
Edge rate limits (Terraform)
When public_signup_enabled = true, module platform_admin manages a zone http_ratelimit ruleset on lovely-home.co.uk.
Default (typical Cloudflare plan): one combined rule for signup, slug checks, account OTP, and contact — 25 requests / 10s / IP (~150/min total across those paths), 10s mitigation timeout.
On many zones, edge rate limiting is capped as follows (Terraform defaults match):
| Plan constraint | Default | Typical error if wrong |
|---|---|---|
Rules in http_ratelimit | 1 (combined rule) | 50001 — “4 out of 1” |
period (seconds) | 10 | “not entitled … period 60” |
mitigation_timeout (seconds) | 10 | “not entitled … mitigation timeout different from 10” |
Optional: public_signup_edge_rate_limit_per_endpoint = true in hub tfvars creates four rules with separate limits (only if your plan allows more than one rule in http_ratelimit):
| Traffic | Per-endpoint limit (10s window) |
|---|---|
POST /api/public/signup | 3 / 10s (~18/min) |
GET /api/public/signup/slug/* | 20 / 10s (~120/min) |
POST /api/public/account/otp | 4 / 10s (~24/min) |
POST /api/public/contact | 2 / 10s (~12/min) |
Per-endpoint app limits in D1 still apply regardless of edge mode.
Disable with public_signup_edge_rate_limit_enabled = false only if your Cloudflare plan cannot use rate limiting rules (not for token 403s — fix the token instead).
Terraform cloudflare_ruleset with phase = "http_ratelimit" requires Zone WAF Write (dashboard: Zone → WAF → Edit) on lovely-home.co.uk (CLOUDFLARE_ZONE_ID). Firewall Services Edit is not the same permission and returns 403 Authentication error on POST /zones/.../rulesets. Zone-only tokens must include that zone under Zone Resources; account-level Account Rulesets Edit only applies when the token also includes the account under Account Resources.
Before Platform admin Terraform, run bash scripts/verify-cloudflare-api-token.sh — it checks Zone WAF read access to the http_ratelimit entrypoint. If a ruleset already exists (plan allows one), it skips the create dry-run instead of failing with Cloudflare error 20217.
Queues already exist (409 on apply)
If targeted apply fails with Queue name 'lovely-home-hub-provision' is already taken, the queues live in Cloudflare but not in this Terraform state. Import queues, set manage_hub_queue_consumers = false in hub.tfvars (consumers cannot be imported — error 11004), then apply again:
export CLOUDFLARE_API_TOKEN="..."
cd terraform
bash ../scripts/import-platform-hub-queues.sh
terraform apply -var-file=environments/hub.tfvars -var=terraform_stack=platform '-target=module.platform_admin[0]'Turnstile keys only need Pages env vars — if you want to skip queues/rulesets for now, target Pages alone (after quoting for zsh):
terraform apply -var-file=environments/hub.tfvars -var=terraform_stack=platform \
'-target=module.platform_admin[0].cloudflare_pages_project.admin'If a ruleset already exists in the dashboard for the same phase, import it before apply:
terraform import 'module.platform_admin[0].cloudflare_ruleset.public_signup_rate_limit[0]' zone/<ZONE_ID>/<RULESET_ID>Application limits (D1)
See platform-billing.md — per-IP signup POST limit (5/hour), optional daily hard cap, slug reservations.
Taken names (#1570). A name is taken if it is on the site list or its billing row is trialing or active, so a home that signed up minutes ago is taken before the next platform deploy adds it to the list. A sign-up for a taken name gets only 409 SLUG_UNAVAILABLE and "already taken": never the other home's billing details.
Slug availability checks also use a separate app limit (40/hour/IP) in addition to the edge rule.
Operator knobs
- Platform admin → Sign-up limits — daily alert and optional hard cap.
PUBLIC_SIGNUP_ENABLED— emergency off for new signups (Terraformpublic_signup_enabled).
Launch checklist (public signup)
Turnstile and signup readiness are separate. Turnstile only adds a bot check; it does not configure Stripe. A broken signup flow after Turnstile is usually Stripe mode vs runtime secrets, not the widget.
Before launch (and after any platform Terraform apply or Pages env edit):
bash scripts/verify-platform-stripe-env.sh(or run the Signup launch check workflow, which runs it in Actions with the Cloudflare secrets) — must end with “Public signup is enabled at runtime.”
The Cloudflare API can showsecret_textas “set” while the worker still sees an emptySTRIPE_SECRET_KEY_LIVE. The script’s second step callsGET /api/public/signup/status(readiness.blockers) — that is authoritative.Platform admin → Monitoring → Marketing & signup — signup enabled (not merely HTTP 200).
readiness.enabled: trueonhttps://platform.lovely-home.co.uk/api/public/signup/status.If
stripeMode: liveandruntimeHasLiveSecret: false: re-pasteSTRIPE_SECRET_KEY_LIVEandSTRIPE_WEBHOOK_SECRET_LIVEin Pages Production, remove duplicate env var names, then Retry deployment on productionmain.Manual smoke: complete Turnstile on signup and create a Free test hub (or Stripe test checkout for Plus).
ICO data protection fee paid (done 2 November 2026: registration ZC290332, expires 1 November 2027, renews by direct debit). Lovely Home stores customers' names, emails and billing records, so the controller must register with the Information Commissioner's Office and pay the annual fee (tier 1 for a micro business) before public signup takes real people's data. Register at ico.org.uk/fee, then add the registration number to the Who we are section of privacy.html and diary the yearly renewal.
Open signup: Platform admin → Maintenance → switch maintenance off. That's what hides the signup form;
lovely-home.co.ukitself is already public (its Access app has a bypass-for-everyone rule). The switch is stored inplatform_settings(D1) and overrides the TerraformMARKETING_MAINTENANCE_MODEfallback, so later applies can't re-enable it. Check/signupshows the form in a private window, re-checksignup/status, and do one Free signup.Optional tidy-up after launch: set the repo variable
MARKETING_SITE_PUBLICtotrueand run Platform admin Terraform. That removes the now-unused marketing Access gate (module.marketing_site[0]); the workflow allows that destroy only while the variable istrue. Afterwards Platform admin's marketing-site access list shows a Cloudflare error, which is expected. Set the variable back tofalseto restore the gate (#1039).
Why signup “worked before Turnstile”: often you were on Stripe test mode, or live secrets were present at runtime and later a Pages/Terraform update left encrypted-but-empty live secret slots. Turnstile was added in the same window; it did not remove Stripe keys.