scripts/audit/secret-in-response.py reads what actually crossed the wire
and reports credential material in it. It shipped 2026-09-15 with nine
test cases covering both directions, a README ending "Exit code is 1 if
anything CRITICAL or HIGH was found, so it can gate CI", and a real
cross-account disclosure to its name: vitareba's GET /api/admin/patients
returning every patient's bcrypt digest, which the code-level sweep had
missed because that route reads findMany() with no projection and a grep
for json(user) shapes does not match json({ success, data }).
Nothing ran it. Not a workflow, not ci.yml, not even its test. That is the
UNCALLED shape the floor audit exists to report, applied to the gate
templates/ci/README.md calls the one that catches what has actually cost
this fleet money — and it sat that way while the README said Rung 5 was
adopted nowhere, which was true only because nobody had looked in
scripts/audit.
WHAT LANDS
- secret-in-response-sweep.sh: every LIVE app from
loki:scripts/hetzner/apps.conf (the SSOT, read from its default branch,
never a local checkout), unauthenticated, three paths, GET only.
- secret-in-response.yml: daily, both suites before the verdict, Telegram
on failure, and fixtures-only on a PR because the live verdict is a
fact about the apps rather than about the change under review.
- both test suites into ci.yml, where neither had ever run.
First live sweep: 12/12 apps reached, 0 findings.
WHAT IT PROVES AND WHAT IT DOES NOT
Unauthenticated only. The README is explicit that the authenticated pass
is the real test — most interesting routes 401 without a session — and it
needs a live session cookie per app held as a rotating secret. A gate
needing twelve of those is a gate that stops running, so it stays manual
and the workflow says so rather than letting green imply more than it
proves. What it does cover is strictly the worse class: credential
material reachable with NO LOGIN AT ALL.
Still unbuilt: identity taken from the request body, and a query missing
its tenant filter. Both are per-repo assertions with no fleet-level
detector yet.
AND THE SAME BUG AGAIN, IN THE SWEEP WRITTEN TO CLOSE IT
With every host unreachable the sweep announced a clean fleet, having read
zero responses. Its own fixtures caught it before it ever ran on a bad
day. A verdict may only be claimed over what was actually READ: it now
reports scanned N/M, withholds unreachable hosts instead of counting them
clean, refuses to pass when N is zero, and when some hosts are missing
says "the N app(s) reached" rather than "the fleet".
13 aggregation cases, stubbed gh and stubbed scanner, no network.
Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
Fleet audit scripts
secret-in-response.py
Reads what actually crossed the wire and reports credential material in it.
Why this exists
Loki shipped passwordHash and privateZonePinHash to the browser from
GET /api/me (loki#306). The fix included a static gate that reads route
handlers (scripts/test/no-raw-user-response.ts, loki#309) — and that gate
says in its own header what it cannot see: RSC flight payloads. A server
component handing a whole row to a client component serializes it into the HTML
exactly the same way, and no route handler is involved.
This scanner closes that half. It needs no knowledge of any app's schema, ORM or framework, because it reads responses rather than code.
It has already earned its keep: on its first run across the fleet it found
GET /api/admin/patients in vitareba returning every patient's bcrypt digest —
a cross-account disclosure that the code-level sweep had missed, because that
route reads db.query.users.findMany() with no projection and the grep for
json(user) shapes does not match json({ success, data }).
Severity is about what the finding lets an attacker do
| meaning | |
|---|---|
CRITICAL |
a live bearer credential — OAuth access_token / refresh_token / id_token, a session token. Possession is access, to a third party, right now. |
HIGH |
a credential digest — bcrypt/argon2/scrypt/PBKDF2, or a key named password*/pin*. Not access by itself, but it moves the secret from where nothing can read it to where everything can, and a low-entropy secret behind it (a numeric PIN) is a cheap offline job. |
MEDIUM |
a long value under a hash/secret/token-ish key. Often a CSRF nonce or a public share token by design — reported so it is looked at, not assumed to be a leak. |
Usage
# unauthenticated — catches anything exposed without a login, costs nothing
python3 scripts/audit/secret-in-response.py \
--base https://app.example --paths / /login /api/health
# authenticated — the real test; most interesting routes 401 without a session
python3 scripts/audit/secret-in-response.py \
--base https://app.example \
--cookie '__Secure-authjs.session-token=<token>' \
--paths /dashboard /admin/users /api/me --json-out findings.json
Exit code is 1 if anything CRITICAL or HIGH was found, so it can gate CI.
Getting a session for a self-hosted app
For NextAuth v5 apps on the box, mint a JWT rather than logging in — no data written, no email sent:
import { encode } from "@auth/core/jwt";
console.log(await encode({
token: { id: "<uuid>", sub: "<uuid>", email: "...", /* + whatever the jwt callback sets */ },
secret: process.env.SECRET,
salt: "__Secure-authjs.session-token", // the cookie name IS the salt
}));
Two traps that cost real time here:
.envvalues may be single-quoted. systemd'sEnvironmentFilestrips quotes; a naivecut -d= -f2- | tr -d '"'does not. The token then signs cleanly and the app answersnull, which reads like a version mismatch. Settle it by comparing against the running process, not the file:PID=$(systemctl show -p MainPID --value <app>.service) sudo tr '\0' '\n' < /proc/$PID/environ | grep '^AUTH_SECRET='- The app-specific claims matter. Read the
jwt/sessioncallback and supply what it sets (role,companyId,tokenVersion, …) or the session resolves to something the guards reject.
Its limits, stated
- It matches key names and digest prefixes. A credential stored under a name
it does not know is invisible — aoz-wohnen's login credential is a
codecolumn holdingAOZ-XXXXXX, which no pattern here would catch. For an app like that, pull the real values from the DB and grep the responses for them directly. - It only reads the paths you give it. It is not a crawler.
- A clean run over N paths is evidence about those N paths, not a proof about the app.
Self-test
python3 scripts/audit/test-secret-in-response.py
Every case is a shape observed in the fleet or one that must stay silent. Run it after touching the patterns — a scanner nobody has watched fail is a scanner that reports clean because it matches nothing.