# Threat model (/docs/operate/threat-model)



This page lists the realistic ways Decision Control can be attacked, the control that answers each
one, and, just as important, what is **not** covered yet. It is written from the code and its
tests, not from intent: each control names where it lives. It is not a penetration test; none has
been done by a third party yet (see [Known gaps](#known-gaps)).

Review it whenever a node type, an integration or an authentication path is added.

## What is being protected [#what-is-being-protected]

| Asset                              | Why it matters                                                                    |
| ---------------------------------- | --------------------------------------------------------------------------------- |
| **Decision logic** (flows, tables) | It encodes credit, fraud and pricing policy. Tampering changes real decisions.    |
| **Execution records**              | The audit trail, and the place personal data ends up (input, output, trace).      |
| **Credentials and connections**    | Bearer tokens, basic auth, broker and database secrets of the customer's systems. |
| **API keys and sessions**          | Anything that can run decisions or change them.                                   |
| **Tenant boundaries**              | One workspace or project must never read or change another's.                     |
| **Availability of `/execute`**     | Callers depend on an answer in milliseconds.                                      |

## Actors [#actors]

* **Anonymous internet**: reaches the console, `/api/v1/auth/*`, public forms and `/demo`. A public
  form runs its pinned version's integrations; it delivers actions (outbox) only when its author
  turns on **Run actions**, and a protected environment's credentials need `deploy.protected`.
* **Caller with an `execute` key**: chooses the payload (and therefore every value an expression sees).
* **Flow author**: a business user who writes URLs, expressions and regular expressions that the
  platform then runs. Authoring is trusted to *compose* rules, not to run code or reach the network
  freely.
* **Member with a low role** (viewer, editor): tries to read or change what the role excludes.
* **Compromised dependency or build**: the supply chain.
* **Insider with database or log access**: reads personal data or alters history.

## Boundaries [#boundaries]

`Browser ⇄ nginx ⇄ API ⇄ Postgres / Redis`, and from the API outwards: customer services (`apiCall`),
webhook and event destinations, identity providers, the AI provider. The embedded runtime
(`@decision-control/runtime`) runs the same engine in the customer's own process.

## Threats and controls [#threats-and-controls]

| #  | Threat                                                                   | Control                                                                                                                                                                                                                                                                                                                                                                                   | Where                                                     |
| -- | ------------------------------------------------------------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------- |
| 1  | **SSRF**: an author points an `apiCall` at metadata or internal services | Loopback, private, link-local and metadata addresses refused; the name is resolved once and the connection goes to the checked address (no DNS rebinding); redirects not followed; response capped at 2 MiB; private hosts only via an operator allowlist.                                                                                                                                | `engine/security/url-guard.ts`, `adapters/http-client.ts` |
| 2  | **ReDoS**: a pattern or a payload makes `matches` take exponential time  | Patterns run on a linear-time automaton, not on `RegExp`; length of pattern (500) and subject (20,000) capped; features that need backtracking (backreferences, lookaround) are rejected with an error.                                                                                                                                                                                   | `engine/security/safe-regex.ts`                           |
| 3  | **Resource exhaustion** by a flow or a payload                           | Per-flow step limit, a **total** step limit and a **time limit** across nested decisions, a cap on what `forEach`/`parallel` may hold, a fan-out cap, nesting depth 5 with cycle detection, `apiCall` timeouts bounded by the time left, payload size limits, per-key rate limits, load shedding with `503`.                                                                              | `engine/flow/budget.ts`, `services/execution.ts`          |
| 4  | **Code execution** through rules                                         | There is no script node and no `eval` in the engine: rules are JSON evaluated by an interpreter.                                                                                                                                                                                                                                                                                          | `engine/expression`                                       |
| 5  | **XSS in the console**                                                   | React escaping; `Content-Security-Policy` with `script-src 'self'` and no `unsafe-inline`; session cookie is `HttpOnly`; no credential in browser storage (a test fails if a storage key looks like one).                                                                                                                                                                                 | `apps/web/docker/security-headers.conf`                   |
| 6  | **Clickjacking, sniffing, downgrade**                                    | `frame-ancestors 'none'`, `X-Frame-Options: DENY`, `nosniff`, HSTS, `Permissions-Policy`.                                                                                                                                                                                                                                                                                                 | nginx snippet, `lib/security-headers.ts`                  |
| 7  | **CSRF** on cookie-authenticated calls                                   | `SameSite=Lax` and an origin check: state-changing cookie requests from an origin that is not `WEB_ORIGIN`, `PUBLIC_URL` or `CORS_EXTRA_ORIGINS` get `403`.                                                                                                                                                                                                                               | `lib/origins.ts`                                          |
| 8  | **Credential stuffing and brute force**                                  | Rate limits per client address and per email (shared across replicas through Redis, falling back to Postgres); a lockout that counts *failures* per (account, address) pair, with a higher ceiling on the account, so typing a victim's address cannot lock them out; 12-character passwords; optional CAPTCHA at registration; optional TOTP and SSO; 2FA can be required per workspace. | `lib/login-guard.ts`, `lib/rate-limit.ts`, `modules/auth` |
| 9  | **Session theft or fixation**                                            | `HttpOnly`, `Secure` (production), `SameSite=Lax`; server-side sessions revoked on sign-out; idle timeout; rotation and revocation of other sessions when 2FA changes or a password resets.                                                                                                                                                                                               | `lib/session.ts`                                          |
| 10 | **Cross-tenant access, privilege escalation**                            | Every request is scoped to a project whose membership is re-checked on the server; routes not listed in the permission table need `project.manage` (closed by default); API keys can never hold admin permissions; a cross-authorization test suite exercises every role.                                                                                                                 | `services/permissions.ts`                                 |
| 11 | **Tampering with history**                                               | Executions are sealed into a per-project SHA-256 chain; verification names the first broken link; exports are hash-summed and can be signed (Ed25519).                                                                                                                                                                                                                                    | `services/chain.ts`                                       |
| 12 | **Secrets exposed** at rest, in traces or in exports                     | AES-256-GCM with rotation; flows store a credential *reference*; auth headers and secret-looking query parameters are redacted before anything is written.                                                                                                                                                                                                                                | `lib/crypto.ts`, `engine/security/url-guard.ts`           |
| 13 | **Personal data kept longer or more widely than needed**                 | Fields marked sensitive are masked before the record is written and sealed; retention is configurable per project; a person's data can be erased without breaking the chain.                                                                                                                                                                                                              | `lib/personal-data.ts`, `services/personal-data.ts`       |
| 14 | **Forged webhooks** to the customer, or replay                           | Deliveries are HMAC-signed; per-webhook secrets; the same outbound screening applies.                                                                                                                                                                                                                                                                                                     | `modules/webhooks`, outbox                                |
| 15 | **Vulnerable or malicious dependency, leaked secret, vulnerable image**  | `bun audit`, secret scanning of the whole history and an image scan **fail the build**; frozen lockfile; dependency overrides for patched transitive versions.                                                                                                                                                                                                                            | `.github/workflows/security.yml`                          |
| 16 | **A migration that locks the busiest table**                             | Migrations after the baseline are linted for blocking operations, and can be rehearsed against a table with millions of rows.                                                                                                                                                                                                                                                             | `docs/MIGRATIONS.md`                                      |

## Known gaps [#known-gaps]

These are open on purpose or not yet done. None is hidden by the controls above.

* **No external penetration test.** Everything here is from reading and testing our own code.
* **The public playground (`/demo`) allows `unsafe-eval`** in its own Content-Security-Policy,
  because it runs the engine in the browser and its schema validator generates code. Only that
  page; the console keeps the strict policy. Entry and exit links reload the document so the two
  policies never mix. It holds no session of its own, but a signed-in person's cookie is sent to the
  same origin.
* **Masking has limits.** A sensitive value is masked at its path and wherever the same value of
  4 or more characters appears in the rest of the record. A shorter value, or a value that the flow
  transforms (hashing, formatting, splitting), is not found. Cases, deliveries and feature
  observations carry the real values because they exist to act on them; erasure removes them.
* **Erased records weaken the chain slightly.** An erased execution's own link and metadata can no
  longer be recomputed, so they are taken as stored. Changing the last erased link of a run, or
  removing a record, is still detected; changing an erased record's status or a hash strictly inside
  a run of erased records is not. Verification reports how many records it took that way.
* **The master encryption key lives in an environment variable.** There is no KMS or envelope
  encryption; there is no per-field encryption of stored personal data.
* **Sign-in lockout has no progressive back-off, and the CAPTCHA guards registration, not
  sign-in.** Passwords need 12 characters and avoid a list of common ones, but are not checked
  against known breaches.
* **No passkeys/WebAuthn and no IP allowlist per workspace.**
* **The container image is not pinned by digest, signed or accompanied by an SBOM.**
* **One dependency advisory is waived** (`braces`, no patched release; reachable only through a
  development-time CLI). It is recorded next to the check and reviewed when a fix ships.
* **Availability behaviour under dependency failure** (Postgres down) answers `500` after a long
  wait instead of a fast `503`; see the performance backlog.

Open items are tracked in `TODO.md`.
