# Security

> Who can see and change a map, the threat model, and the checklist.

Applies to: the Sypnia engine (open source, self-hosted) and Sypnia Cloud (paid service).  
Source: https://cases.docs.sypnia.com/security/

For agents: Access: workspace membership and roles (owner, editor, approver, invited reviewer), checked by the API on every request and again inside an approval's transaction; the server's own Postgres role owns its tables (no superuser) and versions, version_cases and audit refuse UPDATE and DELETE by trigger; no row-level security on the server's tables. Reviewers see the plain level only. Sypnia Cloud (CASES_DIRECTORY=sypnia): roles come from GET /v1/me of the control plane, kept 60 s and read again for approvals; owner → owner, admin → approver, developer → editor, viewer → reviewer; members and roles are managed in the organization, Cases invites reviewers only. Tokens: key-bound sessions need their DPoP proof; PATs checked at the issuer; project tokens syp_cpt_ (one map, editor, never approve, SHA-256 + last 4). Links read each product as the caller (no confused deputy): in Sypnia Cloud through service calls to the Data control plane (Authorization: Service <key shared through SSM> + x-sypnia-user of the verified person), which the control plane accepts only on GET /v1/me, GET /v1/projects/{ref}, PUT|DELETE …/cases-map and the linked project's sql/v1/schema and sql/v1/query, and where it checks that person's role; self-hosted, the caller's own token; a Telemetry link token is kept AES-256-GCM with CASES_SECRET_KEY. 600 requests a minute per credential. Threats: a reviewer approving beyond their role (role checked in the transaction), an agent rewriting scope (agents and project tokens can only propose), a leaked repository token (KMS-encrypted, least privilege, revocable), injection through case text (text is data, never rendered as HTML, escaped in Markdown exports), a map exposing sensitive table names to reviewers (plain level hides data).

## Who can see and change a map

- **Membership and roles** decide everything ([roles](https://cases.docs.sypnia.com/contract/versions-and-reviews#who-can-do-what)). The API checks them on every request, and checks the role again inside the transaction of an approval. The server's own Postgres role owns its tables; versions and the audit refuse every change and deletion by trigger.
- **Reviewers** you invite see the **plain level** only: no table names, no code, no production data.
- **Links read each product as you.** Cases never shows you a table, a trace or a commit you could not open in that product. In Sypnia Cloud, the Cases server and Sypnia Data's control plane share a key, kept in AWS Systems Manager. Cases calls the control plane with it (`Authorization: Service <key>`) and the id of the person it verified, so every kind of session works, those bound to a key included. The control plane accepts such a call only on the routes Cases needs (who you are, the Data project, its link to the map, its schema and the SQL that reads deliveries), and still checks your role in that project. The control plane forwards a map uploaded to Data to its Cases map the same way. A server you run yourself presents your own token to the other product. A Telemetry read token you link to a map is kept encrypted (AES-256-GCM, with `CASES_SECRET_KEY`).
- **Tokens:** a session bound to a key is accepted only with its DPoP proof, so a copied one is useless; a personal access token is checked with its issuer; a Cases project token (`syp_cpt_…`) works on one map, as an editor, and never approves. Project tokens are shown once and kept as a SHA-256 hash and their last 4 characters ([API](https://cases.docs.sypnia.com/api#project-tokens)).
- **Rate limit:** 600 requests a minute per credential by default (`CASES_RATE_LIMIT`), then `429` with `Retry-After`.

## In Sypnia Cloud

A workspace is a Sypnia organization. The server reads your role from Sypnia (`GET /v1/me` of the control plane, on your behalf), keeps it for 60 seconds, and reads it again for every approval. Roles map like this:

| Role in the organization | Role in Cases                    |
| ------------------------ | -------------------------------- |
| owner                    | owner                            |
| admin                    | approver                         |
| developer                | editor                           |
| viewer                   | reviewer (plain level, comments) |

Members and their roles are managed in the organization; Cases only invites reviewers.

## Threat model

| Threat                                             | What stops it                                                                                                 |
| -------------------------------------------------- | ------------------------------------------------------------------------------------------------------------- |
| Someone approves beyond their role                 | the role is checked inside the transaction that creates the version                                           |
| An agent rewrites the scope                        | agents and project tokens can only open proposals; approval needs a person with the role                      |
| A leaked repository token                          | encrypted with KMS, the least access the sync needs (one repository, contents only), revocable from Settings  |
| Malicious text in a case (script, Markdown tricks) | case text is data: never rendered as HTML, escaped in every export                                            |
| A map reveals sensitive internals                  | the plain level hides data and code; table names show only to members                                         |
| History rewritten to hide a change                 | versions are insert-only, enforced by a trigger; the audit table records every action and refuses changes too |
| A request that skips CloudFront                    | with `CASES_ORIGIN_SECRET` set, the server answers only requests that carry the shared header                 |

## Checklist for self-hosting

- Put the server behind TLS; set `CASES_PUBLIC_URL` to the HTTPS address.
- Use a dedicated Postgres role for the server, without superuser, that owns the database (the compose file does this).
- Set `CASES_SECRET_KEY` (32 bytes) so tokens of other products are kept encrypted.
- Point `CASES_AUTH_ISSUER` only at an issuer you control.
- Give the repository token access to one repository's contents only.
