Security

What the kit enforces, and how we test it

Every copy starts with organisation isolation, scoped keys and server-side role checks. The kit is audited by AI agents that try to break those rules and check each other’s work, and what they find is fixed before anything about it is published.

Posture

What every copy enforces

87 properties of the kit, grouped by where they apply. Each is stated in the kit’s own documentation, and each links to the page that explains how it works.

Sign-in and sessions

  • A session is a database row with a 30-day sliding expiry, held in a __Host-session cookie that is HttpOnly, SameSite=Lax and Secure outside development. Authentication
  • A blocked person is refused by every sign-in method, by the session check on each request and on their API keys. Plugins
  • Magic links are 256-bit, single-use tokens that expire after 15 minutes and are stored only as SHA-256 hashes. Authentication
  • Opening a magic link spends nothing. Only the confirm button, a same-origin POST, signs in, so a mail scanner that fetches every link cannot use one up. Authentication
  • After five sign-in emails to one mailbox in 15 minutes, the request gets the same answer but nothing is minted or sent. Plus-tags, and dots in a Gmail address, count as the same mailbox. Authentication
  • In production a magic-link URL is never written to the logs, even with no mail provider configured. Authentication
  • Google, Microsoft and any OIDC issuer use the authorization-code flow with PKCE. The flow cookie is a __Host- cookie carrying the state, the PKCE verifier and a nonce. Authentication
  • An OIDC issuer’s id_token is verified against its published keys (issuer, audience, expiry, nonce), and its discovery document is refused unless the issuer matches exactly. Authentication
  • Accounts link by verified email only. An address the provider marks unverified cannot match or admit an account, and an OIDC issuer that does not assert verification is treated as unverified unless the operator opts that issuer in. Authentication
  • A Microsoft work address is trusted only when its domain is one of the signing-in directory’s verified domains. Authentication
  • Login routes have a KV sliding-window rate limit. Cookie requests pass a CSRF check against an origin allow-list. Authentication
  • Dev login answers 404 in production. Authentication
  • CLI login accepts only a loopback redirect, creates nothing until the person confirms in the browser, and the CLI ignores a callback without its random per-login state. The CLI
  • When a plugin says a domain requires single sign-on, every other sign-in method refuses that domain’s addresses, and a policy check that fails refuses rather than lets them through. Only the operator’s bootstrap admins are exempt. Authentication
  • Identity webhooks are verified by signature over the raw body, with five minutes’ tolerance, and an event older than the row it would change is skipped. Authentication

Organisations and tenancy

  • The organisation comes from the signed-in session or key, never from the request. Background work takes it from a payload the server wrote and re-reads rows with it. Threat model
  • Every domain query filters by the organisation. A test fails any function that queries a tenant table without naming one, and each exception it allows carries a reason. Database
  • Every tenant table, a plugin’s included, carries a row-level security policy. A coverage test fails a tenant table without one, and a table without a tenant column unless its exclusion is listed with a reason. Database
  • A restricted document’s visibility is a SQL predicate added to the organisation filter, never put in its place. An empty grant list means owners and admins only, never everyone. Tenancy and access
  • A row hidden from someone answers the same 404 as a row that does not exist. Tenancy and access
  • Single and multi mode share one schema. In single mode every multi-organisation route answers 404. Tenancy and access
  • New sign-ups are invite-only by default. Uninvited people wait on a pending page, and someone whose access request is pending or rejected cannot create an organisation. Tenancy and access
  • A suspended organisation is refused on every path in: cookie, API key, websocket and the identity seam. Its sockets close, new agent runs are refused whoever asks, queued and waiting runs are cancelled, and a running one stops at its next cancellation check. Tenancy and access
  • Plugins are told when an organisation is suspended or reactivated, so one that publishes outside the sign-in check can stop serving it. Plugins
  • One person may own at most ten organisations by default, counted under a lock, on every path that grants ownership: creating one, a promotion and an accepted owner invitation. Tenancy and access
  • Only an owner-level person may issue an owner invitation. An invitation is accepted only while its issuer could still issue it, and a role change or removal ends the invitations the person could no longer send. Tenancy and access
  • Invitation email is capped: a five-minute resend cooldown, and daily limits per person and per organisation. Tenancy and access
  • Deleting an organisation removes its database rows by cascade, then a job removes its stored files and runs each plugin’s clean-up. Tenancy and access
  • Realtime sockets check the Origin, and removing a member, signing out, blocking someone or suspending an organisation closes the affected sockets. Events carry ids, and the page re-reads the data itself. Background work and realtime

