Skip to content

Security model

  • One gate to the data. Only cemco-api reads or writes the CRM database and the document bucket. The web app, the MCP server and the agents all go through its operations.
  • The server enforces the rules. Roles, customer scoping and the valid-order gate run in the dispatcher and the handlers, never only in the UI.
  • Everything is audited. Every write appends to audit_log with the actor, operation, entity and detail.
  • Staff sign in through Google (limited to the staff domain) or email codes; customers with a password or magic link after an invite; scripts with API keys; MCP clients with OAuth 2.1. See Authentication.
  • Roles are admin, editor, viewer and customer. Each operation lists the roles that may run it; the dispatcher refuses anyone else with forbidden.
  • System operations (document resolve and finalize, calendar feed rendering, invite lookup and accept, the daily run) can be called only by the platform itself, never over public HTTP or MCP.
  • A customer actor always carries its accountId. The dispatcher overwrites any accountId in the input with it.
  • Handlers for portal operations filter by the account and call assertAccountAccess, which answers not_found (not forbidden) for another account’s record, so ids cannot be probed.
  • Customers cannot use the MCP server or the agents.
  • Documents are shown to customers only when marked customer-visible.
  • Tests run every portal operation as a second customer to prove isolation.
  • R2 is private. Documents open through links signed with DOCUMENT_SIGNING_SECRET that expire after 15 minutes.
  • Uploads are limited in size, and their type is recorded.
  • The app is same-origin with its API (app.cemco.app/api), so session cookies need no cross-site allowances.
  • Strict Content-Security-Policy with hashed inline scripts and no 'unsafe-inline' for scripts, frame-ancestors 'none', HSTS, nosniff, a restrictive Permissions-Policy. See Web Worker and hosts.
  • The Worker sets x-forwarded-host itself, dropping any value from the browser.

The development sign-in exists only when ENVIRONMENT is exactly development, which is set only in the local workers/auth/.dev.vars. Deployed configurations say preview or production, and a test checks that the routes return 404 and the header is ignored outside development.

No secret is in the repository. Each Worker lists its settings in .dev.vars.example; production values are set with wrangler secret put. See Deploying.

Programs run by the MCP execute tool run in a separate isolate created by the Worker Loader, with no network access and no bindings except the crm object, which calls the API as the signed-in user.

  • Public token routes (portal invite lookup and accept, the iCal feed) have no rate limiting yet.