Threat model
The written risk assessment for the app. It's a skeleton: each threat has one line for the risk, what controls it today and what's still missing. Later work fills in the detail and adds threats as features ship.
"Today" means what this repo already enforces. Nothing is deployed yet, so most runtime controls are still gaps.
Account takeover
- Risk: someone signs in as a household user and reads or changes household money data.
- Current control: server-side role checks on every route (a table of who may call what, with a test that fails on an unlisted route; ADR 0018, data model). Every API route but
/api/healthneeds a login, the role is read from the database on every request (never from the token), and the Worker verifies the Access token (next section). Nothing is deployed yet, so there is no runtime sign-in yet. - Gap: sign-in through Cloudflare Access with MFA (set up in Cloudflare, not in this repo), rate limits on sign-in and money endpoints, recovery codes for each user.
Forged or unsigned login token
- Risk: someone calls the API directly with a made-up
Cf-Access-Jwt-Assertiontoken (unsigned, signed with the wrong key, another team's or application's token, expired, or with a swapped algorithm such asnoneor HS256) and is treated as a household user. - Current control: the Worker verifies the token on every request outside local development: RS256 signature against the keys Access publishes for the team domain (picked by
kid, never from a URL in the token), issuer equal to the team domain, audience containing this application's tag,expandnbfwith a 60 second tolerance, and asubthat matches a known, unarchived person. Anything else is the same 401. A deployment without the two settings (TEAM_DOMAIN,POLICY_AUD) refuses every sign-in. The unsigned stub login is only on withAUTH_MODE=stub, which only the local config and tests set. Unit and route tests cover each check, with generated keys and no network. The Worker also treats everything under/api/dev/(the local-only tools) as a plain 404 for everyone, signed in or not, wherever the clock override is off. That is before the login on purpose, so the deployed check can see it; it reveals only that thedevprefix is special (every other unknown path is a 401 before login), no data, and everything else still fails closed with a 401. - Check from outside:
npm run security:check -- https://<site>(see Deploying) makes a few requests with no login and fails if any of them gets household data back, if the Worker's headers are wrong, ifX-Nowis accepted, or if a cross-origin header is open. Behind Access it can only see Access's answer: it proves "no data without a login" and reports the Worker's own headers, its 404 and itsX-Nowrefusal as not seen. It never sends a credential. - Gap: the Access application's policy and MFA live in Cloudflare and are set by hand; the config generator never writes
AUTH_MODEorNOW_OVERRIDEand its tests prove it, but nothing checks a deploy config written by hand (deploy only with the generated one, see Deploying); the Worker is also reachable on its own URL if that is left switched on, and on a custom domain ifCUSTOM_DOMAINis used (Access must cover each address before it is deployed, see Deploying): there the API (/api/*) answers 401 without a valid Access token, but the static app files are public (they hold no household data); a stolen valid token works until it expires; no per-person revocation beyond archiving the person; no stale-key fallback (fail-closed): if Cloudflare's key endpoint is down after the 10 minute key cache expires, every sign-in is 401 until it returns.
The public demo leaks something
- Risk: the demo is opened to strangers and gives away a real login, an email address, household data or a secret, or lets a stranger store or spend something.
- Current control: the public demo is the built files and nothing else (ADR 0021): its config has no Worker code, database, bucket, Cron Trigger, variable or secret, and the files are the made-up Addams household running in the visitor's own tab. There is nothing behind them to read or write, so a stranger can't store anything, reach SimpleFIN, or make the server do work. The generator's output is a fixture, and tests fail if a binding, variable or
mainappears in it. A bundle test fails if the default build holds an email address, a Cloudflare Access address, cookie or token header, or the API client.npm run security:check:public -- https://<site>asks the live site, as a stranger, whether Access is still in front, whether the CSP and the other headers are strict, whether any/apiaddress answers with data, whether a cookie or a cross-origin allowance is set, and whether the files are the demo build. - Check from outside: the command above; it sends GET requests only, with no login, and never prints a body.
- Gap: the account still holds what the Access-protected demo left (its D1 database with the linked login, the backup bucket, any Worker secrets, the Access application and its policy emails) until someone deletes it (docs/deploy.md, Public demo, step 6); nothing in the repository can; per-address rate limiting is an optional Cloudflare edge rule, not code; the demo is indexable by search engines (except
/gallery); the source maps of the demo are public (so is the source).
The stored SimpleFIN connection leaks
- Risk: the SimpleFIN access URL (it carries the bank bridge's credentials, so it can read account data) is read by someone who shouldn't: from the database or a backup, from an API answer, a log line, an error message or the audit log, or by a Member.
- Current control: the admin pastes a one-time setup token; the Worker claims it and keeps the result encrypted in one column of the existing Settings table (AES-256-GCM, a fresh random 12-byte nonce on every write, authenticated, with the row's name bound in as additional data) under the
SETTINGS_KEYWorker secret. The database, a backup or a D1 export holds ciphertext only. No route returns it: Settings status is connected or not connected, and a stored value the current key can't open is "unreadable", never shown. Every other read of Settings selects columns that leave the sealed one out (a test greps for a bare read). Only an Admin may call any SimpleFIN route (a Member is 403 before the body is read). Nothing in the SimpleFIN code logs; errors and refusals carry fixed words, never the token, the address, the answer or the thrown error; the audit line says only that a connection was made or removed. A scan test reads every GET route (and each write's answer) as the Admin, a Member and nobody, with and without the key, for the stored value, its ciphertext, the setup token and the keys. The key is a secret binding, never a variable: the config generator never writes or prints it (a test sets it and looks). Requests to the bank bridge send the credentials as a BasicAuthorizationheader split from the address, never inside the URL. The key is checked before the token is sent anywhere, so a missing key doesn't use the token up. A connection that opens is never silently replaced by a second paste ("Disconnect first", token not used); one the key can't open may be. A write that stores nothing leaves no audit line. The key must not be one repeated byte, and the claim host may not end in a private-use name (local,internal,test,example,svc,onion, ...). - Gap: anyone who can read the Worker's secrets (a Cloudflare account owner, a deploy token with Workers secrets access) can decrypt a stolen database copy; the key and the database live in the same Cloudflare account. There is no automatic re-encryption on key rotation (the next connect re-seals it, see Deploying). A claimed token whose answer could not be saved is lost (Settings says so and what to do); the access URL is in the Worker's memory for the length of that one request.
Pasted setup token points somewhere it shouldn't (SSRF)
- Risk: a setup token is Base64 text of a URL, so the Worker would fetch an address from pasted text: an internal address,
localhost, plainhttp, an address with credentials, or a redirect to one, and could be used to probe or send data to places the admin never meant. - Current control: only the admin can paste one. Before anything is fetched the address must be
https, have no credentials and no port, and a public-looking host name: letters, digits and dashes in labels of at most 63 characters, at least two labels, a last label of letters only (so no IP address in any spelling: dotted, a single number, hex, short or IPv6 form), and notlocalhostor a private suffix (local,internal,lan,home,corp,arpaand others). The request is a POST withredirect: "manual": a redirect is a refusal and is never followed. There is a 10 second limit, the answer is read up to 2 KB, and the access URL in it must itself pass the same address check and carry a user name and password.httpis never fetched. - Gap: the host name is checked by its shape, not looked up in DNS, so a public name that points at a private address isn't caught by the check itself; a Worker's
fetchcan't reach a private network, which is what covers it. The claim host isn't limited to SimpleFIN's own domains (a self-hosted bridge is allowed): pasting a token for another public site makes the Worker POST to that site, once, and nothing the site answers is shown or kept unless it is a valid access URL.
Leaked deploy token
- Risk: a leaked Cloudflare token lets someone deploy their own Worker or read and change the database.
- Current control: gitleaks in the pre-commit hook and in CI, GitHub secret scanning with push protection,
wrangler.jsoncholds no account IDs or secrets, nothing with secrets runs on fork PRs (ADR 0009). - Gap: deploy tokens scoped to Workers + D1 + R2 only, a separate token per Cloudflare account, deploys only from
main, yearly rotation. A billing alert at $1 is in the runbook; it is set by hand and not checked here.
Bad npm package
- Risk: a compromised or malicious dependency runs code in CI, on a laptop or in the Worker.
- Current control: lockfile +
npm ci, Dependabot, actions pinned to SHAs behind an allow list (ADR 0009), CodeQL and ESLint security rules. - Gap: a written rule for vetting new dependencies (keep them few), and a check on install scripts.
Lost phone
- Risk: a lost or stolen phone with the installed app gives someone a signed-in session.
- Current control: none yet (no deployed app).
- Gap: short Access sessions, a way to revoke a device's session, and steps in the runbook for a lost phone.
Worker bug
- Risk: a bug in the Worker leaks data across roles, corrupts money values or exposes errors with data in them.
- Current control: strict TypeScript, money in integer cents (ADR 0006), unit tests in workerd, a strict CSP and security headers proven in CI (ADR 0011), Claude review on the owner's PRs.
- Current control, roles: authorization tests for every route and role (
roles.test.ts,masking.test.ts). - Current control, errors: anything a route throws, a database error included, is a 500
internalwith one fixed sentence: no message, SQL, stack or row value. Only the error's kind is logged (Unhandled Error). A test makes the database fail at three different points, with SQL, a note and a token in the failure's own text, and checks neither the answer nor the log holds any of it (security-headers.test.ts). - Current control, logs: audited: the only
consolecalls in the Worker are that one line and the backup job's one line, which writes a fixed sentence per problem (never a key, row or table value). No request body, token, note, amount or query is logged, and a test fails if anotherconsolecall appears. Tests also run successful, refused, forged-token and failing requests with sentinel notes and amounts and check nothing is written. Unconfirmed: what Cloudflare's own Workers observability records about a request (the generated config turns it on). Its invocation logs are Cloudflare's, not this code's, and may include the request's address and query string (dates, never amounts, in this API's queries). Look at one in the dashboard before relying on this, and keep money and names out of query strings. - Current control, headers: every
/api/*answer, errors and 404s included, carriesCache-Control: no-store,Strict-Transport-Security(two years,includeSubDomains),frame-ancestors 'none'andX-Frame-Options: DENY,nosniff,Referrer-Policy: no-referrerand a closedPermissions-Policy; no CORS header is ever sent. The static files carry the same HSTS and framing rules. Unconfirmed: whether a bare/api(no slash) reaches the Worker in production (run_worker_firstis["/api/*"]), and whether a zone's edge HSTS setting would replace the Worker's value.
Lost or damaged data
- Risk: the database is lost or corrupted (a bad migration, a bug, a deleted database, a lost or taken-over Cloudflare account) and the household's history goes with it.
- Current control: a nightly backup of every data table, compressed and encrypted (AES-256-GCM, a fresh random nonce for every object, the backup's day authenticated so a file can't be passed off as another day's) with a key that is a Worker secret, into its own R2 bucket: 14 daily and 8 weekly copies, deleted only by the backup's own naming scheme, never written unencrypted (a missing or bad key fails the job with a plain message and writes nothing). Tests cover the encryption (wrong key, any changed byte, a changed or swapped day, a decompression bomb), retention, idempotence, a failed try being repeated the next hour and a dump that loads into an empty database with identical rows. D1's own Time Travel (30 days on the paid plan) is a second layer. Steps for the restore drill, the monthly off-site copy and the alerts are in the runbook.
- Gap: the restore drill has not been run on a real account; the hourly Cron Trigger that starts the job is in the generated config but has never been seen firing on a real account; the billing alert (at $1) and the Worker-errors alert are set by hand in the dashboard and are not checked by anything here; the backups and the database are in one account, so the monthly off-site copy is manual; nothing alerts if the backup silently doesn't run (the job-health check is still a stub), so the monthly look at the bucket is the only detection; a failed backup is retried for 6 hours after the backup hour and then the night is lost; a dump over 24 MiB is refused until the job streams it, and the append-only
audit_logandpull_logmake the dump grow every day (a real household's size is unmeasured).
Backup key lost or leaked
- Risk: lose the key and every backup is unreadable; leak it and anyone who also gets a backup object (they are in the same Cloudflare account) can read the household's data.
- Current control: the key lives only as a Worker secret (never in a config file, the generated config or the repository; a test proves the generated config holds no secret and the decrypt script refuses a key on the command line). A bad key stops the job loudly instead of weakening the encryption. The runbook says to keep the key in two independent places outside the repository and to keep an old key until the backups written under it have aged out.
- Gap: where the owner keeps the key is the owner's call and nothing checks it; there is no automatic key rotation (a new key applies to new backups only); a Worker secret can't be read back, so a key held only there is already lost.
Data dump
- Risk: a bulk copy of household money data leaves the app: a script that reads every route with a stolen token, a database export or backup that ends up somewhere it shouldn't, or real data pasted into a place that is public (a pull request, an issue, a log).
- Current control: there is no export, download or "dump everything" route: every read is one page of data for the signed-in person's role, with other people's private envelopes masked and the trust balance Admin-only; the entries list covers at most 366 days at a time; answers are
no-store, so a browser or proxy keeps no copy. A signed-in token is needed for every read, so a dump needs a live login (see the sections above for what stops a forged one). The repository is public and holds only the fictional Addams household: gitleaks and GitHub push protection watch for secrets, and the repo's own rules ban real amounts, names and account numbers everywhere, including logs and test data. The import tool's own files (the household's real history) stay on the owner's computer. - Gap: a stolen valid token can still read everything its person may read until it expires, and nothing limits how fast it reads (no rate limits yet). A database export (
wrangler d1 export) or a Cloudflare dashboard download is made by someone with the Cloudflare account, and the repo can't see where that file goes: keep one only on the owner's computer, never in a chat, ticket, pull request or shared drive, and delete it when done. The nightly backup is encrypted and kept in its own bucket (see "Lost or damaged data"); a restored or downloaded copy is as sensitive as the database itself. Unconfirmed: that Cloudflare's own audit logs would show an export; check this in the dashboard when production is set up.
Parent-domain cookie tossing
- Risk: a compromised parent domain sets cookies for the app's subdomain and fixes or hijacks a session.
- Current control: none yet (no deployed app).
- Gap: the app on its own domain, not under a shared parent domain;
__Host-cookies only, and the app ignores every other cookie.
Demo account abuse
- Risk: someone hammers the public demo, uses up its quota or tries to reach production through it.
- Current control: the demo's database holds only the fictional Addams household and the demo config is generated separately from production (its own Worker name, no shared bindings), so a visitor who gets in learns nothing real. The demo sits behind Access like everything else, so an anonymous visitor reaches only Access's login and the Worker's
/api/healthis never seen unless Access is off. The deployed-site check (Deploying) shows that an unauthenticated visitor gets no data from the demo, and no dev routes or clock override. Nothing is deployed yet, so none of this has been run against a real demo: unconfirmed until someone runs the check on one. - Gap: the demo on a separate Cloudflare account with its own deploy token and no production bindings or secrets (a convention in the deploy guide, not something the repo enforces), rate limits on its API (none: Access is the only gate, and its own limits are Cloudflare's), a nightly reset, a quota alert. If the demo is ever opened to the public without Access, every one of these becomes a requirement, and the check's "never data without a login" rule has to be replaced with a rule for what a public visitor may see.