# Security posture (/docs/operate/security)



## No `eval` [#no-eval]

Rules are data, evaluated by a **JSONLogic interpreter**. There is deliberately no node that
runs arbitrary JavaScript: a `script` escape hatch would end "rules are data", and sandboxing
one properly is a runtime we would have to keep secure forever. Code that genuinely needs a loop
over a payload belongs in a service, called by an `apiCall` node. Everything else is covered by
the expression vocabulary, `calculate` and the table cells.

## Outbound calls are screened [#outbound-calls-are-screened]

Business users author URLs, so requests to loopback, private, link-local and cloud metadata
addresses are refused, redirects are not followed, response size is capped, and the resolved
address is re-checked by the HTTP adapter. Services on a private network are reachable only if
an operator allowlists them explicitly: `OUTBOUND_ALLOWED_HOSTS="api.internal,*.corp.example"`.

The name is resolved once, every address is checked, and the connection goes to the checked
address, so a hostile name server cannot answer differently the second time (DNS rebinding).
Webhook deliveries from the outbox take the same path.

## Secrets are encrypted at rest [#secrets-are-encrypted-at-rest]

**AES-256-GCM**, key from the environment. A flow stores a credential **reference**, so the graph
can be exported without leaking anything. The key rotates without downtime: move the old one to
`CREDENTIALS_ENCRYPTION_KEYS_PREVIOUS`, set a new `CREDENTIALS_ENCRYPTION_KEY`, deploy, then run
`bun run credentials:rotate` in `apps/api` — it re-encrypts credentials, connections, webhook
secrets and two-factor secrets.

**Credentials never reach the trace.** Auth headers and secret-looking query parameters are
redacted before anything is written, and there is a test asserting it.

## API keys [#api-keys]

Stored as a hash plus a lookup prefix, compared in constant time, carry scopes that are enforced,
and have a per-key rate limit.

## Rate limits hold across replicas [#rate-limits-hold-across-replicas]

Counters live in Redis (one atomic script per hit), so several API instances share one budget.
If Redis cannot answer, the hit is counted in Postgres instead: limits stay enforced during an
outage. Sign-in, sign-up and password reset are limited per client address and per email address.
`X-Forwarded-For` is honoured only with `TRUST_PROXY=true`, because without a proxy that
overwrites it the caller chooses its value. Behind a reverse proxy such as Dokploy's Traefik, the
bundled nginx reads the client address from the proxy's `X-Forwarded-For`, trusting only
private-network peers.

## Two-factor authentication (TOTP) [#two-factor-authentication-totp]

Anyone can add an authenticator app (**Settings → Security**): the secret is encrypted like a
credential (and rotates with the key), counts only once a code confirms it, and comes with ten
single-use recovery codes stored hashed. With it on, `POST /auth/login` answers a five-minute
challenge bound to the password hash instead of a session, and `POST /auth/login/2fa` completes
it; a code is refused for its step once used, and guesses spend the account's own sign-in budget.

A workspace admin can **require** it: members without it get `TWO_FACTOR_REQUIRED` from the
workspace's projects until they turn it on. Sign-ins, failures and every 2FA change are in the
audit log.

## Single sign-on and SCIM [#single-sign-on-and-scim]

A workspace admin adds an identity provider (**Settings → Single sign-on**):

* **OpenID Connect** (authorization code with PKCE, state and nonce, ID token checked by
  `openid-client`).
* **SAML 2.0** (SP-initiated, signed assertions required, checked by `@node-saml/node-saml`).

The console routes an address to its provider by domain, and a provider only signs in addresses
in its own domains. With **Require SSO**, password sign-in is refused for those domains
(`SSO_REQUIRED`), except for owners — the way back in when the provider is down. First sign-ins
can create the account and join the workspace.

**SCIM 2.0** (`/api/v1/scim/v2`, a workspace bearer token shown once) creates, updates,
deactivates and removes people and pushes groups; a group mapped to a project grants it with a
role (and custom role), and that access follows group membership, while access set by hand is
never touched.

Issuer and IdP endpoints are screened like any outbound call. `PUBLIC_URL` sets the origin used
for redirect and ACS URLs when it is not `WEB_ORIGIN`.

## Password reset [#password-reset]

The token is signed, expires in an hour, and is bound to the current password hash: once the
password changes, the link stops working, with no table of spent tokens. A reset signs every
session out.

## The console is authenticated [#the-console-is-authenticated]

