Skip to content
Select language:English

Security model

This page is the operator’s summary of Kept’s threat model and the mechanisms behind it. The developer pages go deeper: row-level security, sign-in and the architecture.

Kept connects to Postgres with four logins, each allowed only what its job needs:

Login Used by What it may do
kept_owner kept migrate, kept admin, the nightly backup owns the schema; never used to serve a request
kept_app every web request, instance-admin routes included reads and writes app tables, always under row-level security (NOBYPASSRLS, FORCE RLS on every table)
kept_auth sign-in (Better Auth) its own auth schema only
kept_system background jobs that span households (reminder scan, retention), the setup code explicit system policies only

Every request runs in a transaction that names the signed-in person, and every policy asks one function which locations that person belongs to. When no person is set, the policies return nothing, so a code path that forgets the scope fails closed. A schema-wide leak test checks the request, auth and worker paths. The depth is in row-level security.

What this means for you: requests never run as the owner. The process that runs the nightly backup holds the owner’s login, because a backup reads every table (the owner login); with Compose that is the kept container. The owner can do what the other logins can’t: change the schema and rewrite the audit log. Removing the two environment lines and the volume line from the kept service in compose.yaml takes it out of that container, and turns Kept’s own backups off. An instance admin has no in-app access to other people’s locations; an operator with database access can bypass that, which is why the database itself must stay private to the server.

  • KEPT_SECRET_KEY seals every secret value: secret fields on things, AI keys, notification channel settings, webhook secrets, email-in mailbox passwords, Paperless-ngx API tokens, the web push private key, the backup password. AES-256-GCM with a per-row data key, each ciphertext bound to its table, row and field, so one can’t be swapped for another.
  • KEPT_AUTH_SECRET signs sessions and tokens. It is separate so either can be rotated alone.
  • Generated on first boot when both are unset, into the config volume (never the data volume), with one log line saying where. Set them yourself with kept admin gen-key; boot refuses a key shorter than 32 bytes, and refuses one set without the other.
  • Neither is in the database or the backup. Keep the recovery kit. Without the secret key, a restore brings back everything except secret values and AI keys.
  • Rotation: kept admin rotate-key makes a new key current and re-wraps every sealed value; the old key is kept as a retired version so older backups still open. --resume finishes an interrupted run, --drop <version> removes a retired key nothing uses (the CLI).
  • Mailbox passwords are write-only: an email-in mailbox’s server, user name and password are sealed together; the page shows the server and user name, never the password.
  • AI keys are write-only: once saved, Kept shows only their last four characters.
  • Paperless-ngx tokens are write-only: a location’s Paperless address and token are sealed together; the page shows the address, never the token, and the browser never talks to Paperless with it. Thumbnails and downloads come through Kept, after Kept’s own access check.

Kept uses Better Auth on its own login and schema. What an account can sign in with:

  • Email and password. A password reset signs the account out everywhere, and the owner is told by mail when a credential changes.
  • Passkeys, registered for the host name of KEPT_PUBLIC_URL. Each must verify its user (Face ID, a fingerprint, a PIN) and be discoverable.
  • Two-factor with an authenticator app (TOTP) or a passkey that verified the user. An emailed one-time code is never a second factor. A location’s owner can require two-factor for everyone in it. Accounts without a password can use the authenticator app too.
  • Settings → Sign-in and security adds, renames and removes passkeys, and turns the authenticator app on, makes new backup codes, sets it up again and turns it off (Sign-in and security). Every change asks for the password, or a sign-in in the last ten minutes on an account without one, and signs out every other device (renaming aside). The server refuses removing the last way in, and turning two-factor off while a location requires it and the account has no passkey. Setting the app up again keeps the old secret working until a code from the new one is proven.
  • Magic links for existing accounts only (no open sign-up), valid 15 minutes. Mailed tokens travel in the link’s #fragment and are spent by a POST from the page, so a mail scanner that opens links can’t use them up; only a hash is stored.
  • Usernames for managed accounts (people without an email address).
  • OIDC, when KEPT_OIDC_ISSUER and KEPT_OIDC_CLIENT_ID are set (configuration). An outside identity is never linked to an account because the email matches; a new person gets in by invite, or by an allowed domain or group. The identity provider’s tokens are never stored.
  • Google, when KEPT_GOOGLE_CLIENT_ID and KEPT_GOOGLE_CLIENT_SECRET are set, with the redirect URI Admin → Status shows. The same rules as OIDC, except that nobody gets in by domain: only an existing account that linked Google, or an invited person.
  • Linking and unlinking an outside sign-in happen in Settings → Me → Sign-in methods. Linking needs a sign-in in the last ten minutes; unlinking asks for the password (or that recent sign-in on an account without one). An account keeps at least one way in.

Sessions last 30 days over HTTPS, extended once a day of use, with Secure, __Secure- prefixed cookies. Over plain HTTP they last 12 hours and are never extended, and Kept refuses the actions that reveal or change a secret (HTTPS). Sensitive actions ask for the password again, or a sign-in in the last ten minutes; renewing a sign-in doesn’t reset those ten minutes.