API keys and the CLI

  • Keys are stored hashed, expire and can be revoked. Authentication
  • A key belongs to one organisation and acts with its creator’s role, and the role check still applies on top. Authentication
  • Scopes are checked on every request: a read key may only GET, HEAD and OPTIONS, and an unknown scope is refused. Authentication
  • A key cannot reach the admin area, which accepts a session cookie only. The CLI
  • A key cannot list or act in its creator’s other organisations, invitations or access requests. Beyond its organisation it reaches only its creator’s own profile. Authentication
  • A key stops working in an organisation its creator no longer belongs to. Plugins
  • The CLI keeps its key in a file only its user can read, and never prints a full key. The CLI
  • The CLI drops terminal control characters from server text before printing it. The CLI

Roles and permissions

  • Owner, admin, member and support are a CASL permission matrix checked on the server. “Your own row” is a query predicate, never a CASL condition. Tenancy and access
  • Deleting an organisation and changing an owner need an explicit owner check, not a general manage permission. Tenancy and access
  • The admin area is the only cross-organisation surface, behind a global-admin check. Tenancy and access
  • Support enters an organisation as a real support membership its people can see. When the global-admin role goes, every support membership goes in the same transaction. Tenancy and access
  • Memberships an identity provider manages are read-only in the app, and managed tenancy never grants owner or support. Tenancy and access
  • Feature flags are configuration, never permissions, so a global admin’s full access does not switch one on. A disabled feature answers 404, and the release list is fail-closed. Feature flags

Data, secrets and files

  • Tenant AI keys, OAuth tokens and plugin credentials are encrypted with AES-GCM under the deployment’s key. The AI layer
  • A stored credential is never returned or logged: the API answers whether one is set. Errors have secrets redacted. The AI layer
  • A stored AI key stays with the provider and base URL it was entered for. Changing either needs the key again. The AI layer
  • Files are stored under the organisation’s own prefix, and another organisation’s file answers 404. Email and file storage
  • File bytes stream through the Worker with no presigned URLs, and the browser can only name a file by its database row. Email and file storage
  • Uploads are checked for type and size per kind of upload. Email and file storage
  • Only allowlisted file types display in the browser; everything else downloads. Email and file storage
  • Request bodies are capped at 1 MB before any parsing. Upload paths allow up to 10 MB, and each upload route sets its own tighter limit. A plugin can raise one exact upload path to at most 50 MiB. The API shell

AI and agents

  • One resolver is the only place model credentials are decrypted, and they never leave the server. The AI layer
  • Tools run with the access of the person asking, read when the tool runs. The model never chooses an organisation. Threat model
  • The server owns the chat transcript. The client sends only the new message, and tools sent by the client are refused. The AI layer
  • A tool that needs approval runs only in an agent run, never in chat, and an approval runs exactly the call the person was shown: that tool, those arguments or their edit, once. The AI layer
  • A tool can be refused by rule before it runs, and the model is told why. The AI layer
  • A tool that fetches the web reads only addresses the person wrote or its own search returned, so text in a page, document or email cannot point it elsewhere. Plugins
  • Model output renders as Markdown with raw HTML off and links opened with noopener. Images show as links, so a model or document cannot make the browser fetch anything. The AI layer
  • Run details go to the people who may see that run, never over the organisation-wide socket. The AI layer
  • Thumbs feedback is accepted only on an answer the person can read. Another member’s thread is a 404, for admins too. The AI layer
  • Agent runs can be capped by tokens and cost per run, by a daily cost per organisation and by the number active at once. Every model call in a run is metered as it returns. The AI layer
  • While a cost cap applies to a model the deployment pays for, a call to a model with no known price is refused before it is made. The AI layer
  • Traces record prompts and completions only when the operator turns that on. Only admins can read traces, and they are kept 14 days by default. The AI layer

