# Security

> How konto protects tenants, money and personal data, the limits it states openly, and how to report a vulnerability.

konto handles money and personal data for several legal entities at once. This page says
how it protects them, and where its protection ends.

## Tenants and roles

- **One tenant per creditor.** A bearer token names the creditor, the actor and the role.
  No route takes a creditor from the caller; another creditor's account or bill answers
  like one that does not exist.
- **Least privilege.** `producer`, `courier`, `portal` and a customer's session reach only
  their routes, and the role is checked before the body is read. Tests call every route
  with every role and with a customer's session.
- **Only hashes are configured.** kontod stores the SHA-256 of each token and compares
  every configured hash in constant time.

## Customers

- **Passkeys, no passwords.** Customers sign in with a passkey that requires user
  verification; konto checks origin, challenge, signature and counter with webauthn-rs.
  A ceremony is held by the server for 5 minutes and finishes once.
- **Or the operator's login, checked like a passkey.** With a provider configured, kontod
  is its confidential client: authorization code with PKCE and a nonce, the sign-in bound
  to the browser by its own cookie, ID tokens with asymmetric signatures only, checked on
  kontod's clock. A login links to accounts only with an invitation; konto keeps its
  issuer and subject, no profile and no token.
- **Secrets only as hashes.** Invitation codes (160 bits, 14 days, one use) and session
  tokens (256 bits, 8 hours) are stored as SHA-256 only.
- **A cookie no script reads.** The session is a `__Host-` cookie, HttpOnly, Secure and
  SameSite=Strict; calls that change something also need the sign-in origin.
- **A fresh sign-in for money.** Changing the mandate or the delivery address needs a
  sign-in within 15 minutes, with a passkey or a provider login whose `auth_time` says so;
  a mandate is stored with the text agreed to, ended and never edited, and every change to
  holder, payment and delivery is logged with actor and time. Customers see the IBAN masked.
- **Read on every request.** A session reads only the accounts of its current grants;
  revoking a delegation or removing a passkey or a login takes effect on the next request.
  Every other account or bill answers like one that does not exist.
- **Several companies, still apart.** A person may hold accounts at every creditor of the
  sign-in group (`KONTO_SIGNIN_CREDITORS`), linked by the person alone. Each request
  reaches one creditor's grants; a clerk sees only its creditor's grants and the names
  its own invitations gave.

## Money

- **Review, then confirm.** Sealing and allocation bind the effect, the actor and every
  input they read with HMAC-SHA-256; a forged, foreign, reused or stale review is refused.
- **The IBAN comes from configuration only.** No route can change the seller's IBAN or
  creditor identifier, so a stolen token cannot redirect payments. Both are checked at
  start.
- **A suspension is a person's decision.** Only an approval with a reason creates a
  suspension order; no other code path can construct one.

## Documents

- The HTML bill has no script, escapes every text it did not write and is served with a
  Content-Security-Policy that allows no script, no foreign resource and no framing.
- The PDF is typeset in a sandbox that sees only its template and the bill as data; no
  producer text is evaluated as markup.
- The Kundenportal renders every server text as React text; its guards fail the build on
  any HTML or code sink, and a browser check runs it under a strict Content-Security-Policy.

## Supply chain

Every dependency is locked, and `cargo deny` checks advisories, licences and sources on
every change. An advisory is ignored only with its exposure stated and a date for the
next review. The Kundenportal pins every npm package to an exact version in a lockfile,
installs with `npm ci`, and ships nothing at run time beyond React.

## Known limits

konto does not protect against the following:

- **A digest is not a signature.** A bill's SHA-256 proves that it is consistent, not who
  issued it. The PDF is not signed, so a forged PDF would still recompute; the bill in
  the customer's portal is the authoritative copy.
- **Stored journal heads are plain digests.** Replaying the stored commands finds a
  changed or lost command, but not someone with write access to the database who rewrites
  a head together with its command. Restrict database access.
- **Customers through a portal token are scoped by the operator.** Where the operator's
  backend reads kontod with a `portal` token instead of [customer sign-in](sign-in.md),
  that backend decides which accounts a customer may read.
- **Transport is the deployment's.** kontod speaks plain HTTP behind your TLS terminator;
  the courier's channel (SMTP with TLS and DKIM, a print house) carries the bills.

## Report a vulnerability

Report it privately as described in
[SECURITY.md](https://github.com/hupe1980/konto/blob/main/SECURITY.md), not in a public issue.
