Cloudflare Access must protect the complete production hostname. The Worker independently validates
the Cf-Access-Jwt-Assertion header:
- Load signing keys from
https://<team>.cloudflareaccess.com/cdn-cgi/access/certs. - Verify RS256 signature, issuer, audience and expiration with
jose. - Require non-empty subject and email claims.
- Normalize email and resolve a provisioned D1 member.
- Bind the Access subject once. A different later subject is rejected until an Admin explicitly resets the binding.
An unprovisioned verified identity is denied. A bootstrap address is admitted only after that exact address presents a valid Access JWT and only while no active Admin exists. Bootstrap completion is persisted and does not continually rewrite roles.
After initial setup, set BOOTSTRAP_ADMIN_EMAILS to an empty string and redeploy. Keep the field:
the runtime schema requires it. Bootstrap completion is persisted; this setting is not an ongoing
administrator recovery mechanism.
src/domain/permissions/policy.ts is the central role/action matrix. API routes and entry services
enforce it; React visibility is convenience only. Members are forced to their own time at the query
layer and never receive monetary fields. Managers receive team and financial report access but
cannot modify Admin/security settings. Admins can reset identity bindings and override entry locks
with a mandatory audit reason.
- Same-origin deployment avoids CORS.
- All state-changing routes require an exact
Origin, acceptableSec-Fetch-Site, and an identity-bound HMAC CSRF token. - Content Security Policy and defensive headers are defined in
public/_headers. - API errors use structured JSON and do not expose SQL or token internals.
- CSV cells are always quoted and values starting with
=,+,-or@are prefixed to prevent formula execution.
- D1 foreign keys, check constraints and a partial unique index protect the schema.
- User data is passed through D1 bindings. LIKE input is escaped.
- IDs use
crypto.randomUUID(). - Optimistic versions reject stale edits.
- Audit rows are protected by database triggers against update and deletion.
- Timers and idempotency records are committed in D1 batches.
- No password, Access JWT, authentication cookie or production secret is stored in the application database.
- Create a random
CSRF_SECRETof at least 24 characters with Wrangler secrets. - Restrict the Access application to your organization’s intended identity policy.
- Set short, appropriate Access session duration and require the company identity provider’s MFA.
- Review audit events and Worker logs; avoid logging request bodies or Access assertions.
- Back up D1 before destructive operational changes and keep Cloudflare D1 Time Travel available.