TempMail-CFW handles untrusted email content and issues short-lived access tokens.
Primary risks: unauthorized inbox access, XSS via HTML email, token leakage, brute-force on admin login, abuse of creation endpoints, data left after expiration, and accidental exposure of R2 objects.
- Public / anonymous — health, username check, inbox creation (rate-limited)
- Inbox owner — Bearer token scoped to one inbox
- Administrator — server-side session after password login
These boundaries must not be mixed. An inbox token never grants admin rights. An admin session is separate from inbox tokens.
- Cryptographically random, sufficient length
- Returned once at creation
- Only a secure hash stored (SHA-256 or stronger)
- Compared in constant time
- Never logged, never placed in URLs
- Stored only as Cloudflare Secret (
PANEL_PASSWORDor successor) - Not hard-coded
- Verified with a password-hashing approach appropriate for Workers (not fast unsalted SHA-256 for passwords)
- No public registration; single-admin model initially
- Unpredictable session identifiers
- Prefer storing a hash of the session secret
- Cookie:
HttpOnly,Secure,SameSite=Strict(orLaxonly if strictly required),__Host-prefix when possible - Server-side expiration and logout invalidation
- CSRF protection for cookie-authenticated state-changing requests
- Parse with size bounds; reject oversized streams early
- HTML is sanitized before any privileged use
- Preview in sandboxed iframe (
sandboxwithout unnecessary allow-* flags) - Disable scripts, forms, and dangerous URL schemes
- Remote images controlled or blocked by default
- Filenames and MIME types from senders are not trusted for security decisions
- Stored in private R2
- Random object keys
- Downloads only through authenticated handlers
- Per-file and per-inbox size quotas
- Content-Type served carefully; prefer download disposition for untrusted types
- Parameterized queries / bound statements for D1
- Strict validation of usernames (
[a-zA-Z0-9_-], length limits) - Unique constraints prevent silent inbox takeover
- Duplicate message detection (Message-ID) where practical
- Login rate limiting by IP (KV)
- Creation / read rate limits as configured
- Inbox and message quotas
- Early reject of invalid recipients
- Never log tokens, passwords, full email bodies, or raw MIME by default
- Request IDs for correlation
- Secrets only via Cloudflare Secrets / encrypted env — never committed
- Explicit allowlist for browser origins that need credentialed access
- Default deny for unexpected origins on credentialed routes
- Expired inboxes and their R2 objects must be removed
- Failed cleanup must be retryable (idempotent jobs)
- See
docs/DATA-RETENTION.md
- Public R2 buckets or permanent public attachment URLs
- Outbound open relay
- Storing plaintext inbox tokens
- Trusting client-supplied HTML without sanitization
- Shipping with a default known admin password
Security-sensitive changes (auth, token handling, HTML sanitization, R2 access, CORS, rate limits) require focused review and tests.
Ponytail-style review should examine callers outside the diff when shared security helpers change.