Data isolation
D1 is SQLite. It has no row-level security and no database roles. The D1 binding of a Worker can read every row. gymgym gets the same guarantees from several layers. Each layer catches a different kind of mistake.
- One way into the database. Resolvers receive
ScopedData, which the server builds for each request from the session. Every read filters on the user id of the caller. Every insert sets that id from the session. Clients never send a user id. - System access is explicit and audited. Code that must read across users (cron reminders, admin screens) uses
SystemData. It writes an audit row with a reason. Reading what a person wrote to the coach is one of these: the admin dashboard writes a row each time it lists the conversations of a person (list_conversations; the conversations of a day write one for each person on the list) and each time it opens one (read_conversation, with the conversation in the reason). Photos stay with their owner. What people did in the app is another one: the admin dashboard writes a row each time it lists the events of a person or of a day (list_events, one for each person on the page). - The database refuses links between users. Child tables carry the id of the owner. Triggers in
0001_owner_guards.sqlreject a child whose owner differs from the owner of its parent. They also reject any update that changes an owner. - Nobody can probe ids. Ids are UUIDv7. A row of someone else and a missing row both return
NOT_FOUND. - There are no shared caches. GraphQL responses carry
Cache-Control: private, no-store, so no browser or edge cache keeps or shares them. - Other storage follows the same rule. The rest timer Durable Object is addressed by the user id of the session, never by an argument from the client. The Durable Object of a coach answer is addressed by the id of its conversation. The Worker first checks that the conversation belongs to the signed-in person. The Worker tells the object who that person is, and only that person can join or stop the answer.
- Sharing is a snapshot. A shared plan is a sanitized copy that you read with a token. It never contains workouts, weigh-ins or identity.
Columns
Section titled “Columns”- The schema is the allowlist. Clients see only the fields that the GraphQL schema declares. Session tokens, OAuth tokens and passkey keys are never exposed.
- Field scopes. Every root field declares who can call it (
public,vieweroradmin). Sensitive fields have their own scope. The access column in the GraphQL reference is generated from these declarations. - Explicit inputs. Each mutation has its own input type. It never accepts owner ids, roles, ban flags or computed values.
- Quiet errors. In production, the server masks unexpected error messages.
Remote MCP and connected apps
Section titled “Remote MCP and connected apps”Assistants on the remote MCP server (/mcp) get OAuth access tokens from the authorization server of gymgym. An assistant gets a token after the user signs in, picks an account and allows the assistant. The server checks each request before any tool runs. It checks:
- the signature, the issuer and the expiry of the token
- the audience: the token must be issued for
/mcp, so the server refuses a token for something else - the DPoP binding, when the token has one
- that the account exists and is not disabled
- that the user still allows the app
Then the tools reach the data in the same way as the web app: through GraphQL and the row rules above, as that one user. The Worker vouches for the user id in the same process and never forwards the token of the assistant. If you remove an app in Settings → Connected apps, gymgym deletes its consent and its tokens, and it refuses the next request of the app.
Personal API keys
Section titled “Personal API keys”API keys let scripts call /api/graphql as their owner. The Better Auth api-key plugin stores only a hash and the first characters of a key. It checks the expiry and limits each key to 120 requests a minute. The own HTTP endpoints of the plugin are disabled, so you create and revoke keys only through GraphQL. A key resolves to the same ScopedData as a session, so the row rules above apply without change. These rules add to them:
- The server refuses every mutation from a read-only key before any resolver runs.
- Managing keys, signed-in devices and connected apps needs a real browser or CLI session. A key never gets admin scopes.
- Only GraphQL accepts a key. The endpoints of Better Auth and the MCP server do not treat a key as a session.
- A trigger deletes the keys of a user together with the user.
The list of signed-in devices also reads sessions through ScopedData, and it returns no session tokens.
How it is tested
Section titled “How it is tested”- An isolation test runs every operation in
packages/sdk/operationsas user B against the data of user A. It expectsNOT_FOUNDor nothing. New operations are covered without a change to the test. - A schema contract test fails if a root field has no access scope or no description.
- Database tests insert children of another user and change owners directly in SQL. They expect the triggers to refuse.
Stronger options
Section titled “Stronger options”If the engine itself must isolate the data, two paths stay open: one SQLite database for each user in a Durable Object, or Postgres with real row-level security through Hyperdrive. Both give up some of the simplicity of D1.