---
title: "Security model"
description: "What TRUSTIVAN trusts, what it refuses to trust, and the specific decisions that follow from treating a scan target as hostile input."
---

TRUSTIVAN accepts a string from a caller and makes an outbound network request
on that caller's behalf, then stores what comes back. That single sentence is
the whole threat model: everything below follows from taking it seriously.

This page describes the properties the system has. It is not a compliance
statement and it does not claim a certification. If you have found something
that contradicts it, see [Reporting a
vulnerability](/security/disclosure).

## The scanner has no local privilege

**Images are pulled from remote registries only.** The worker does not use a
Docker socket, containerd, Podman, or any local image store, and it needs no
container runtime installed at all: it deploys as a plain binary.

The detection engine's own default image sources include the local Docker
daemon. TRUSTIVAN removes them, for two independent reasons:

- **Mounting a runtime socket into the worker would be root on the host.** The
  worker is the process that handles untrusted input; it is the last one that
  should hold that socket.
- **A local image store is a cross-tenant disclosure channel.** The caller
  supplies the reference. If a local store were consulted, a reference
  matching an image the worker happened to have pulled would resolve to *that*
  image (another tenant's, or an internal one) and its contents would be
  reported to whoever asked. TRUSTIVAN's tenant boundary is enforced over
  TRUSTIVAN's data; it cannot reach into a container runtime's cache.

There is a third, quieter benefit: the same request cannot return different
results depending on what a given worker happened to have on disk.

## Image references are untrusted input

`POST /api/v1/scans` takes a string that will become an outbound request.
Validation is therefore a security boundary, not a formatting helper, and it
runs before anything is queued or persisted.

| Refused | Why |
|---|---|
| `169.254.169.254/x:latest` | On AWS, GCP and Azure that address serves instance credentials to anything that asks. It is a valid image reference by syntax |
| `10.0.0.5:5000/x:1`, `localhost:5000/x:1` | Otherwise TRUSTIVAN is a port scanner and a reader of unauthenticated internal registries |
| `user:password@registry/x:1` | A reference reaches a database row, a job payload, a log line and an API response. A secret must not ride along inside it |
| `https://registry/x:1` | A scheme is not part of a reference. Accepting one means accepting whatever a URL parser tolerates |
| `registry/../../etc/passwd:1` | Traversal segments must never reach a registry client or a cache path |
| Newline, space, NUL, a leading `-` | Argument splitting, log injection, and a reference read as a flag |
| Over 512 characters | Resource exhaustion, refused before any parsing |

Rejections are returned as `400` with a message naming the rule that was
broken. That is safe to return (the validator's errors never quote a
credential) and telling a caller exactly which rule they broke is the
difference between a usable error and a support ticket.

Private and loopback registries are permitted only by the deployment settings
`SCAN_ALLOW_PRIVATE_REGISTRIES` and `SCAN_ALLOWED_REGISTRIES`. Neither can be
requested per scan, because the caller is the untrusted party.

### Names are judged where they are connected to

The validator rejects a host that *literally is* a disallowed address. It does
not resolve DNS, and it should not: a name can resolve differently by the time
the scanner connects. So a name pointing at `169.254.169.254` passes the
parser, and the second check catches it.

That check is in the connection. Every connection a scan makes to fetch its
target goes through the same guard as webhook delivery. It runs after the name
is resolved and before the connection opens, once for every address the name
resolved to. It covers:

- **Image pulls:** the registry, its token service, every redirect, and every
  foreign-layer URL a manifest names. Each is judged by its own host.
- **Repository clones**, by every engine that clones. A redirect to another
  host is a new connection and is judged again.

A name that resolves to a private address is refused. So is a name that
changes its answer between the request and the scan (DNS rebinding), and so is
a redirect to one. In each case the scan fails without connecting. `ssh://`
repository targets are refused at clone time, because an SSH connection cannot
be sent through the guard.

The opt-in settings open loopback and private ranges only. Link-local
addresses, which include the cloud metadata service, stay refused under every
setting.

One limit remains. Some scans fetch what the target's *content* names, rather
than the target: a Terraform module source during a misconfiguration scan, or
a Maven repository declared in a `pom.xml`. The scanning engine makes those
requests with HTTP clients of its own, which cannot yet be routed through the
guard. Restrict the worker's egress with a network policy to cover them.

## Credentials, and how each is authorised

| Mechanism | Holder | Ambient | CSRF header |
|---|---|---|---|
| `Authorization: Bearer twk_…` | machines | no | not required |
| `trustivan_session` cookie | the dashboard | yes | required on unsafe methods |

Browser sessions are `HttpOnly` cookies, not tokens in `localStorage`. A token
JavaScript can read is a token any script on the page can exfiltrate, and the
set of scripts on a page is not a set you fully control.

Because a cookie is ambient (the browser attaches it to any request to this
origin, including one a hostile page caused), cookie sessions carry a
double-submit CSRF token: a `trustivan_csrf` cookie whose value must be echoed
in an `X-CSRF-Token` header on every unsafe method. Bearer requests are exempt,
and that exemption is not laziness: a bearer token is not attached
automatically by anything, so there is nothing for a hostile page to ride.

The token is **bound to the session**: it is an HMAC over each session
credential under a key derived from the server's signing secret, and a request
passes only when the token covers every ambient credential it carries. So a
value planted in the browser, or a genuine token issued for another session,
is refused even when the cookie and the header match. Matching alone would
prove only that the sender could write the cookie, which a sibling host of the
same site can do without being able to read one.

The exemption applies only to a header of exactly the form `Bearer <token>`,
the only form the API authenticates with. Any other `Authorization` value
(`Basic …`, a bare token, `Bearer` with nothing after it) is ignored for
authentication, the request falls back to the session cookie, and so the CSRF
header is required as for any other cookie request.

### An API key in a cookie is refused outright

A credential beginning `twk_` presented as a session cookie fails
authentication, even if it is a real, valid, unexpired key.

This is the one rule most worth understanding, because it looks like an
inconvenience. An API key deliberately has **no** CSRF protection, on the
grounds that it is not ambient. A cookie **is** ambient. Honouring a key from a
cookie would therefore produce a credential that is both ambient and
unprotected, strictly worse than either mechanism alone, and reachable by any
page that can persuade a browser to set a cookie on this origin.

### Every authentication failure looks identical

Missing, malformed, unknown prefix, wrong secret, revoked, expired, key in a
cookie: all return the same `401` with the same body. A test compares them
byte for byte.

Distinguishing them tells an attacker which part of a forged credential to fix
next. The reason is classified internally for metrics and logs, which is where
that information is useful and where it is not reachable by the person
attacking you.

Two further details follow from the same principle. The order of checks is
parse, look up, **compare**, then evaluate state. Checking revocation before
comparing the secret would let someone learn that a guessed prefix belongs to a
revoked key without ever holding the secret. And a prefix that matches nothing
performs the same hashing work as a real verification, so response time does
not distinguish "this prefix exists" from "it does not".

### Signing in

- **Password hashing.** Passwords are stored as bcrypt hashes at cost 12. An
  account whose hash was made at a lower cost is re-hashed at the current one
  the next time it signs in successfully, which is the only moment the
  password is available to hash again; a failed sign-in changes nothing. A
  sign-in for an address with no account does the same amount of hashing as
  one for an address with an account, so response time does not say which
  addresses are registered. The same applies to staff-console accounts.
- **Per-account lockout.** From the fifth consecutive wrong password an account
  is locked for 30 seconds, doubling with each further failure up to 15
  minutes, and it unlocks on its own. This is in addition to the per-address
  rate limit, which a password spray from many addresses walks past. A locked
  account answers exactly as a wrong password does, so the lockout does not
  reveal whether an address is registered. Each lock is recorded on the
  identity trail.
- **Require MFA for every member.** An owner can switch this on in
  **Settings → Security**. A member without a second factor is then held at
  enrolment on their next password or social sign-in, before any session
  exists, and cannot renew an existing session. Single sign-on sessions are
  exempt: the identity provider owns that factor.
- **Signing keys rotate without logging everyone out.** Every token names its
  key (`kid`), and `JWT_SECRET_PREVIOUS` verifies the old key's tokens during a
  rotation; see the configuration reference.

### Machine access ends with the person

An API key stops working the moment its creator is no longer an active member
of the key's organization (removed, deprovisioned by SCIM, or suspended), and
the agents and workloads a person delegated stop while they are suspended or
gone. See [Credential handling](/security/credentials).

### An agent cannot approve itself

An AI agent invoking a tool declared irreversible is answered `step_up` until a
**human** approves that exact action (that agent, that tool, that resource)
with their second factor if they have one. The approval is single-use and lapses
in five minutes. The agent cannot declare a human present on its own behalf.

## CORS is an allow-list

The only permitted origin is the dashboard's (`DASHBOARD_URL`). There is no
wildcard option and no reflection of the request's `Origin`, because both
amount to the same thing: any site becomes a first-party caller of your API.

The marketing website is deliberately not allowed. CORS is sent with
credentials, and the website is usually same-site with the API, so its visitors'
session cookies would ride its requests: listing it would let any script on the
website read authenticated API responses. The website never calls the API.

## The API sets its own response headers

Every API response, including errors and routes that do not exist, carries
`X-Content-Type-Options: nosniff`, `X-Frame-Options: DENY` and
`Referrer-Policy: no-referrer`. `Strict-Transport-Security` is added only when
the request arrived over TLS: terminated by the API itself, or reported by a
proxy listed in `TRUSTED_PROXIES`. An `X-Forwarded-Proto` from anywhere else is
ignored, and nothing is promised over plaintext. A deployment whose edge also
sets these headers can send one twice. The shipped edge configuration sets the
same `Strict-Transport-Security` value, and a browser processes only the first
anyway. Its `Referrer-Policy` is `strict-origin-when-cross-origin`; a browser
given both applies the last one it recognises, and either keeps the path and
query of an API URL off cross-origin requests.

## The dashboard ships a nonce-based CSP

Every dashboard page is served with a `Content-Security-Policy` carrying a
fresh per-request nonce. `script-src` allows this origin and nonced scripts
only (with `strict-dynamic`, so a nonced script may load its own chunks) and
never `'unsafe-inline'`; outside development it never allows `'unsafe-eval'`
either. An injected `<script>` or `onclick=` therefore does not run. Styles are
nonced the same way; inline style *attributes* are allowed, because React
renders them for the theme tokens and an attribute cannot execute script.

`frame-ancestors 'none'` is the clickjacking control, with `X-Frame-Options:
DENY` beside it for browsers that predate it. `object-src 'none'`,
`base-uri 'self'` and `form-action 'self'` close the remaining injection
routes, and `connect-src 'self'` keeps an injected fetch on this origin.

## Telemetry is disabled at the source

The embedded detection engine is configured with **both** its version check and
its telemetry flag disabled. One alone is insufficient (upstream's own
comment is explicit that skipping the version check still sends telemetry
headers), so both are set, and a test asserts it.

## A stale database fails the scan

Vulnerability data ages. A scan run against a database that predates the
advisories it was supposed to find succeeds, exits cleanly, and reports
nothing. Nothing in the result suggests the answer is wrong.

TRUSTIVAN treats this as a correctness problem with two thresholds:

| State | Default | Behaviour |
|---|---|---|
| `fresh` | under 48 h | The result is presented as authoritative |
| `stale` | over `VULN_DB_MAX_AGE_HOURS` (48) | The scan runs and records a warning saying so |
| `unusable` | over `VULN_DB_HARD_MAX_AGE_HOURS` (336, i.e. 14 days) | **The scan fails.** No findings are persisted |
| `unknown` | no build time reported | Treated as usable and flagged: a first scan on a new deployment legitimately has no timestamp |

Failing is the point. A stale scanner's silence is indistinguishable from good
news, so the only honest response is to refuse to produce the result at all.
The state is reported on every scan as `database_state`; see [Your first
scan](/getting-started/first-scan) and [Vulnerability
database](/configuration/vulnerability-database).

## Secrets in the deployment

`TOKEN_ENCRYPTION_KEY` is a **master key**, and the keys used for individual
purposes are derived from it with HMAC-SHA256 under a stable domain separator:
cursor signing, webhook signing-secret encryption, and the salt applied to
secret-finding digests.

Deriving rather than configuring each one separately is deliberate. Every
additional mandatory secret is another chance for a deployment to be
misconfigured and, worse, another thing an operator might set to the same
value as an existing one, quietly coupling two purposes meant to be
independent. Derivation means a deployment cannot forget one and silently fall
back to an empty key.

In production the key is mandatory, must be hex-encoded, and known placeholder
values are rejected at startup. The JWT signing key is treated the same way,
and in development the backend generates an ephemeral random one per process
rather than shipping a default. A published default signing secret was a real
finding in this codebase's own security review, not a hypothetical. See
[Credential handling](/security/credentials).

### Secret findings, precisely

Secret detection is **not enabled by default**: a container image scan runs
vulnerability detection unless the tenant has asked for more. A tenant enables
it per target kind with `PUT /api/v1/settings/scanners/{kind}`, and its results
appear in the dashboard, where the matched value is shown only in redacted form.

When it does run, TRUSTIVAN never stores the matched value. What is stored is a
truncated SHA-256 digest of the value under a per-deployment salt derived from
the master key. The digest exists so that one leaked credential can be told
apart from another across rescans; the salt exists so that an attacker who
obtains the database cannot confirm a guessed credential by recomputing the
hash. The salt's domain separator is a constant because changing it would
re-fingerprint every existing secret finding, closing them all and reopening
them as new.

## The AI assistant reads as the person asking

[Ask AI](/integrations/ai-assistant) holds no credential of its own. The
model's tools are the MCP server's read tools, and each lookup re-enters the
API in-process with the asking person's own session and their organization
pinned, so their role, row-level security and the rate limit apply to every
call. The write tools are not offered to it, so it cannot change anything; it
can only suggest an action the person confirms through the existing screens.
Scanned text reaches the model labelled as untrusted data, and anything shaped
like a known credential is redacted before it leaves. It is off until an admin
turns it on, and every question is audited.

## Tenant isolation

Isolation is enforced by the type system rather than by discipline: a
tenant-scoped repository method cannot be called without a `tenancy.Scope`, and
a `Scope` cannot be obtained without a membership check. A handler that forgets
to authorise does not compile.

That, the 404-not-403 rule, tenant-bound cursors, and an honest account of what
team management does *not* yet exist, are covered in [Tenant
isolation](/security/tenant-isolation).

## Where to go next

- [Credential handling](/security/credentials): key lifecycle, storage,
  and what a key may never be granted.
- [Tenant isolation](/security/tenant-isolation): how the boundary is
  enforced, and its current limits.
- [Reporting a vulnerability](/security/disclosure): how to reach us.