The web surface

  • Every return path after sign-in passes one rule: no control characters or backslashes, then same-origin only. Authentication
  • Security headers are set early, so error responses carry them too. Framing is denied unless a route has proved the file is a PDF, and then only by the same origin. Email and file storage
  • CORS, CSRF and the websocket share one origin allow-list derived from the app’s URL. The API shell
  • Sign-in is checked per mount, so the public surface is a short list. An unknown API path answers a JSON 404, never the app’s HTML. The API shell
  • A plugin’s public site runs on its own hosts under a strict Content Security Policy: no script, frame, connection or form target unless declared, and inline script refused. Plugins
  • On a public site’s host the app’s API, sign-in and websocket routes cannot be reached, the host comes from the request URL rather than a forwarded header, and a cached page is fetched without cookies or authorisation. Plugins

Plugins

  • A plugin reaches the kit only through declared entries and the context it is handed. The plugin check refuses an import past them. Plugins
  • Everything a plugin adds carries its id: tables, jobs, routes, query keys and events, never kit.. Two plugins declaring one table fails the check. Plugins
  • A plugin’s tenant table must carry an isolation test, and the check refuses one without. A plugin that adds its own query surface owns the test that proves it stays in one organisation. Threat model
  • Public plugin routes live only under /api/hooks/<id>, rate-limited per IP and body-capped before the plugin runs, and get no organisation until the handler proves the caller. Plugins
  • Plugin routes that need sign-in are mounted after the kit’s, so a plugin cannot shadow a kit route. The API shell
  • Signed state is HMAC with a purpose and an expiry, and the kit gives a callback one call that re-checks the person’s membership, role, block and organisation status. Plugins
  • A plugin signs people in through the identity seam and never writes a session. Linking by email needs a proved domain, and the operator’s bootstrap admins are never created or linked through it. Plugins
  • An event emitted in a request’s context cannot name another organisation, and its payload is re-read under the organisation filter on delivery. Plugins
  • A plugin’s skills cannot shadow the kit’s, and its coding-agent hooks may only run scripts the plugin ships. Plugins

How the code is kept this way

  • Contracts first: every API input and output is a zod schema shared by the server, UI and CLI, and routes validate input against it. Shared contracts
  • Secrets never go in a config file, in git or in a response. gitleaks scans the full history in CI, and only test fixtures are allowlisted, by path and pattern. Deployment
  • Provisioning tokens never reach the Worker, and every line the provisioning scripts print is redacted. Deployment
  • The Worker code may not read process.env or use Node-only APIs, and the build fails if it does. The API shell
  • Staging and production use different names for account-wide resources, and a parity test refuses a collision, so one environment cannot run against the other’s data. Deployment
  • An optional external deployer lets CI deploy with no Cloudflare token and no database credential. Deployment
  • The gate (lint, typecheck, test, build) passes before every commit and is the same command CI runs. Database
  • Each fixed audit finding keeps its proof as a permanent regression test, named for the behaviour. Security audit
  • Findings stay outside the repository until the fix ships, and a fix commit describes the behaviour, not the attack. Security audit
Threat model

Who may do what

The audit starts from a written threat model: who touches the app, what each may do, and what each must not. This is its actor table in short. In a copy the threat model is yours to rewrite for your own product.

  • Anonymous visitor

    MayUse public routes, sign in, and use an invitation they hold the token for.

    Must notRead or change an organisation’s data, or learn whether an account exists.

  • Pending or rejected user

    MaySee the pending page.

    Must notGet into an organisation or use the platform’s resources.

  • Member

    MayUse what the permission matrix grants them in their organisation, and see documents visible to them.

    Must notReach another organisation, read a restricted document, or raise their own role.

  • Admin

    MayManage their organisation within the permission matrix.

    Must notCreate or remove an owner, or extract a stored credential.

  • Owner

    MayDo everything in their organisation.

    Must notReach another organisation.

  • API key

    MayAct as its organisation and role, within its scopes and expiry. Read its creator’s profile, and with a write scope edit it.

    Must notGo past either, reach the admin area, or list or act in its creator’s other organisations, invitations or access requests.

  • Support and global admins

    MayWork across organisations through the admin area and the audited entry path.

    Must notKeep elevated access after losing the role.

  • A document’s author

    MaySupply text the model reads, including a colleague or the source of an uploaded file.

    Must notSteer another person’s model turn into disclosing data or taking an action.

  • The model

    MayCall tools bound to the requester’s scope.

    Must notChoose an organisation, or do more than the requester could.

  • Identity providers and webhook senders

    MayAssert what their configuration trusts.

    Must notBe believed about anything else, or replay a message outside the accepted window.

  • A plugin

    MayUse the declared entries and the context it is given.

    Must notReach the kit any other way. It runs in the same Worker with no sandbox, so an installed plugin is trusted like a dependency.

  • Operator and developer

    MayControl the configuration, the secrets and deploys.

    ScopeOut of scope as attackers.

