# How it is protected

- **No account's password is stored.** Each account's password derives (scrypt) a key that
  unlocks the one key every saved KVM password is encrypted with (AES-256-GCM).
- **The saved vault requires a separate server storage key.** The complete settings document,
  including account-key wrappers, device metadata and encrypted credentials, is protected by
  AES-256-GCM with an independent random key outside the data directory. An account password,
  owner recovery key or old inner data key cannot decrypt a copied protected file by itself.
  The server still enforces roles and MFA online. This does not protect against a compromised
  server process or someone who obtains both the data and its key material. Keep the server
  storage key backup separate; losing it cannot be repaired with an account recovery code.
  Logs, history and TLS keys are not covered by the settings envelope. Earlier legacy backups
  remain sensitive and cannot be revoked by migration. See [Security](https://qkvm.com/docs/security-policy).
- **Forgotten password:** *Forgot your password?* on the sign-in page lists the ways back in.
  - *The recovery key* sets a new password for any account and keeps everything else as it
    was. It is shown once when qKVM is set up; an admin can make a new one under
    *Settings > Security*, which cancels the old one. Only a locked copy is stored. Whoever
    holds it can take over any account, so keep it like a password, and not on the computer
    qKVM runs on. It replaces the password only: an account with two-factor sign-in still
    needs its code.
  - *Another admin* can set a new password for you under *Settings > Accounts*.
  - *Starting over:* with neither, `qkvm --reset-password` forgets every account
    and the recovery key, so the first account can be created again. The saved KVM passwords
    were encrypted for those accounts, so they are erased and must be entered again; the
    list of KVMs and the other settings stay.
- **Signing in through an identity provider** holds its ID token to every rule of OpenID
  Connect before anybody is let in on it, and keeps one admin who signs in here: see
  [Sign in with an identity provider](https://qkvm.com/docs/accounts#sign-in-with-an-identity-provider).
- **Sign-in** uses an HttpOnly, SameSite=Strict session cookie. Repeated wrong passwords lock
  the address they come from out for 30 seconds, doubling up to 15 minutes. Signing in to one
  account does not forgive guesses made at another, and the addresses of one IPv6 network
  count as one.
- **HTTPS from the first request:** started with `--https`, qKVM never serves plain HTTP,
  not even for the first-run setup, and the box in the settings cannot switch it off. With
  `--tls-cert` and `--tls-key` it uses a certificate of your own (from your company's
  authority, say) instead of the one it makes: the files are checked at start, and read
  again at every restart of the listeners, so a renewed certificate is picked up by a restart.
- **Only from where you say:** with `--allow-from` and a list of addresses or networks
  (`--allow-from 192.168.1.0/24,100.64.0.0/10`), qKVM answers those and the computer it runs
  on, and turns everybody else away before there is a sign-in page to guess at. Behind a
  named proxy it is the visitor's address that counts. Given without an address (an empty
  variable in a compose file), the option is an error at start and not "everybody".
- **Behind a reverse proxy,** start qKVM with `--trusted-proxy` and the proxy's address or
  network (`--trusted-proxy 172.18.0.0/16`). It then takes the visitor's address from
  `X-Forwarded-For` and "came over HTTPS" from `X-Forwarded-Proto`, both of which the proxy
  has to send. Without that every visitor looks like the proxy: five wrong passwords by one
  lock everybody out, and the activity log names the proxy. Where no proxy is named, one on
  the same computer is believed as it is (`tailscale serve`, for one), and has to send
  `X-Forwarded-For` as well: one that sends nothing makes every visitor look like somebody
  sitting at that computer, who is let through the first-run setup without the code. That
  also means that any program on that computer can say it is passing on whichever address
  it likes. Once a proxy is named, only what was named is believed: name `127.0.0.1` too if
  one of your proxies runs on the same computer.
- **A proxy that keeps its connections to qKVM open between requests** has to let an idle one
  go sooner than qKVM does, which is 130 seconds after its last answer: otherwise it can send
  a request on a connection at the moment qKVM closes it, and lose that request (a press of a
  power button among them). The defaults of nginx (`keepalive_timeout` in an `upstream` block,
  60 seconds), Traefik (`idleConnTimeout`, 90), cloudflared (`keepAliveTimeout`, 90) and Caddy
  (`keepalive`, two minutes) all do; a value set above 130 seconds does not. (qKVM keeps 1000
  idle connections at once at the most, from everybody together, or a quarter of the open
  files the system allows it where that is fewer, and past that closes the one kept longest
  sooner; a busy wall keeps a few hundred.)
- **First-run setup takes a password and nothing else**, so a new qKVM belongs to whoever
  opens it first: choose the password right after starting it. Started with `--setup-code`,
  qKVM asks whoever sets it up from another machine for a code printed in its terminal (or
  its log: `journalctl -u qkvm`, `docker logs qkvm`), so that nobody on the network can
  claim a copy you just started. Use it where others can reach the port before you do.
- **Each KVM's certificate is remembered** the first time qKVM talks to it (like an SSH host
  key). If something else answers at that address later with another certificate, qKVM refuses
  to send it the password and the tile says so; *Settings > KVMs > Edit > Review certificate*
  shows both fingerprints. A server's controller may show the certificate its maker put on
  every board: a server is told apart by the numbers it gives for itself instead, before the
  password goes to it where its controller gives one (see [Servers](https://qkvm.com/docs/servers)), a PC with
  Intel AMT by its PlatformGUID (see [Intel AMT](https://qkvm.com/docs/intel-amt)), and a guest of Proxmox, whose
  certificate is its Proxmox's, by its SMBIOS UUID (see
  [Proxmox and virtual machines](https://qkvm.com/docs/proxmox-and-virtual-machines)).
  A tile moved to another address takes its saved password along only where the device
  there shows that same certificate; anywhere else, and always for a server's controller
  (whose maker may have put one certificate on every board) and for a guest of Proxmox
  (whose certificate is its Proxmox's, or a proxy's, or a wildcard other hosts show too),
  the password or API token is typed again.
- **Give qKVM a host name or address of its own.** A browser keeps what signs it in by host
  name, not by port. Where a device's own page is reached on another port of the name qKVM
  is looked at under (a router that forwards two ports of one name, tunnels to `localhost`),
  the browser would hand that page your sign-in to qKVM, and a device is not trusted with
  that. The wall offers no *Open console* link to such a device and says why. A console link
  is saved with its host written one way; one that a browser and qKVM would read as two hosts
  (numbers written another way, `127.1`) is refused. One that 0.2.0 saved so is kept as it is
  through an edit of the rest of the tile, until it is written again.
- **HTTPS** for qKVM itself is one checkbox (a certificate is made on this computer; its
  fingerprint is shown so you can check the browser's warning). Turn it on whenever qKVM
  listens on the local network. Tailscale already encrypts its traffic, and `--tls-tailscale` gives the wall a
  certificate browsers trust for its tailnet name (see [Over Tailscale or NetBird](https://qkvm.com/docs/over-tailscale-or-netbird)).
- Every change must come from qKVM's own page (cross-site requests are refused), the page
  runs under a strict Content-Security-Policy, and requests for unknown host names are rejected.
- **Nobody holds a connection for nothing.** One that has not sent a whole request within 20
  seconds is closed, a request's body gets the same, one that asks and then takes nothing of
  the answer for 20 seconds is dropped, and one that was answered is kept for its next request
  for 130 seconds (longer than a proxy in front keeps one, see above) and then closed, 1000 of
  those at once at the most, or a quarter of the open files the system allows qKVM where that
  is fewer (past that, the one kept longest is closed first). The one
  thing in qKVM that is spoken to over a websocket, the live view's line, shows a pass within
  ten seconds or is closed, and is hung up on when it answers no ping, takes nothing off the
  line, or floods it (see [Live view and control](https://qkvm.com/docs/live-view-and-control)). Wrong passwords
  are checked two at a time at most, so that guessing cannot use up the computer's memory.
- **A KVM is not trusted either.** What a device sends is read only up to a limit, only JPEG
  and PNG data of a sane size is passed on to a browser as a picture, and what a device says
  about itself (name, model, numbers) is reduced to plain short text or a number before it is
  shown or logged. A device cannot send qKVM on to another address, and qKVM talks to it
  directly whatever proxy the computer is set to use for the web (that one is used for
  alerts and for update checks). A broken or taken-over KVM can show a wrong picture; it
  cannot fill the memory of the computer qKVM runs on, or of the browser looking at it, or
  put a page of its own in your browser. One part of that is not qKVM's own to promise: a
  JetKVM's video and its control channel come through a WebRTC library (aiortc), and what a
  taken-over JetKVM could make that library hold or compute has not been measured.
- **Virtual media is root on a machine**, and is kept so: an admin's right, in person, never a
  token's; a confirmation that names the machine and the image, which the request carries and
  is held to, with the machine the list was made of (a tile edited to another machine since
  is refused); every mount, unmount and start from an image in the activity log; images
  read-only; and a device is only ever handed what qKVM itself listed or made, never an
  address somebody typed (a device that fetches an address is a way into the network it stands
  in). On Proxmox nothing is fetched at all: the image is one on its storages. An image carried
  to a KVM's own storage goes through the wall as it comes, never written to its disk, with a
  rule of its own for its length (16 GB) and a minute for each piece; it is hashed on its way,
  and what one cut off left is removed from the KVM. A server's controller, which fetches its
  image by an address, is handed one qKVM made for that mount alone, which answers that
  controller's address alone (and the mount's user and password over HTTPS), for as long as the
  image is mounted, and only the file in the admin's folder that was mounted.
- **The activity log** (*Settings > Activity*) keeps 50 MB, which is some nine months of a
  busy wall, in files of JSON lines in the data folder that are its record, never rewritten:
  one entry a line, with the time, what happened, the address it came from, the account, and
  what it concerned. Where it cannot be written (a full disk), what is asked for is done all the
  same, a power button included, and the log says at its top how many entries are missing
  and since when. A log collector (Filebeat, Vector, Promtail) can follow it from there.
  Started with `--audit-syslog collector.example` (or `host:port`, or `tcp://host:port`),
  qKVM also sends each entry to a syslog collector as it is written (RFC 5424, the entry as
  JSON in the message), so that what was done is known somewhere whoever did it cannot
  reach. This transport is unencrypted UDP or TCP; use a protected local relay for TLS
  forwarding, or a protected management network. The file stays the record: an entry the collector was not there for is not sent
  again, and nothing in qKVM waits for the collector. The page searches it, narrows it to a
  machine, an account, a kind and a time, and downloads it; in the table, a name that begins
  like a spreadsheet formula is written as text. The chapter [Activity log](https://qkvm.com/docs/activity-log) has
  all of it.
- What every account may look at on the wall is a tile's name, address and console link; how
  qKVM signs in to a device is shown to admins only.
- **Updates are installed only when signed** by the publisher's release key (see *Updates*).
- At start, qKVM says so if a library it runs on is older than the first version without a
  known vulnerability.