Every management endpoint needs a session, carried in an httpOnly cookie (`dc_session`). The
session is a row, so signing out revokes it for real and expiry is enforced on every request;
passwords are hashed with argon2id through `Bun.password`.

A session also ends after `SESSION_IDLE_TIMEOUT_DAYS` (7 by default) without a request. Turning
two-factor authentication on or off gives the session a new token and ends every other session
of the account, so a token that leaked earlier stops working.

Each request acts on the project in `x-project-id`, and membership is re-checked server-side —
a stale selection in a tab grants nothing.

## The console sends a strict Content-Security-Policy [#the-console-sends-a-strict-content-security-policy]

nginx serves the console with `script-src 'self'` — no inline script and no `eval`, so an injected
`<script>` or event handler does not run — plus `frame-ancestors 'none'`, `object-src 'none'`,
`base-uri 'self'`, `form-action 'self'`, `connect-src 'self'`, HSTS and a restrictive
`Permissions-Policy`. Styles keep `'unsafe-inline'` because the UI libraries set `style`
attributes at run time. The one exception is the public playground (`/demo`), which runs the engine
in the browser and so is allowed `'unsafe-eval'`; see the [Threat model](/docs/operate/threat-model).
No credential is kept in browser storage: the session is an `HttpOnly` cookie, and a test fails if a
new storage key looks like one.

## What one execution may spend [#what-one-execution-may-spend]

A flow is limited to 500 steps, but a `forEach` that calls a decision, or an `apiCall` that waits
120 s per attempt, could multiply that. Every execution therefore also has a **total** step budget
shared by the decisions it calls (`EXECUTION_MAX_TOTAL_STEPS`), a **time limit**
(`EXECUTION_TIMEOUT_MS`, which also caps each outbound call and its retries), a cap on what
`forEach` and `parallel` may hold in memory (`EXECUTION_MAX_COMPOSITE_BYTES`), at most 25 parallel
branches, nesting of at most 5 levels with cycle detection, and a 2 MiB cap on any response an
`apiCall` reads. Hitting one fails the execution with `STEP_LIMIT_EXCEEDED`, `EXECUTION_TIMEOUT` or
`RESULT_TOO_LARGE`, with the trace up to that point; `onError: continue` does not hide a timeout.

## Regular expressions cannot hang the engine [#regular-expressions-cannot-hang-the-engine]

`matches` takes its pattern and its subject from callers. A backtracking engine takes exponential
time on a pattern like `(a+)+$`, and evaluation is synchronous, so one request could stall the
process. Patterns here run on a linear-time automaton: the cost is bounded by pattern × text
whatever the pattern looks like. Patterns are limited to 500 characters and subjects to 20,000.
What needs backtracking — backreferences (`\1`), lookahead and lookbehind, `\p{…}` — is rejected
with a clear error rather than run unsafely.

## Personal data [#personal-data]

Mark a field **sensitive** in a decision's input (or output) model (the toggle in the schema editor,
or `"x-sensitive": true` in the JSON Schema). The decision still receives and answers with the real
value; the record stored for audit has it masked, and so does every copy of that value found in the
variables, trace, reasons and actions of the run. Masking happens before the record is written, so
the hash chain seals the masked form.

Each project sets how long it keeps executions (Settings → Data protection; `0` keeps them for ever,
empty follows `EXECUTION_RETENTION_DAYS`). A person's data can be **erased** by the identifier the
caller sent with the executions: their content becomes a tombstone, the cases, delivery payloads and
observations derived from them are removed, and the erasure is audited (with a hash of the
reference, not the reference). The rows and their place in the chain remain, and the chain still
verifies. Erasure is irreversible and needs `project.manage`; an API key can never perform it.

Limits worth knowing: values shorter than 4 characters are masked at their path but not searched
for elsewhere; a value the flow transforms is not found; and the actions a decision asks for (a
webhook, a case) carry the real values because they exist to act on them.

## Supply-chain checks [#supply-chain-checks]

The Security workflow runs on every push and pull request and **blocks merges**: a dependency audit
(`bun audit`), a secret scan of the whole git history (gitleaks) and a scan of the API image
(Trivy, fixable HIGH and CRITICAL findings). A waiver is a recorded decision, with a reason, in the
place each tool provides — never a job that is allowed to fail.

## Cross-algorithm portability [#cross-algorithm-portability]

The API hashes on Bun; the test runner is Node, where the `Bun` global does not exist, so
`lib/password.ts` falls back to scrypt. Both formats describe themselves and verification dispatches
on the stored hash, so a password is always checked by the algorithm that hashed it.
