Security overview
What a customer's security review asks, answered from the code. Keep it true: when you change something this page describes, change the page in the same commit.
Architecture
One Node server (apps/server, Hono and Better Auth) with one SQLite database, behind Caddy. Files go to Cloudflare R2 when it's set up, otherwise into the database. The web app is static files. Published sites are served from their own domain (HATCH_SITES_HOST), which the server refuses to share with the API, so a site's scripts can never read the app's sign-in. See docs/architecture.md and docs/deploy.md.
Encryption
| Where | How |
|---|---|
| In transit | TLS on every domain, from Caddy (or Cloudflare in front, Full strict). HSTS on the app. Cookies are Secure on https. |
| Vault contents, end to end | Optional per vault. A passphrase becomes an AES-256-GCM key on the device (packages/sync/src/crypto.ts). The server stores only ciphertext and can't read it. |
| Files and backups at rest | R2 encrypts every object with AES-256. Backups go to R2 (below). |
| The database at rest | On the server's disk, so it's as encrypted as the host's volume. Use an encrypted volume (most cloud hosts do this by default). |
| Passwords | Hashed with scrypt by Better Auth. Never stored or logged in plain text. |
Sign-in and sessions
- Email and password, with confirmed email addresses once mail is set up.
- A forgotten password is reset by email (once mail is set up): "Forgot your password?" on the sign-in screen sends a link that works once, for an hour, to a plain form on the server (
apps/server/src/passwordReset.ts). Setting the new password signs out every session. The request answers the same whether or not the account exists. Signed-in people change their password in Settings, Account and sync, Security, which asks for the current one and signs out their other devices. - Two-step sign-in (Settings, Account and sync, Security): a code from an authenticator app after the password, with 10 single-use backup codes. Passkeys sign in with the device's fingerprint, face or PIN in the web app. The middle of a sign-in travels in a signed header instead of a cookie (
apps/server/src/authState.ts), so it works in the desktop and phone apps too. - People see every place they're signed in and can sign any of them out, or all but this one.
- Sessions last 30 days and are refreshed daily. Apps use bearer tokens, never cross-site cookies. CORS only allows the app's own origins and never sends credentials.
- Deleting an account deletes its vaults, sites, files and activity, and holds its site addresses for 30 days so old links don't land on someone else's site.
Who can see what
- A vault belongs to its owner. The owner can invite editors. Every route that touches owned data checks ownership, and
apps/server/src/policies.test.tsfails if a new owned route doesn't. - Workspaces give a team's members its vaults by role: owners and admins manage people, rules and vaults, members edit, viewers only read (the server refuses their changes). Removing someone takes their access away at once, including open live sessions. A workspace can require two-step sign-in before its vaults open, and keep invites inside email domains it has proved it owns with a DNS TXT record. Invite emails go only to addresses in those domains, and joining needs a confirmed address. Every change to people and rules is in its activity log.
- Single sign-on (OIDC or SAML) is set up per workspace, only for an email domain that workspace proved with its TXT record, and only by an owner who just entered their password. Hatch reads the provider's OpenID configuration itself through the public-only fetch, and Better Auth's own provider registration and sign-in endpoints answer 404. A provider only signs in emails in its own domain. The app holds bearer tokens, not cookies, so the browser trip ends with a one-time code (60 seconds, stored hashed) in the address fragment, bound to the browser that started it by an HttpOnly cookie, and redeemable only with the secret the starting tab kept (a PKCE-style challenge). The first single sign-on for an existing account links it and signs its other sessions out. Owners can make single sign-on the only way in for the domain: password sign-in, sign-up, resets and passkeys are refused there, and existing non-SSO sessions end. An owner must have signed in with it once first. It covers only the provider's own domain, and owners with an email outside it keep their password, so keep one such owner as a way back in if the identity provider ever breaks. Every change to single sign-on needs an owner who entered their password or signed in with single sign-on in the last 10 minutes, and emails every owner.
/api/sso/doneonly hands over a session that this workspace's provider made on its way back (recorded when Better Auth creates it), never another session in the same browser. An account nobody confirmed that already holds an address in the domain is taken back on its first single sign-on: its password, passkeys, two-step and sessions end. Since a fresh single sign-on counts as confirmation, whoever controls the identity provider can also change Hatch's single sign-on setup; every owner is emailed when that happens. Desktop and mobile sign in on the web for now. The OIDC setup, client secret included, is sealed in the database (AES-256-GCM, key derived fromHATCH_AUTH_SECRET,apps/server/src/sealed.ts), so a copy of the database or a backup alone doesn't give it away. Setups saved before sealing are sealed at start-up, with the old rows zeroed and the write-ahead log emptied; backups made before that still hold the plain secret, so rotate the client secret at the provider. Sealing hides the secret but doesn't stop someone who can write to the database: a plain setup is still read, and a sealed one isn't tied to its workspace. Changing the auth secret makes them unreadable, so owners would set single sign-on up again. - User provisioning (SCIM 2.0) lets a workspace's directory add its people and remove them when they leave, at
/api/auth/scim/v2with a bearer token. Each workspace has at most one token, made by an owner under the same rule as single sign-on changes, shown once and kept only as its hash. The directory can only provision addresses in the workspace's verified domains, so it can't create accounts for anyone else. Provisioned people join as members; deactivated or deleted ones leave the workspace and every session they have ends. People in the directory's group named "Hatch admins" (any case) are admins; leaving the group makes them members again, but only admins the group made (kept inscim_admin), so admins an owner chose stay. Once an owner changes such a person's role by hand, the directory leaves it until they leave the group. Turning provisioning off keeps roles and what the group made. Role changes by the directory say so in the activity log. Owners are never removed or changed by the directory. The directory can't move an account to an address outside those domains. Someone it deactivated doesn't come back in through single sign-on. Turning it off, or removing the last verified domain, ends the token and clears the directory's records, and keeps the people it added. Accounts the directory makes have no password: they sign in with single sign-on, or set a password by email, so pair it with one of those. - Published sites are public unless the owner makes them private.
- Server input is treated as hostile: size limits on everything, rate limits per visitor address, HTML sanitized by
packages/text. - Sign-in, sign-up, password reset and confirmation emails are rate limited per visitor network and per account (
apps/server/src/limits.ts), with counts kept in the database so a restart doesn't reset them. Accounts are stored hashed in those counts. Every try is counted before it runs, so guesses sent at once are stopped too. Two-step codes are also limited per account (10 wrong codes in 15 minutes), so someone who knows the password can hold the account's code step shut for a while; that also means the password is known, so change it. - Public forms (a site's forms, job applications, email updates, following a roadmap idea, the report page) can also ask Cloudflare Turnstile whether a person sent them, when the operator sets
HATCH_TURNSTILE_*(apps/server/src/turnstile.ts). Off by default. Only the widget's token goes from the server to Cloudflare.
Activity log
The server records who changed what on each site and vault (apps/server/src/audit.ts): publishing, domains, invites, removals, deletions and takedowns. Owners see their sites' activity, and everyone in a shared vault sees its activity. Details never hold note text or a visitor's personal data.
A workspace's owners and admins see its own activity (apps/server/src/activityStream.ts): people joining, leaving and changing roles, invites, rules, domains, sign-in setup, vaults in and out, and each member's sign-in (how, and the network it came from: the IPv4 address or the IPv6 /64) and wrong password, only in workspaces whose verified domains hold their address, and deleted with their account. They filter it by kind, person and time, download it as CSV (formula cells are quoted so a spreadsheet can't run them) or JSON, and choose how long it's kept (30 days to 10 years). An owner who just entered their password can send each new event to the company's SIEM: one https address on the public internet, signed with HMAC-SHA256 like form webhooks, tried a few times and then dropped, with the last failure shown in Settings. After 10 dropped events in a row it pauses until a test goes through. Changing or removing it first tells the old address, and emails every owner. Admins who aren't owners see only the address's origin, since collectors often put a key in the path. Downloads are recorded too.
Logs
The server writes one JSON line per request to stdout: time, request id, method, route pattern (/api/sites/:id, never the real path or query), status, milliseconds and, on signed-in vault and live routes, the account id. Never a body, a note, a header or a visitor's address. Every response carries an X-Request-Id, and a server error names it, so a customer can quote it and support can find that line. HATCH_ACCESS_LOG=0 turns the log off. /health answers only while the database does.
Backups and recovery
Litestream sends every database change to R2 within 10 seconds, takes a full copy daily and keeps 7 days, so a restore can go back to any moment that week (deploy/litestream.yml). The server never sees the backup keys. A heartbeat pings a monitor only while backups are getting through, so a stalled backup raises an alert.
| Target | Value |
|---|---|
| Most data lost if the server's disk dies (RPO) | 10 seconds |
| Time to be back on a new machine (RTO) | Under 1 hour: start the image with the same settings and it restores itself (docs/deploy.md, "Restore on a new machine") |
| How far back a restore can go | 7 days |
scripts/backup-check.sh backs up to a local S3, loses the disk and restores, end to end. Once a month the Restore drill workflow (scripts/restore-drill.sh) restores the real newest backup into a scratch file, checks it with SQLite's integrity check, and pings a monitor only when that worked, so a month with no good restore raises an alert.
Data kept, and for how long
| Data | Kept |
|---|---|
| Notes, files, sites | Until the owner deletes them or their account |
| Sessions | 30 days from last use |
| Activity log | 1 year (a workspace's own: what its owners choose, 30 days to 10 years) |
| Site visit counts (no cookies, no addresses) | 400 days |
| Job applications on careers sites | 90 days |
| Vault invites | 14 days if not accepted |
| Newsletter sign-ups nobody confirmed | Until the confirmation link expires |
| Billing events from Stripe | 30 days |
| Background jobs that failed | 30 days |
| Database backups | 7 days |
| Crash reports | Off unless the operator sets HATCH_ERROR_DSN. Never hold note text (docs/errors.md). |
| Performance traces | Off unless the operator sets HATCH_OTEL_ENDPOINT, and then only for people who turn on "Send performance traces". Route patterns, timings and counts, never content or who (docs/tracing.md). Kept by the operator's collector, not the server. |
An account export (Settings, Account) gives a person everything the server holds about them, including their activity.
What the apps send
Nothing by default. Each thing the app can send on its own has a switch in Settings, Privacy, off until turned on, with a plain list of what it sends. The apps never read sign-in or credential files from the device.
Service providers
Only the ones the operator turns on:
| Provider | For | Set by |
|---|---|---|
| Cloudflare (R2) | File storage and backups | HATCH_R2_*, HATCH_BACKUP_* |
| Resend or Postmark | HATCH_MAIL | |
| Stripe | Payments | STRIPE_SECRET_KEY |
| Sentry or GlitchTip | Crash reports | HATCH_ERROR_DSN |
| Any OpenTelemetry collector (Grafana, Honeycomb, a self-hosted one) | Performance traces | HATCH_OTEL_ENDPOINT |
| Cloudflare (Turnstile) | Telling people from scripts on public forms. The widget runs in the visitor's browser. | HATCH_TURNSTILE_* |
| The AI provider a person picks | The chat, with their own key, from their device | The person, in the app |
The code and its dependencies
- Every change goes through a pull request that runs typecheck, strict lint, unit tests and
pnpm audit(fails on high or critical advisories). Browser suites run before merging. - Dependabot proposes updates weekly and security fixes at once. New versions wait 3 days, and pnpm won't install anything less than a day old, so a hijacked release is usually pulled before it reaches us.
- GitHub Actions are pinned to commits. The checks’ token can only read. Only the desktop release and the Dependabot merge jobs can write, to publish a release and merge a safe update. Docker base images are pinned by digest.
- Only three dependencies may run install scripts (
pnpm-workspace.yaml). - The desktop app follows the Electron checklist: context isolation, sandbox, a narrow preload bridge (
apps/desktop).
Incidents
- Whoever spots it opens a private note with the time, what's affected and what's known. Severity: critical (data exposed or lost, or everyone down), high (one feature down, or a weakness with no known use), low (everything else).
- Contain first: take a site down (
pnpm --filter @hatch/server admin takedown), rotate a key, or stop the server. Keep the database and logs as they are. - Fix, restore from backup if needed, and check the fix.
- Tell affected customers within 72 hours of confirming that their data was exposed, with what happened, what data, and what we did.
- Write up what happened and the change that stops it happening again.
Access
- Production access is limited to the people who run the server, with keys that only the server and the operator hold. Settings live in the server's environment, never in the repo.
pnpm --filter @hatch/server check-configchecks them without printing any values. - GitHub accounts with access to the repo use two-factor sign-in.
- Someone who leaves loses access the same day, and any key they could see is rotated.
Reporting a problem
See SECURITY.md.