Skip to content
Spools
Documentation
On this page

Security

Each deployment of a Spool serves one business. This page says who can do what in one, and what to know before putting customer data in it. A business whose groups (branches, regions, teams) must each see only their own records turns on record scopes, and one whose roles must each reach only some kinds of record gives them role access. To report a vulnerability, see the security policy.

Trust model#

These are the boundaries the code enforces:

Who Can do Enforced by
Anyone See the sign-in page, unsubscribe with a valid signed link The only public routes; the unsubscribe token is signed with APP_SECRET
Signed-in person not on the allowlist Nothing in the CRM The boundary checks a verified email against access in crm.config.json. An auth adapter hands over an address only when its provider has verified it
CRM user Read and write every record, run actions, use the assistant, unless role access or record scopes narrow it Every CRM server function and API route goes through the boundary (crmHandler, apiRoute); lint refuses one that doesn't
Swirls (workflows, assistant tools) Call /api/swirls/tools/* Bearer SWIRLS_APP_TOKEN (32+ chars, constant-time compare). Fails closed when unset
An outside caller of your own door Call the endpoints you build behind publicRoute. See Your own door Nothing of the framework's: your endpoint's own checks, in the order Building your own door gives
A cron job Run one pass of the mailbox sync, the sequences or the scheduled posts, or keep the server warm, through /api/cron/* Bearer CRON_SECRET (16+ chars, constant-time compare). Fails closed when unset
The email provider Report bounces and complaints to /api/webhooks/email The email adapter checks the signature (Resend: Svix, with RESEND_WEBHOOK_SECRET). Refused when no secret is set

Without scopes in crm.config.json, and without role access, every allowed user has the same access: they read and write every record. With scopes, see Record scopes. Use separate deployments if you need the separation a database gives. Apart from scopes and role access, the one narrower rule is who may connect and disconnect an account shared with the team, when its provider says (canManage, below). It limits managing the connection, not using it.

Role access#

A role with access says which objects the people holding it may reach, and the server enforces it: { "deny": ["ledger"], "readOnly": ["jobs"] }. It keeps kinds of record apart (an office-only ledger, a look-only role); record scopes keep groups of the business apart (one branch's jobs from another's). The two are independent and both apply, so the stricter wins.

What it does. For each signed-in request the boundary (crmHandler, apiRoute) works out what the person's roles allow (asPerson in packages/spools/src/server/object-access.ts), and the data layer checks it on every read and write:

  • A denied object's records are not found, never "forbidden", wherever they would be reached: record pages and lists, counts, related lists, relation pickers and titles, CSV matching, Cmd+K's index and deep search, value suggestions, saved views, the record's timeline, tasks and notes (on it, and in the lists that gather them), favourites, reports, exports and imports, the record's folder and the folders inside it, and actions. A relation to one is returned with its id only: no title, no linked records. Home and the sidebar leave the object out.
  • A read-only object's records are read and never changed, and neither is what hangs off them: a create, change, delete, import or action, a note, task or logged call on one, an email to one, an enrolment in a sequence, a file or folder added, renamed, moved or deleted in its folder (or any folder inside it, a related record's included), a folder made for it or shared with another record, and a change to a view everyone shares of that object are each refused in words ("You can look at jobs but not change them."), and the page doesn't offer them. It is refused before anything else happens: before the app's before hooks run, before a workflow starts or an email is sent, and before the file store is asked to do anything (the test that reads the server's source for every such place lists these checks too). Reading, listing, searching and downloading stay theirs, and so do a favourite and the views only they see.
  • A role that may change no object (readOnly: true, or every object read-only or denied) changes nothing that is the whole business's either, as a read-only person with record scopes changes nothing: no task or note on no record, nothing in the shared file library or any folder, no view everyone shares, no marketing post and no connection the team or a group shares. Each is refused before it is written, sent or asked of the file store.
  • Several roles: a person gets what any of them allows. Someone with no role reaches everything, unless access.default says otherwise.

What it does not do.

  • The tool API is not narrowed by roles. A call from the assistant or a workflow says which deployment it is from (SWIRLS_APP_TOKEN), not which person it acts for: the chat's tool workflows carry no grant, and a grant is only made in a Spool with record scopes. So the assistant reaches what everyone does, less the objects assistant.deny names, which are not found to it. Keep internal objects there.
  • Code with nobody behind it is not narrowed. A script, a cron route and the config's automations (they run after a change was let through) run with nothing kept from them, and so does code inside asSystem.
  • What the app's code reads through the framework is. An apiRoute, a server function (crmHandler), a handler or a hook called for a teammate keeps their role access in what it does through @swirls/spools/extensions, as scopes are kept: a denied object is not found to it, a read-only one refuses its changes, and changedSince says nothing of a denied object's records. Code that must reach further says so with asSystem. Your code is still handed what the framework hands it (a hook's record): don't send that on to someone it is kept from.
  • Code nobody is signed in for holds no role. A publicRoute, a cron job or a script runs with nothing kept from it by role access (access.default applies to people, not to them): an endpoint for outside callers decides itself what they reach.

Four ways that would otherwise have reached a denied object are closed:

  • Timeline lines. A line on a record's timeline is kept as it was written and read by everyone who reads the record, so a change to a relation that leads to an object any role, access.default or assistant.deny keeps from someone never names the record it now points at: it says "updated Client", or "added Tags: 2". Lines written before an object was denied are rewritten by spools timeline redact.

  • Filters and sorts. A condition that looks into a denied object (a field of a related record of it, source.path contains ...; the records of it that point here, ~ledger.job; a relation or relations field holding its records) is not there for the person: their list is what it is without it. A sort by a relation to one is by the related record's id.

  • The team activity report counts no call, email, meeting, task or note on a denied object's records.

  • File search finds no file in a denied record's folder or below it, as the folder itself can't be opened. Nor is the folder listed in the one above it (its name is the record's title), and a file is opened, renamed, moved or deleted through the folder it is in (the link carries it), never by its id alone, for anyone role access keeps something from.

Record scopes#

With scopes in the config, each record of a scoped object belongs to one scope, and a person reaches only the scopes they hold.

Who Can do
A person who holds a scope with a writing role Read and change that scope's records, and what hangs off them: timeline, tasks, notes, files, sequence runs
A person whose roles are all read-only Read what they hold, shared objects, Marketing and Integrations. Any change is refused: scoped records, shared objects' records, folders and files, shared views, marketing posts, the team's connections. They start no action, workflow or sequence, and nothing is sent or published for them
A person whose role has all The same, in every scope
A person on the access list who holds nothing Read shared objects, the shared file library, Marketing and Integrations, which are everyone's by the config's own word. They change nothing of the business's, as a read-only person changes nothing, and see no scoped record and nobody on the team list
A workflow calling the tool API What its signed grant says, and no more than the person who started it holds when the call is made: the one record it was started for. With no grant, it reads shared objects and changes no record at all
A cron job, a webhook, a script Read shared objects. Nothing scoped, and no change to any record, a shared object's included, unless the code that runs says it is the system (asSystem)

Where it is kept. In one place, under everything: every store is behind a guard (packages/spools/src/server/store/scope.ts) that narrows each read, count, change and delete to the scopes of whoever the request is for. Pages, search, reports, exports, imports, saved views, the assistant's tools and your own extensions all reach the database through it, on every database adapter. A record of another scope is not found; it is never "forbidden". With nobody said, a scoped table refuses the call, and so does a change to any record, so new code that forgets fails closed. A refusal is a failure of its own (ScopeRefused), with words for staff, and is never reported as a database failure: code that expects one (a unique index keeping one row) doesn't mistake a refusal for it.

What to know.

  • A scope counts only when it is one of this Spool's. Whatever a sign-in provider or a resolver says a person holds, a scope gives them something only when it is holdable here: an option of a scoped object's scope field, where that field is a select, and for a field kept as text or as a relation, a scope the resolver lists. This is asked in one place, before anything else is worked out from what a person holds. It matters beyond that scope's own records, because whoever writes some scope may change what is shared: shared objects' records, shared views, the file library, Marketing, the team's connections. A scope nobody defined would otherwise be a way to all of that. With no list, a text or relation scope field has no scopes, nobody holds one, and the server says so when it starts.
  • With Clerk organizations, the organizations that are scopes have to be named, and so does head office. At Clerk, unless you have turned it off, anyone can create an organization, and is its admin there. So an organization is a scope only when its id is in scopesFrom: a membership in any other gives nothing at all, whatever its role, and such an organization is never listed. Without scopesFrom no organization is a scope and nobody holds one, and the server says so when it starts. A role marked all counts only from the organizations listed in everyScopeFrom, by id, for the same reason: Clerk's own org:admin is held by whoever runs any organization. Turning organization creation by users off at Clerk is good housekeeping, and nothing here depends on it. Scopes are keyed by the organization's id (org_...) and never by its slug, because an organization's administrators can rename its slug, to one that another scope's records were filed under. See Signing in.
  • What a person holds is kept for a minute. A scope taken away at the provider stops working within one.
  • The scope a person works in is a preference, not proof. The spools-scope cookie (or Clerk's active organization) is checked against what the person holds on every request.
  • Relations stay inside a scope. A record can't point at a scoped record of another scope, and can't move to another scope while scoped records point at it: move or unlink those first. Its timeline, tasks, notes, folder and sequence runs move with it, in the same transaction: a move that can't take them all is undone, and a row being added to a record as it moves waits and takes the scope the record came to. A record being pointed at is held until the record that points at it is saved, so a move and a new link to the same record can't pass each other: whichever comes second waits, and is refused.
  • Many-to-many links belong to the records they join. A link of a relations field has no scope of its own: it belongs to the scope of each scoped record it joins. The rules follow from that:
    • Two scoped records are linked only inside one scope, as a relation is. A link across scopes is refused, for a role marked all too.
    • A scoped record and a shared object's record (a contact's tags): the link is the scoped record's. Whoever reads that record reads the link, and adding or removing it takes the right to change that record. So a tag shows each person the contacts of the scopes they hold, and counts only those.
    • Two shared objects' records: the link is everyone's, and anyone who can change something can change it.
    • Reading. A linked record out of reach is left out everywhere, from either side of the relation: its id, its title and its place in <field>Count, in lists, on the record, in the picker, in footer counts, exports, search and the tool API. A filter that asks about one is answered as if the link were not there. A record shows the first hundred of its links: those are the first hundred its reader can reach, not the first hundred there are with the others taken out.
    • Writing. A list of ids that replaces a field's records removes only the links its writer was shown. Someone who writes nothing changes no link. Under a grant made for one record, the tool API adds and removes that record's links and no others.
    • Moving. A record can't move to another scope while it is linked to scoped records that would stay behind: unlink them first, move it, and link it again there. Its links to shared records go with it. A record being linked is held until the link is saved, so a move and a new link can't pass each other.
    • Deleting. The database removes a record's links with it, whoever the record at the other end belongs to. So a record can't be deleted while it is linked to a record of a scope its deleter can't change, a shared record (a tag) included. Someone who can change those records unlinks them first, or a role that writes every scope deletes it.
    • Links that crossed before scopes were turned on are left as they are. Only someone who holds both scopes is shown one; everyone else sees each record without it. Remove such links when you turn scopes on.
  • A shared record's timeline is everyone's. So a line on it never names a scoped record: it says how many records a field gained or lost ("added Contacts: 2"), or that a relation changed ("updated Maker"). A scoped record's timeline is its scope's, and names them.
  • Deleting a record clears the links to it, so it is refused while that would write another scope. An optional relation is emptied when the record it points at is deleted, by the database, whoever the linking record belongs to. So a shared record (a product) can't be deleted while records of a scope the deleter can't change point at it, and neither can a scoped record that a record of another scope still points at. Someone who can change those records unlinks them first, or a role that writes every scope deletes it.
  • A scope kept in a relation. When an object's scope field is a relation (a depot's region), the record it points at is that scope's key. Nobody deletes that record while any record takes its scope from it, a role marked all and the system included: every one of them would be left with no scope. The database refuses it too (ON DELETE RESTRICT on that relation). And nobody changes a record's id.
  • What can be a scope. A record can't be given * as its scope, by anyone: it stands for every scope, and the record's timeline, tasks and notes would be everyone's. A select field's scopes are its options. For a text or relation field they are the ones the resolver lists, and a scope it doesn't list is refused when a record is saved. A resolver of your own that lists none (Extending) leaves such a field with no scopes: nobody holds one, and its records are only there for a role marked all.
  • Records that crossed before scopes were turned on. A relation that already pointed into another scope is left as it is. The related record's title is not shown, filters can't ask about it, and a list sorted by that relation sorts the row as one with no related record. The row keeps the related record's id. Clear such relations when you turn scopes on.
  • A shared object can point at a scoped one (a product's supplier). Whoever can't reach the related record is shown the row without it, can't filter by it, and has it sorted as a row with none.
  • A deleted record's folder stays its scope's. The folder and its files are kept in the file store, and the row that says whose they were is kept with them. Every record's folder carries part of the record's id in its name, so a new record never takes over a folder another left, and a folder's name never says whether another scope has a record called the same. A record deleted before scopes were turned on has no such row: its folder is nobody's, so everyone's, and the backfill can't tell whose it was. Move or remove those folders before turning scopes on.
  • Rows written before scopes were turned on have no scope and are only there for a role with all, until bun run db:scopes (spools scopes backfill) has given them their record's. A task or note on no record stays with head office: nothing says whose it was.
  • Changing which objects are scoped. Each row that hangs off a record (a line on its timeline, a task, a note, a favourite, its folder, an upload, a sequence run) keeps a copy of its record's scope, and a row on a shared object's record is marked as everyone's. That copy was true when the row was written, so after any change to scopes.objects run bun run db:scopes again. Until it has run:
    • An object that was shared and is now scoped. Its records are scoped at once. The rows already on them are still marked as everyone's, and that mark is no longer taken at its word: they are out of reach of every scope, their own included, and are only there for a role with all. Their folders and files are too, and a sequence run among them is held, not sent. The backfill gives each its record's scope.
    • An object that was scoped and is now shared. Its records are everyone's at once, by the config's own word. The rows already on them stay with the scope they had, read and changed by that scope's people only. The backfill gives them to everyone, as a new row on a shared object's record is.
    • An object taken out of the config. The rows that were on its records keep what they carry: one that has a scope stays that scope's, and one marked as everyone's is only there for a role with all. The backfill leaves them as they are.
    • A scope field changed for another. The records take their scope from the new field at once. The rows already on them keep the scope the old field gave. Where the two fields use the same scope names for different records, this is exposed until the backfill has run: the people of the scope a row still carries read and change that row, a line on the record's timeline, a task, a note, its folder and the files in it, though the record itself is no longer theirs and they can't open it. The guard can't close this by itself. A row's copy is all it has to go by, and that copy is a scope someone really holds. So change a scope field with the server stopped, or run bun run db:scopes in the same deploy, before anyone signs in. The backfill gives every such row its record's scope, and takes away the scope of a row whose record has none.
    • A server that stays up says at start-up when rows are waiting for the backfill, and in which tables. For rows that carry another scope than their record's it holds a few hundred rows of each table against their records and says so in a line of its own, naming what is exposed. That is a sample: finding none is not proof there are none. A serverless host does not look each time it starts: run the backfill there without being told.
    • The backfill never leaves a row behind a record that moves beside it. For a row that carries anything but its record's scope it holds the record, reads its scope again, and writes the row in that same transaction, which is how a move itself takes a record's rows with it. A move that is under way is waited for, and a move that comes after waits and takes the rows on.
    • Synced mail and meetings are lines on a record's timeline, and follow these rules with the rest of it. Which mailbox was read up to where is each person's own and belongs to no record. Marketing posts, ad results and connected accounts hang off no record.
  • * is never a record's scope. A record that has * in its scope field (text typed before scopes were turned on) is a record with no scope: only a role with all sees it, and what is hung on it has no scope either. Give it a real one.
  • Owners and assignees. A user field can name anyone, including someone who can't open the record. The pickers only offer people who share the scope.
  • Saved views are shared by everyone who uses the object, whatever their scope: a view's name and its filters are seen by all. The titles of records a filter names are not. A view everyone shares is renamed, re-filtered, rearranged and deleted only by someone who can change something: a read-only person, and someone who holds nothing, are refused, and so is their resetting a view the config declares. They still sort and filter what is on their own screen, and make, change and delete views only they see.
  • Files. The file store knows nothing of scopes, so the CRM checks every folder and file it is asked about: a record's folder, and everything under it, is only reached by those who reach the record. A file is opened, renamed, moved or deleted through the folder it is in (the link carries it), never by its id alone. Whether it is in that folder is asked of the file itself when the folder holds more than a listing shows. Anyone with access to the store itself still reads all of it. The shared library, and folders the team made outside a record's folder, are everyone's.
  • Grants for the tool API. A workflow started for a record is handed a token signed with APP_SECRET (HMAC-SHA256, compared in constant time). It states the record's scope, the record, who started the work and when it ends: fifteen minutes later unless scopes.grantMinutes says. The tool API answers a call that carries it about that record only, and refuses it once that person is off the access list. That one record goes with the call into your own code: a hook, a handler or a run target that a change made under a grant sets off reads and changes, through @swirls/spools/extensions, that record and no other (getRecord, updateRecord, its timeline, tasks, notes and folder), and is refused listRecords, createRecord and the rest that reach further. Code that must reach further says so with asSystem. This is what those functions do, not a wall around your code: an extension that goes past them to the server's own modules is working with the grant's whole scope, as it always could. Each time it is used it is cut down to what that person holds at that moment: someone who has lost the scope has lost the grant with it, and someone who may now only read it has a grant that only reads. As with everything a person holds, that is within the minute. Whoever holds a grant has its reach until then, so workflows must keep it out of prompts and messages. See Swirls.
  • Actions, automations, sequences and email are changes. Running an action on a record, writing to its email address, and anything else that starts a workflow, the app's own handler or an email sequence for it, needs the right to change that record. It is checked before anything is started or sent, so a read-only person's click starts no workflow and sends no email. The same goes for everything the server does outside its database: the app's before hooks run, and the file store is asked to take, move or delete something, only for someone who may make that change, and with nobody said none of it happens. A test reads the server's source for every such place and fails when one is added without saying what settles who may do it (packages/spools/tests/unit/effects-after-checks.test.ts).
  • The assistant. Its chats must be each person's own, which needs federation with your sign-in provider: with a project API key everyone would read everyone's chats, so the assistant is refused and says so. And the assistant's record tools are refused in chat, because a chat has no way to carry a grant that the model can't relay; see Swirls. Workflows started from a record do carry one.
  • Marketing, integrations and guides are not scoped: the Marketing page and its posts are the whole business's, and everyone on the access list reads them. Changing them is for someone who can change something. A person who can change no record, because their roles are all read-only or because they hold nothing, reads Marketing and Integrations and changes neither: they don't draft, edit, schedule, publish, take back or delete a post, have the website checked or read, or have ad results read again, and they don't connect, replace or disconnect an account the team or a group shares. Each is refused before anything is written, started or sent ("You can look at Marketing, but not change it."), and the pages show them no control for it. What is their own stays theirs: a mailbox or another account of their own, the guides they have seen, their favourites, the views only they see. A post that someone who may scheduled goes out at its time with nobody signed in, as before. A Spool without scopes is as it was: every CRM user does all of this.
  • Marketing is written by nobody on a record's behalf. What is on the Marketing page is read by every scope, and by people who hold none. So a call to the tool API under a grant made for one record is refused the tools that write there (draft_post, save_site_profile, post_result, save_ads): a workflow that can read one scope's record could otherwise be talked into copying it to where everyone reads, by text on that record's timeline. The marketing workflows that answer through those tools are started for no record and carry no grant. And the assistant drafts no post in a chat: a chat's call can't say whose draft it would be, and the person chatting may be one who can change nothing. A person writes it on the Marketing page.
  • A credential is not bound to a record. getAccessToken and findConnections in @swirls/spools/extensions answer a hook that runs under a grant made for one record as they answer any other. A hook that a workflow's write-back sets off is where an app sends a changed record to the books, and a token for another service is no way into the CRM's records. What your code sends with it is your code's to decide.
  • What a refusal gives away. A record that can't be deleted or moved says why, and the reason can be records its reader can't see: "deals of a branch you can't change point at it", "it is linked to contacts of a branch you can't change", "parts need it". So someone who may change a record learns that some record of that kind, out of their reach, points at it. That is all they learn: never how many, which, or of which scope. It is kept on purpose. The alternative is a delete that fails with no reason, which nobody could act on.
  • Connections are shared across scopes, and a group is not a scope. An account connected on the Integrations page is used the same way whatever scope a person works in: a teammate's own by that teammate, one shared with the team or with a group by everyone on the access list. A provider's group is a label that says which account to use (a branch's books). It is not a permission: holding a scope gives nobody a group, and a group reaches no record. A connection is a token for another service and never a way into the CRM's records: a handler that uses one reads and writes records with the access of whoever it runs for, and code with nobody behind it reaches a scoped record only inside asSystem. See Integrations.
  • Read-only people are shown no edit controls. Someone who writes nothing gets no buttons to add, import or delete records, no editing in a table cell, a board card or a record's details, no record actions, and nothing to add a task, a note, a logged call or an email, or to upload, rename, move or delete a file. Nor anything to rename, rearrange or delete a view everyone shares: they are offered "Save as my view" instead. Someone who writes some scopes and only reads others gets them record by record. This is the page being tidy, not the rule: the server refuses each change itself, and says why, whatever a page shows. Starring a favourite is a person's own and stays, and so are the views only they see.
  • A record others must have. A required relation is kept by the database (ON DELETE RESTRICT): the record it points at can't be deleted while any record needs it. Staff are told so in words ("This product can't be deleted while parts need it"), with or without scopes, and not shown the database's own, which name its foreign key.
  • Every store is tested, and so is a browser. The scope tests run on PGlite, on Postgres through Effect SQL and through Prisma, in CI. The browser tests run the starter with scopes laid over its config and two branches' records: lists, search, relation pickers, a record's linked records, notes, tasks and files, the address of another branch's record, a read-only person's page and a change sent past it, and head office switching branch and moving a record. The ones that set two changes against each other (a move and a new link, a delete and a new link, for relations and for many-to-many links) run as two connections on a real Postgres, and so do the ones that set changes holding the same records from different ends against each other, a move of scope among them. A database adapter of your own inherits the guard; run the integration tests on it (TEST_STORE) before relying on it.

Your own door#

Spools has no door for people who are not teammates: an app builds its own behind publicRoute from small helpers (Building your own door). The framework enforces nothing about who such a caller is or what they reach; each helper does one thing, and stands on its own:

Helper What it guarantees
verifyToken A user id only for a token the auth adapter checks as issued to one of the origins named (azp); with none named, only a developer's or a test's server takes any. Never a network call per token (clerk(): a keyring, or CLERK_JWT_KEY offline)
bearerToken Only the Authorization: Bearer header: a session cookie sent alongside counts for nothing
callerAddress The address TRUST_PROXY (1 to 10, anything else is none) says to trust, or null when it can't be known: never one shared value to count by
hitLimit, peekLimit, consumeLimit Your buckets are counted as app:<bucket>, apart from the framework's; bad numbers are refused; with storeRateLimits() the same on every instance, no more than the limit however callers race
idempotent A key is the caller's alone (app:<caller>, apart from teammates' staff:<id>): the caller must be a verifiedCaller (its type, and a runtime check of its shape), made from ids the app verified. Answers sealed by the vault for their row and caller, never kept in the clear
sealText, openText Sealed for an owner you name, kept apart from the framework's secrets (app:<owner>); nothing sealed without a vault; text in the clear is refused
writeKeptFields Only readonly fields, so no person's change goes untold; the record's rules still hold
changedSinceAs Narrows the answer by your own check; a check that fails says no
asSystem Lifts record scopes and role access for what your code does inside it, and nothing else: there is no other guard to lift

What is yours, because nothing in the framework knows your callers:

  • Who they are. Map a verified user id to a record of yours by a readonly field, written only by your code, so no teammate, import or the assistant can point a record at someone else.
  • What they reach. Your endpoint runs with nobody signed in: a read through @swirls/spools/extensions reaches every record (record scopes refuse a scoped object until your code says asSystem). Check every id a caller sends against your own rules, and answer one out of reach exactly as one that doesn't exist.
  • What leaves. Answer an explicit list of fields, never a record as it is read.
  • What they write. Write only the fields you name. Hooks and automations run for those writes as for any other; a before hook's values are written as the server's.

Residual risks you accept#

What the framework does not close, by design or for now. Each is yours to weigh:

  • Uniqueness 409s tell anyone whose write clashes that a record with those values exists, across rows and record scopes.
  • An object-level changedSince key tells when any record of the object changed, records out of reach included.
  • Values a before hook returns are written as the server's: not checked against readonly.
  • A write can run twice if storing its idempotent answer fails on every retry: the claim then goes stale and a repeat runs.
  • Quotas count in fixed windows (a UTC day, a minute): about twice a limit can go through around a window's edge.
  • Signing keys Clerk rotates in are picked up within a minute of the first token that names them, and dropped keys within an hour.
  • With the memory limiter, rate limits are per server instance: N instances allow about N times a limit, and a restart forgets.
  • Without TRUST_PROXY callerAddress is null: an app that skips its address limit then relies on the platform in front to tell callers apart.
  • A file store that doesn't enforce an upload's declared type or size relies on the CRM's check at finish, which a store that can't say a size skips.
  • idempotent takes only a verifiedCaller, but what the app verified before making one is its own: an id taken from the request instead of a verified token lets one caller replay another's answers.
  • An endpoint for outside callers is as safe as its own checks: the framework applies no field allowlist, ownership rule or role to it.

Locks and deleting#

A lock or a parentLock keeps a record as it is for everyone, the server's own work included: no change gets past one. Deleting is the one exception, so that data a lock holds is never undeletable for good (an erasure request, a submission made by mistake): the server's own work, said out loud with asSystem, may delete a locked record, a record its parent locks, or the parent, which takes the records it locks with it in one hold. A person, the assistant and code with nobody said are refused. Gate such an action in your app yourself (an admin-only handler or server function that runs it inside asSystem): the framework can't tell a mistaken submission from a wanted one. The records it pointed at say on their timeline who removed it (the actor your code passes) and that it was a system removal.

Things to know#

  • The development parts don't run in production. A copy with no keys uses a database inside the server and a sign-in that lets everyone in. In a build both are left out: src/spool.server.ts picks them only when NODE_ENV isn't production, which a build fixes, and the development sign-in refuses to start under NODE_ENV=production. A deployment missing its keys stops at start-up.
  • Clerk development instances are for testing. One verifies any address ending in +clerk_test for whoever types a fixed code. A deployment never accepts such an address, and says at start-up when it is running on a development instance's keys (sk_test_). Use the production instance's keys where real people sign in.
  • Field encryption isn't active yet. Fields marked encrypted are stored as plaintext until @cipherstash/stack-prisma supports Prisma 8. Treat the database as holding plaintext PII and secure it accordingly.
  • AI sees CRM data. Swirls workflows and the assistant receive record contents, including text that came from outside your team (imports, pasted notes). Treat that text as untrusted input to the model. Mark fields people outside the team write "untrusted": true (Record rules): the tool API then hands their values over as { "untrusted": true, "text": "..." }, which the assistant's instructions tell it is data, never instructions. Every timeline line the tool API hands over is wrapped too, whoever wrote it, and a line about a change to an untrusted field doesn't repeat the value. The assistant's tools can only read and modify CRM records and add notes, and they can't change email addresses. A record made through the tool API starts no automations, so nothing emails an address the model chose. Its replies never load an image, so text it read can't have a browser send what it knows to another server. Workflows email your team.
  • Mailboxes. For the account a teammate signs in with, the auth provider holds the Google or Microsoft tokens and the CRM asks it for one when it reads or sends. With Clerk, access to your Clerk secret key is access to those mailboxes. With Better Auth they are in your own database, encrypted with BETTER_AUTH_SECRET, so that secret together with the database is. Only the subject, a short preview and the time of mail involving a known contact are stored; message bodies are never fetched. Whose mail it is comes from the address in the From header, never the name beside it. Only the mailbox itself says a teammate sent a message: Gmail's Sent label, or Microsoft's Sent Items folder. Junk and deleted mail are read past. See docs/mailbox.md.
  • Connected accounts. Tokens for accounts connected on the Integrations page are sealed by the vault in the app before they are stored; the database holds only ciphertext and there is no plaintext fallback. Each is sealed for the row it is stored on, and is refused anywhere else, so someone who can write to the database can't move one teammate's tokens onto a connection of their own. The vault's keys (CS_*, or VAULT_KEY) together with the database are access to those accounts. The OAuth flow uses PKCE and a state signed with APP_SECRET that names the teammate and is tied to their browser by a cookie. A teammate removed from access keeps their stored tokens until they are deleted, but their mailboxes stop being read, and code acting for them is given no token. Disconnecting revokes the token at the provider unless another connection holds the same account, whose access revoking would end too. See docs/integrations.md.
  • Shared connections. A provider can make its connections the team's, or one group's (shared in src/app/extensions.ts). Every CRM user can then see that the connection exists and act through it, whoever connected it, and it goes on working after that person is removed from access: it was connected for the business, not for them. So connect an account the business owns, and remember that removing a person does not remove what they connected for the team; disconnect it if it should go with them.
    • Who may connect, reconnect and disconnect one is every CRM user, or only those the provider's canManage names. It is checked on the server when a connection is started, again when the provider sends the browser back, and on disconnect. A rule that fails lets nobody in.
    • The signed state also says whose the connection will be (the team's, or which group's), and the callback reads that from nowhere else, then checks it against what the provider says now. A state for a personal connection can't be replayed to make a shared one, nor one group's for another.
    • Which account a shared connection is comes from the provider, asked with the token it just issued. Nothing in the callback's address is taken as the answer, because the address passes through the browser: a connection whose provider code did not get an answer from the provider is refused. Otherwise a teammate could authorize an account of their own and send it back under the team's name, replacing the team's tokens with theirs. The CRM checks that the provider was asked, not what it was asked: a provider you add must ask for something only the right account can answer.
    • An account is one connection for the team, or one for a group. The database holds it to one row, so two people connecting it at once can't leave two sets of tokens.
    • A shared connection's tokens are sealed for a name that includes whose it is. Editing a row in the database to turn a personal connection into a shared one, or to move it to another group, leaves tokens the CRM refuses to open.
    • Groups are labels today, not permissions: any CRM user can use any group's connection. findConnections({ usableBy }) and getAccessToken(id, { as }) refuse someone who is not a CRM user, their own connections included, and a personal connection to anyone but its owner, when an app's code says who it is acting for. They also refuse when the person named is nobody: as: ctx.actor in a handler that ran with no one signed in is not a way to be trusted. Only code that names no person at all (getAccessToken(id), findConnections without usableBy) is trusted, so the choice is visible where it is made.
    • No browser is sent a token. The page is sent the account's name, whose it is, who connected it and its state.
  • Marketing. An account connected for marketing (LinkedIn, X, Google Ads) is a shared connection: any CRM user can publish through it from the Marketing page, whoever connected it, and can see, reconnect or disconnect it on the Integrations page, unless the app names who may with marketing.canManage in src/app/extensions.ts. Its tokens are sealed like any other, and no browser is sent one. META_ACCESS_TOKEN is a token for the business's page and ad account: treat it as you treat the database's password. Only a CRM user can schedule or publish a post. The tool API can save a draft and nothing more, so text the assistant read can't put a post out. The website check fetches the address in crm.config.json and no other, and the install code it shows is built only from ids that match their vendor's form. See docs/marketing.md.
  • Files. The file store's keys stay on the server; a browser is only ever given a transfer URL for the one file it is sending, or a five-minute link to the one file it is opening, after the CRM session is checked. Without record scopes or role access, anyone who may use the CRM can open, rename, move and delete any file. With them, a record's folder and what is under it is reached only by those who reach the record, and the shared library and the team's own folders stay everyone's. Anyone with access to the store itself can read all of it: its folders are not permission boundaries. With FlashDrive the key reaches every drive in its workspace. Files the server hands out itself are never run by the browser as a page of the CRM. See docs/files.md.
  • Assistant conversations are shared across CRM users when using a project API key (see docs/swirls.md).
  • Secrets. Every key in .env.example is server-only except CLERK_PUBLISHABLE_KEY, which is meant for the browser. Rotate SWIRLS_APP_TOKEN in both the app and Swirls together.
  • Cross-site requests. Server functions and the assistant endpoint reject requests that don't come from the app's own origin (csrfMiddleware in src/start.ts), so another site can't act through a signed-in user's session. Keep that middleware first if you add your own. Every answer also tells the browser not to show the CRM in another site's frame and to take each file as the type it is sent as. Send Strict-Transport-Security from the proxy in front of the server, which is where HTTPS ends.
  • Supabase Data API. The app never uses it. supabase/config.toml doesn't expose public. Every generated table has row-level security on with no policies (@@rls in the Prisma schema), and bun run db:push / db:migrate run spools harden, which revokes the anon and authenticated roles on every table and fails if RLS is off anywhere. On hosted Supabase, also remove public from Settings → API → Exposed schemas.