Security model
Principles
Section titled “Principles”- One gate to the data. Only
cemco-apireads 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_logwith the actor, operation, entity and detail.
Identity and roles
Section titled “Identity and roles”- 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.
Customer isolation
Section titled “Customer isolation”- A customer actor always carries its
accountId. The dispatcher overwrites anyaccountIdin the input with it. - Handlers for portal operations filter by the account and call
assertAccountAccess, which answersnot_found(notforbidden) 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.
Documents
Section titled “Documents”- R2 is private. Documents open through links signed with
DOCUMENT_SIGNING_SECRETthat expire after 15 minutes. - Uploads are limited in size, and their type is recorded.
The browser
Section titled “The browser”- 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-hostitself, dropping any value from the browser.
Development sign-in
Section titled “Development sign-in”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.
Secrets
Section titled “Secrets”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.
Codemode
Section titled “Codemode”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.
Known gaps
Section titled “Known gaps”- Public token routes (portal invite lookup and accept, the iCal feed) have no rate limiting yet.