patchwise-agent-studio / docs /SECURITY-REVIEW.md
EnergyVenom's picture
Astra: security review, left-on-pod ledger, chosen scenarios all run, GL navigation and Create Order popup on 26D, health check (ed9256cd4029)
348eedc verified
|
Raw History Blame Contribute Delete
10.4 kB
# Security review (production)
Scope: the FastAPI backend (`coworker/`), the React web app (`web/`), the Docker deployment behind Caddy (`deploy/`) and the
browser runner API (`automation/remote_runner/server.py`). Reviewed at `d52c9b9`; fixes are on branch `security-review`.
Nothing was deployed or contacted other than the dependency advisory databases.
Severity: High = exploitable by an outsider with real impact; Medium = needs a precondition or limited impact; Low =
hardening or defence in depth. Every new behaviour is a setting with a safe default (listed at the end).
## Findings
| # | Area | Finding | Severity | Status |
|---|---|---|---|---|
| 1 | Sessions / sign-in | Limits were per user **and** visitor only: a guesser using many addresses had unlimited tries at one account, and one visitor could spray many names | Medium | Fixed: added a per-name limit across visitors (50 failures / 5 min) and a per-visitor limit across names (30 / 5 min, only behind a trusted proxy, see 2). Both counted on failures only; `0` switches off |
| 2 | Deployment | `deploy/docker-compose.yml` did not set `FPT_TRUST_PROXY`: behind Caddy every visitor shared the proxy's address, so "per visitor" limits were really global (5 bad tries on a name locked it for everyone) | Medium | Fixed in compose (default `1`; the app port is only exposed to the Caddy container). **Operator action**: redeploy, or set `FPT_TRUST_PROXY=1` in `.env` |
| 3 | Deployment | Interactive API docs (`/api/docs`, `/api/openapi.json`) are on by default and compose did not turn them off, although `docs/SECURITY.md` says they are off in production | Low | Fixed in compose (`FPT_API_DOCS` default `0`). Set `FPT_API_DOCS=1` in `.env` to show them |
| 4 | Break-glass reset | The "applied once" marker for `FPT_ADMIN_PASSWORD_RESET` was an unsalted SHA-256 of the secret, kept in the database (and in the saved state): a leaked copy let anyone test guesses of the reset password at full speed | Medium | Fixed: marker is now an argon2id hash; markers written by earlier versions still count, so an upgrade never re-applies a reset |
| 5 | Break-glass reset | A reset value shorter than 12 characters raised during start-up and stopped the server from booting | Low | Fixed: refused with a logged error, server starts. The reset only runs from a host environment variable, still audited (`users.admin_password_reset`) and ends the account's sessions |
| 6 | Audit log | A failed sign-in wrote the typed user name to the append-only audit log; people paste their password into the name field, and the log cannot be scrubbed | Medium | Fixed: a name is recorded only if it is a real account or an e-mail address; otherwise a short fingerprint (`unknown:<hash>`) |
| 7 | Constant-time compares | `hmac.compare_digest` on `str` raises `TypeError` for non-ASCII input: a crafted `X-CSRF-Token`, metrics bearer, signed-link `sig`, OAuth secret or callback signature gave a 500 | Low | Fixed: one helper (`users.consteq`) used everywhere. Runner token compared as bytes |
| 8 | Request size | No limit on request bodies: the recording and Excel checks looked at `Content-Length` only (chunked bodies bypassed them) and JSON bodies were unbounded | Medium | Fixed: `BodyLimit` middleware, 12 MB default (`FPT_MAX_BODY_BYTES`, `0` = off), 413 by `Content-Length` or while streaming. Caddy has no limit of its own |
| 9 | CORS | `FPT_CORS_ORIGINS=*` together with `allow_credentials=True` would let any website act as a signed-in person | Medium (config) | Fixed: `*` is ignored with a warning. Default origins are localhost only |
| 10 | Evidence serving | Evidence is served inline with a type guessed from the file name; a browser run can upload any file | Low | Fixed: only images and videos show inline; anything else downloads; every evidence response carries a `sandbox` CSP |
| 11 | Open endpoints | `POST /api/agent-studio/standin/inbox` (unauthenticated demo receiver) stored every body, signed or not: a table-filling DoS | Medium | Fixed: 5 unsigned callbacks / 5 min per visitor then 429, table kept to the last 500 rows |
| 12 | Open endpoints | `POST /oauth/token` had no limit on wrong client secrets | Low (secrets are random, 256-bit) | Fixed: 5 wrong secrets / 5 min per client and visitor |
| 13 | Runner API | A non-ASCII `Authorization` header raised in `compare_digest`; a negative or non-numeric `Content-Length` hung the handler (`rfile.read(-1)`) or raised; no socket timeout, so a stalled client held a thread | Medium (DoS on the runner) | Fixed: bytes compare, 400 on bad length, 120 s socket timeout |
| 14 | Runner bundle | The Astra side unpacked a runner's zip without a size cap (zip bomb from a compromised runner). Path traversal was already guarded | Low | Fixed: unpacked size cap 2 GB (`FPT_RUNNER_BUNDLE_MAX_MB`) |
| 15 | Secrets | The vault file was written with default permissions and `chmod` afterwards (a short world-readable window; a crash mid-write could corrupt it) | Low | Fixed: written to a 0600 temp file and moved into place |
| 16 | Authorization | Route inventory (194 routes): every route outside the public list needs `current_user`, `require(perm)` or its own credential | Info | Public on purpose: sign-in/register/forgot/reset/config, `health`, `ready` (internals hidden when anonymous), `metrics` (admin or metrics token inside), signed share link, stand-in inbox (signature + limit), `/oauth/token`, `/mcp`, `/a2a` and the agent card (personal tokens inside). A test (`TestEveryRouteIsGuarded`) fails if a new route is left open |
| 17 | Passwords / tokens | argon2id with a concurrency cap; sessions server-side, random 256-bit, SHA-256 at rest, 12 h (7 d with "keep me signed in"), ended by password change/reset/disable; personal tokens hashed, expiring, revocable, `/mcp` only; CSRF double submit; timing-equaliser hash for unknown names | Info | Reviewed, no change |
| 18 | HTTP headers | CSP (`script-src 'self'`, `frame-ancestors 'self'`, report pages sandboxed), nosniff, Referrer-Policy, COOP, X-Frame-Options (dropped only when `FPT_EMBED_ORIGIN` is set), HSTS when https or `FPT_COOKIE_SECURE=always`, `Cache-Control: no-store` on `/api` | Info | Reviewed, no change. `style-src 'unsafe-inline'` remains for the SPA's inline styles (script injection is not possible through it) |
| 19 | File serving | Reports: path comes from stored state and must be inside the runs folder; SPA files: resolved and checked against `web/dist`; evidence by numeric id; case YAML by strict id pattern | Info | Reviewed, no traversal found |
| 20 | Secrets in logs | Access log has paths only (no query strings, so signed links stay out); `pwt_` tokens filtered; egress audit logs descriptions, never headers; OCI PAR address is stored with `/p/***/` (`ocistore.shown`) and refused requests log the masked form; error handler returns the exception class name only | Info | Reviewed, no leaks found beyond #6 |
| 21 | Runner API | Token on every endpoint except `/healthz` (version and busy flag only); no shell (`Popen` with an argument list); config, env keys, file names and ids are allow-listed or pattern-checked; body 20 MB | Info | Reviewed |
| 22 | Runner API | The token is a long-lived bearer: anyone holding it can have the runner execute spec code (drafts/library are TypeScript run by Playwright) and receives the pod sign-in session on `finish`. There is no failed-token throttle (the runner sits behind Caddy, so per-address counting is not available there) | Medium (design) | Not changed. Mitigation: keep it behind HTTPS, restrict the runner's port to the Astra host (firewall or Caddy `remote_ip`), use 32+ random characters, rotate on staff change. The runner accepts 24+ characters; raising that would stop existing runners from starting |
| 23 | Vault | Secrets are plain JSON on the data volume (mode 600) | Low | Not changed (documented in `docs/SECURITY.md`): prefer `FPT_SECRET_*` environment values; the volume should be encrypted at rest (OCI block volume encryption) |
| 24 | Personal tokens | A personal access token keeps working after its owner's password is reset (it follows the owner's role, ends on disable/expiry/revoke) | Low | Not changed. After a break-glass reset or suspected compromise, revoke the owner's tokens in Settings |
| 25 | Dependencies (Python) | `pip-audit` on `coworker/requirements.txt` (and the architecture requirements it includes): no known vulnerabilities | Info | none needed |
| 26 | Dependencies (npm) | `automation/`: 0 advisories with `--omit=dev`. `web/`: `react-router-dom` / `react-router` 6.30.6 matches two moderate advisories (open redirect through a backslash in `<Link>`/`navigate`, GHSA-wrjc-x8rr-h8h6; `deserializeErrors` in SSR hydration, GHSA-337j-9hxr-rhxg) | Low here (the app is a client-only SPA, no SSR; paths passed to `navigate` are fixed in-app routes) | Not fixed: the only patched version is 7.18.x, a major upgrade (breaking). Plan it as its own change |
## Settings added (all safe by default)
| Setting | Default | Meaning |
|---|---|---|
| `FPT_LOGIN_MAX_PER_USER` | 50 | failed sign-ins for one name from all visitors in the window (300 s) before it is paused; `0` off |
| `FPT_LOGIN_MAX_PER_IP` | 30 | failed sign-ins from one visitor across all names; only counted when `FPT_TRUST_PROXY=1`; `0` off |
| `FPT_MAX_BODY_BYTES` | 12000000 | largest request body; `0` off |
| `FPT_RUNNER_BUNDLE_MAX_MB` | 2048 | largest unpacked runner bundle |
| `FPT_TRUST_PROXY`, `FPT_API_DOCS` (compose) | `1`, `0` | see findings 2 and 3 |
A note on the per-name limit: it also pauses the real owner of the name while it is reached (at most the window, 5 minutes, after
the last failure), so someone who knows an account name can keep it paused by sending 50 bad tries per window (a denial of
service on one account, not a break-in). Raise `FPT_LOGIN_MAX_PER_USER` or set it to `0` if that trade is not wanted. The
break-glass reset (`FPT_ADMIN_PASSWORD_RESET`) is not affected.
## Operator actions
1. Redeploy with the updated `deploy/docker-compose.yml` (or add `FPT_TRUST_PROXY=1` and keep `FPT_API_DOCS` unset in `.env`).
A redeploy interrupts a running test run: check first.
2. Restrict the runner's port to the Astra host and confirm its token is 32+ random characters.
3. Delete `FPT_ADMIN_PASSWORD_RESET` from the environment once it has been used.
4. Plan the `react-router-dom` 7 upgrade.