KEPT_HTTP_SIGN_IN_DAYS (1 to 30, unset by default) lets whoever runs the server make a sign-in over plain HTTP last that many days, renewed as it is used. It’s the one setting that loosens this, it can’t be changed from the app, and it does nothing over HTTPS. Secrets stay refused over HTTP, the ten minutes stay, and signing out everywhere still ends every sign-in. The cost: over plain HTTP a sign-in cookie can be copied by anyone who can see the traffic, and with the setting on, a copied one keeps working for as long as it’s used, until that device signs out or your other devices are signed out (Staying on your network).

Requests from other sites are refused: a write that carries Kept’s cookie must come from the origin of KEPT_PUBLIC_URL, or it gets 403 before the session is even read. So must first-run setup, which has no cookie yet, before its setup code is tried.

KEPT_EXTRA_ADDRESSES (unset by default) lets whoever runs the server list other exact origins that count as Kept. They’re read once at startup and compared whole against the browser’s Origin; Host and X-Forwarded-* play no part. A wildcard, or a mix of http and https, stops startup. The refusal names KEPT_PUBLIC_URL and never the list. Passkeys, outside sign-ins, OAuth and every link stay on KEPT_PUBLIC_URL: a passkey is checked against that address whatever the request says. The cost: a page served at a listed address can act for whoever is signed in there (More than one address).

The pages are served with a default-src 'self' content security policy, may not be framed, and get HSTS when the public URL is HTTPS, unless KEPT_HSTS=off (HSTS).

As built:

What Limit
Sign-in attempts 5 a minute per address; per account and address, 20 an hour, with delays that grow after the fourth failure (up to 5 minutes) rather than a lockout
Other auth routes 100 a minute per address and route
API and MCP, per token 120 reads and 30 writes a minute
Password reset and magic link 3 an hour per account
A share link’s page 60 views a minute per link

Limits are kept in the database, so replicas share them. The client’s address comes from the socket, or from X-Forwarded-For only when the connection is from an address in KEPT_TRUSTED_PROXIES (reverse proxies).

Kept fetches only addresses someone configured: an AI provider’s base URL, webhooks, push, an OIDC issuer, an OAuth client’s metadata, a Homebox server to import from, barcode lookups, the update check, a location’s email-in mailbox (IMAP) and a location’s Paperless-ngx. Each goes through the same guard (apps/server/src/net/ssrf.ts):

  • the address is checked when the connection is made, after the name resolves, so a name that changes between a check and the request can’t slip through;
  • private, loopback, link-local (including the cloud metadata address), carrier-grade NAT, multicast and reserved ranges are refused, IPv4 and IPv6;
  • redirects are refused, so a public host can’t bounce the request inward.

A refused address is 400 private_address. On a self-hosted server an instance admin can allow private addresses (Admin → Settings → Allow private addresses), which a provider on your own network, such as Ollama, needs. It is off by default.

Imports and uploads are treated as hostile. The defaults:

Limit Default
Import ZIP 5 GB uncompressed, 100:1 compression per entry, 200,000 entries, no symlinks
Images decoded up to 100 megapixels, one at a time under 3 GB of RAM or a container limit under 3 GB
PDFs parsed in a child process, 20 s and 256 MB
Uploads KEPT_MAX_FILE_MB (25 MB by default), refused before the body is read

Stored files are fetched through a five-minute signed link on a path that reads no session, with nosniff and a default-src 'none'; sandbox policy, and as a download unless the file is one of Kept’s own re-encoded JPEGs. Exported CSV cells that start like a formula are neutralised.

  • Nothing about Kept itself. There is no telemetry of any kind; the sign-in library’s own telemetry is switched off. Tracing and error reporting go only to a collector you set (monitoring).
  • The update check is off by default. On, it asks GitHub for the latest release once a day, and once after an upgrade, sending nothing but the request (upgrades).
  • What an AI provider sees, when a location uses one: photos as a re-encoded copy with EXIF and XMP removed (Kept refuses to send an image that still has them), the fixed prompt and the location’s languages for extraction, the question and the tool results the asker’s role allows for the assistant, and descriptive fields for semantic search. Never secret values, and never money for search. Kept’s own record of each call stores tokens and cost, never the prompt, the image, the reply or the key. See AI providers.
  • Share links (/s/<token>) are the one page anyone can open without signing in. The token is 32 random bytes, shown once and stored as its SHA-256; it never reaches a log line. The page is read through one database function that takes the token’s hash and returns only names, types, where things are, quantities, condition, notes and photos, for the shared box, place or search in that location. Photos are previews with GPS removed, as five-minute signed URLs, and only for those things. A link stops when it is revoked or expires, or when its maker no longer administers the location; it is checked on every view.
  • Backups are restic snapshots encrypted with a password of at least 12 characters before they leave; with no password there is no backup (backups).

Use GitHub’s private vulnerability reporting on the repository (the Security tab → Report a vulnerability); it is the only channel, and there is no security email address. Don’t open a public issue. SECURITY.md has the details and the supported versions, which apply from 1.0. To check that an image is the one the maintainer built, see verifying a release.