02 · Sign-in & security
Signing in to the plan portal
There are two ways in, and only one is active at a time.
1. Cloudflare Access (preferred, used when ACCESS_TEAM_DOMAIN and ACCESS_AUD are both set)
- Cloudflare Zero Trust handles login at the edge (one-time PIN by email, or Google).
- On every gated request the Worker checks the signed
Cf-Access-Jwt-Assertiontoken itself: RS256 signature against the team’s/cdn-cgi/access/certskeys, issuer, audience and expiry. ACCESS_AUDcan hold several audience tags, comma separated, ifplan.and the previews are separate Access apps.ACCESS_ALLOWED_EMAILS(optional) adds an extra allowlist on top of the Access policy.- The password routes (
/api/auth/init,login,change-password) answer 410 Gone, and the login screen shows a Continue to sign in button instead of a password box. - Each partner is known by their Access email, which is how chats label who wrote what.
- Rolling back: delete either variable and the password login comes back.
2. Password (fallback)
- One shared password for the couple. Stored only as a hash: PBKDF2-SHA256, 100,000 iterations, random salt (
pbkdf2$<iters>$<salt>$<hash>insettings.password_hash). - First run: the login page shows “Welcome — set up your planner” with “Set a password (min 8 characters)” and “Create password & continue”. A temporary password can be set during bootstrap; while it is in use the Dashboard and Setup show a “You’re using the temporary sign-in password” warning until it is changed.
- Login lockout: 5 wrong passwords lock login for 5 minutes.
- Session: cookie
wp_session,HttpOnly; Secure; SameSite=Lax; Path=/, set for.<domain>, lasting 30 days. - Change password on Setup: current password, new (min 8), confirm. Changing it resets the device whitelist (old sessions stop working).
The preview gate (v1–v5)
Preview hosts check the session (Access token, or the password cookie) before serving anything. Without one the visitor gets the static “preview ended” page: no app bundle, no API calls, no data. Preview-token links (?pt=, minted per host with an expiry) could give limited access, but they stop working on Access-protected hosts because Access blocks the visitor before the Worker sees the token.
Guest-side protections
- Access-code guess limit: 5 wrong codes from one visitor within 15 minutes time that visitor out of every code endpoint (site unlock, RSVP access, RSVP submit, QR/code lookup) for 15 minutes. They get a 429 with “Too many incorrect codes. Please wait N minutes and try again.”
- It is per visitor: a salted SHA-256 of the IP, kept in a short-lived
settingsrow (code_guess:<hash>), so one person guessing never locks out other guests. - A correct code does not reset the count.
CODE_GUESS_EXEMPT_IPS(Worker secret, comma separated) lists IPs that are never counted, for the couple’s own testing.
- It is per visitor: a salted SHA-256 of the IP, kept in a short-lived
- RSVP submit only accepts the values the form sends (status
confirmed/declined), caps every free-text field, and is written as one D1 batch, so it saves completely or not at all. It only updates guests already in that household. - The guest site API serves published content only. Drafts need the couple’s session.
- Guest notes in the plan are private and never sent to the guest.
Other locks
| Thing | How it’s protected |
|---|---|
MCP connector /mcp/<token> |
A per-person link. Only its SHA-256 is stored. Revocable instantly. See notebook 26. |
| Family portal | Cloudflare Access and the D1 family list, checked on every request. Fails closed. See notebook 09. |
| Invoice links | Only http(s) URLs are stored or rendered, so javascript: / data: links can’t become stored XSS. |
| Media uploads | JPEG/PNG/WEBP/GIF only, ≤5 MB, checked by file signature (magic bytes), not just the name. |
| Email assistant | Acts only on allow-listed senders; can never choose recipients. Optional strict sender check (DKIM/DMARC). See notebook 22. |
| Push notifications | Only sent to well-known push services (Google, Apple, Mozilla, Microsoft); end-to-end encrypted. |
Secrets and logs
- No credentials and no personal data in the repo. Workers Builds generates its own deploy token.
- Secrets (Anthropic key, mailbox password, Access and sync settings) are Worker secrets.
keep_vars = truestops deploys wiping dashboard variables. process.envis deliberately kept empty (nodejs_compat_do_not_populate_process_env) so no library, including the Anthropic SDK, can read secrets or be steered by strayANTHROPIC_*variables.- The backup export leaves out
auth_secret,password_hash, API keys,preview_tokens,mcp_tokens,push_vapidand the code-guess rows. - Logs:
log-safe.jsmasks email addresses (m***@e***.com); never log names, message bodies, tokens or secrets. MCP requests write no console lines at all.