# Test your own site for flaws before an attacker's tool does (SCAN_SELFTEST=1)

Flaws in public services are now found by machines within hours. This finds yours first. It is for **hosts you have proved you own, and nothing else**. Off unless the operator runs Scan with SCAN_SELFTEST=1; every call answers 404 otherwise.

## 1. Add the site and prove you own it
`POST /selftest/sites` with your account key: `{ "origin": "https://example.com" }`. The answer gives a token and two ways to prove ownership; do either one:
- a DNS TXT record `_praecise-scan.example.com` = `praecise-scan=<token>`, or
- the token as the whole content of `https://example.com/.well-known/praecise-scan.txt`.

`POST /selftest/sites/<id>/verify` checks it. **The proof is checked again before every run**; a site that stops proving it is not tested. Refused outright, at the add and at every run: anything that is not a public https host name on the default port, an address, `localhost`, and any name that resolves to a private, loopback, link-local (the cloud metadata address) or other reserved address, even one of several. Other people's hosts cannot pass the proof.

## 2. Settings (POST /selftest/sites/<id>)
- `openapi`: path of your openapi or developer description (default: /openapi.json, then /developer.json, on the same host only).
- `params`: example values for path parameters ({id}) so those routes can be asked; `publicRoutes`: routes public on purpose.
- `accounts`: **two** test accounts `{ name, headers: { authorization | cookie | x-api-key }, objects: [paths each owns] }`. Use accounts made for this, with no real data and short-lived credentials: they are kept in Scan's state (readable by the owner only) and never returned or put in a report.
- `manifest`: `{ kind: "package-lock" | "requirements", text }` for the version check.
- `pages`: extra paths to read for secrets. `intervalHours` (1 to 720, default 24). `requestBudget` (20 to 400, default 150 requests a run).
- `shield`: `{ site, token, autoPlace? }`, a Shield patch token (see Shield's virtual patching guide).

## 3. What it checks (read-only)
Missing authentication on every route of your own description (it asks each GET without credentials; it never sends a write: write routes are judged from the description alone); one account reading the other's object; security headers and cookie flags; exposed files (.env, .git, backups, dumps, keys, status and debug pages) and admin surfaces, with a check against your site's "not found" page so that a page that answers 200 to everything is not a false alarm; known-vulnerable versions from the manifest against public advisories (OSV; only package names and versions leave Scan); expired, expiring, untrusted or weak TLS and TLS 1.0 or 1.1; secrets in the pages and their scripts (redacted: the value is never stored).

Every request is a GET or HEAD to your verified host, paced, with a hard cap per run; a redirect to another host is not followed.

## 4. Findings, report, Shield
`POST /selftest/sites/<id>/run` runs now (at most once every 10 minutes); the schedule runs it for you. `GET .../findings?status=open`: each has severity, evidence, the fix, first and last seen; the same flaw is one finding across runs; when a check ran in full and no longer finds it, it is marked fixed. `GET .../report` is the report signed with Ed25519; the key is at `GET /selftest/public-key`, and the report says what it does not prove.
A finding that a Shield rule can shut offers it (`patch`). `POST .../findings/<finding>/patch` places it in Shield now, or with `autoPlace` Scan places it at once; when a later run shows the fix is live, Scan removes it. A finding that needs a code fix, or sign-in for a route (Shield's safe mode, which only the site's own secret sets), says so.

## Scope of the checks
- A report with no findings means these checks found nothing in the requests allowed.
- The checks are read-only: no password guessing, no write requests, no exploit payloads, no load.
- Object-level access is tested on the objects you listed for the two accounts.
- Authentication is judged from your own description, route by route.