Out of scope: anything that needs a compromised operator, Cloudflare account or developer machine, upstream bugs with no reachable effect here, and floods of traffic. Running up the AI bill, or one request that exhausts a resource, stays in scope.

Read the full threat model
How it is tested

An audit by agents that check each other

/rf-security is a multi-agent security review that ships in the kit, built on Cloudflare’s security-audit skill (MIT). Separate agents look for holes, and other agents check each one from scratch.

  1. Reconnaissance

    One agent maps the system against the threat model: entry points, trust boundaries, the sign-in and tenancy paths.

  2. Hunters

    Each hunter gets one narrow unit: a subsystem, a boundary and a list of attack classes. A hunter never sees another hunter’s results or a list of suspected bugs.

  3. Independent verifiers

    Every candidate goes to a fresh verifier on a different model from the hunters, so a mistake one model tends to make is not repeated by the model checking it. It confirms with a proof, rejects, or names the one fact it could not settle.

  4. A critic

    A critic reads the coverage ledger and names what nobody looked at. That becomes the next wave of hunters while the budget lasts.

  5. Reviewers

    Reviewers challenge every confirmed finding. A review that changes one materially sends it to a new verifier before it stands.

  • Confirmed means proven

    A finding counts only when a test, built with the kit’s own test helpers, fails on the untouched code. Every file and line it cites is checked.

  • Proofs never touch a deployment

    They run in a locked-down container with its own throwaway database and test organisations, a read-only filesystem and no route out. No agent sends traffic to a deployed app.

  • Findings stay private until the fix ships

    Nothing goes in an issue, a pull request or a commit message before the release. The repository is public, and an early write-up would work against every copy that has not upgraded.

  • A fix keeps its proof

    Each fixed finding’s proof becomes a permanent regression test, named for the behaviour rather than the attack.

Cadence

When it runs

Before a release that touches a boundary

A standard run scoped to what changed since the previous release, whenever the changes reach sign-in, tenancy or row-level security, the identity or plugin seams, or the tools the model is given. The kit’s release script warns when they do. It is a reminder, not a gate.

Every quarter

A deep run over the whole kit, with the plugins installed.

Your copy

Run it on your own app

Every copy ships /rf-security and a threat model to rewrite for your product. Ask your coding agent for it. It agrees the mode and the budget with you before it starts, and it needs Docker for the sandbox.

Mode Agent calls Cost When
/rf-security quick 16 ≈ $35 A quick look, a re-run, or a renamed copy’s first check.
/rf-security standard 50 ≈ $110–150 Before a release, over what changed since the last one.
/rf-security deep 90 ≈ $200+ A first audit, or after sign-in, tenancy or AI changed a lot.

Costs are at API prices, about $2.00–2.50 per agent call. A standard run takes a range of refs, such as /rf-security standard 0.34.0..HEAD, and audits the files that changed and the code that reaches them. Its results stay in your home directory, outside the repository.

Read how the audit works
Found something?

Report a vulnerability privately

Please do not open a public issue for anything exploitable. Use GitHub’s private vulnerability reporting on the repository the problem is in. You will get an acknowledgement, and a fix or a reasoned answer, before anything is made public.

Read the full security policy.

Taking a fix

Fixes land in the next kit or plugin release. A copy takes them with /rf-upgrade, which ports each later release into your app. Each release’s porting note says what changed, never how to exploit it.

See the changelog