SPB Git

Repository Public

THREAT_MODEL.md 9.3 KB 111 lines markdown

1# Threat model23Scope: the SPIDER gateway, workers, stored data and the sources it reads. Method: assets →4adversaries → threats by trust boundary → controls → residual risk. "Tested" points to the test5that proves the control; controls without a test are marked as such.67## Assets891. The internal network (MacLustr LAN, WireGuard 10.67/10.68/10.70, cloud metadata, other apps).102. Tenants' collected data, schemas, keys and webhooks.113. The sources: their availability, their terms, their users' personal data.124. The operator's reputation (the outbound address and the bot's name).135. Secrets: signing secret, API keys, worker keys, database credentials.1415## Adversaries1617A. A client with a valid key trying to reach internal services or another tenant's data.18B. A hostile web page (scripts, redirects, DNS tricks, huge or malformed content, prompt injection,19   content that becomes active when displayed in the dashboard).20C. A network attacker between workers and gateway, or on the public route.21D. A compromised worker node.22E. An honest client asking for something a source forbids.2324## Boundary 1 — client → gateway2526| Threat | Control | Status |27|---|---|---|28| Unauthenticated or under-scoped use | Hashed keys (SHA-256 of a 256-bit secret), scopes, expiry, revocation, rotation; 401/403 structured errors | tested (`tests/integration/test_api_*`) |29| Session theft / CSRF on the dashboard | HttpOnly SameSite=Strict cookie, per-session CSRF token on every state-changing request, 12 h expiry, sessions deleted on key revocation | tested |30| Cross-tenant read | every query filtered by tenant; other tenants' ids answer 404; signed artifact URLs bind artifact + tenant + expiry | tested |31| Existence leak through deduplication | references are per tenant; no answer depends on prior existence of a blob | tested |32| Abuse / exhaustion | per-key rate limit, quotas on active and daily jobs, body size limits, bounded budgets validated server-side | tested |33| Disabling safety by request | mandatory policies are part of the contract; `false` is a validation error | tested |34| Replay of a submission | idempotency keys unique per tenant; conflict on a different body | tested |3536Residual: rate limiting is per gateway process (in memory). Dashboard authentication is by API key,37not passkeys or an identity provider (ADR-0006).38**Known and failing by design (strict expected failure in the test suite): any tenant's `admin` key39is a fleet operator** — it can set operator-wide kill switches, delete policies, list and drain all40workers, and `GET /v1/policies` lists suspended hosts of all tenants. Acceptable with one operator;41must be fixed before a second organisation gets an admin key (ADR-0006). Session ids and CSRF tokens42are stored unhashed in the database. Client-supplied path regexes are length-capped and compiled, but43run in the gateway: a pathological pattern can still burn CPU.4445## Boundary 2 — worker → Web (SSRF and hostile content)4647| Threat | Control | Status |48|---|---|---|49| Fetch of internal addresses | http/https only; no userinfo; denied ports; loopback, private, link-local (metadata), CGNAT, multicast, reserved, and their IPv6 forms (mapped, 6to4, NAT64, Teredo, compatible) refused; internal name suffixes refused | tested (`tests/security/test_netguard.py`) |50| DNS rebinding | every address of a name must be public; the connection is made to the validated address (pinned resolver), never re-resolved | tested |51| Redirect to internal or out-of-scope target | redirects followed manually; each hop re-validated (guard, scope, robots) | tested (fixture `/r/internal`, `/r/metadata`, `/r/external`) |52| Browser sub-resources, scripts, iframes reaching inside | two layers: (1) browsers are launched with a loopback egress proxy as their route out; the proxy applies the same rules and opens the upstream socket to the validated address; (2) inside the browser every request is checked against the same destination rules before it leaves, and main-frame navigation is restricted to allowed hosts. **Measured: WebKit on macOS does not always send loopback requests to the proxy**, so for WebKit layer 2 is the effective one for literal internal addresses; a name that resolves to an internal address is caught by the proxy only | both layers tested in both engines (`tests/unit/browser/test_browser_guard.py`); Chromium is the default engine |53| Side effects on the source | no form submission; unsafe or ambiguous controls skipped with a reason; every non-GET request aborted at the network layer; dialogs dismissed; downloads and permissions denied | tested on the fixture `/ui/danger` (zero POST received) |54| Decompression bombs, endless bodies | cap on decoded size while streaming; sitemap gzip unpacked once with a cap; no archive unpacking | tested (`/err/big`, `/err/gzip-bomb`) |55| Malicious documents | PDF: text layer only, JavaScript/attachments flagged and never executed | tested (extract unit tests) |56| Browser escape / resource exhaustion | fresh context per page, no persistent profile, recycle by count and memory, hard time-out watchdog, only PIDs spawned by the pool are killed | tested for time-out and recycling; **no OS sandbox profile beyond the browser's own** (residual) |57| Prompt injection against the vision model | image content declared untrusted in the prompt; model has no tool, no network, no SPIDER secret in its environment; output parsed as JSON, only requested scalar fields, coerced to the schema; a value is accepted only if OCR shows it in the capture | tested with a real model run |58| Injection through extracted text | extraction is deterministic parsing; page text is data; nothing extracted is executed or used as an instruction | tested (fixture `/product/5`) |5960Residual: the egress proxy trusts the host resolver of the worker node. Workers run as the node's61normal user, not in a container; filesystem isolation relies on per-task temporary directories.62CPU/RAM limits are those of the browser pool, not cgroups.6364## Boundary 3 — stored content → dashboard and exports6566| Threat | Control | Status |67|---|---|---|68| Stored XSS from snapshots | HTML/SVG artifacts served as `text/plain` or attachment with `CSP: sandbox`; `nosniff`; the dashboard writes API data with `textContent` only; replay is a neutralised document in a sandboxed iframe | tested |69| Replay contacting the source or running its scripts | scripts, handlers, `javascript:` URLs, meta refresh, `<base>` removed; external URLs neutralised; strict CSP in the document | tested (replay unit tests) |70| Spreadsheet formula injection | CSV cells beginning with `= + - @` are prefixed | tested |71| Leak of signed URLs | 5-minute expiry; exports never contain them | tested |7273## Boundary 4 — gateway ↔ workers, secrets7475| Threat | Control | Status |76|---|---|---|77| Rogue worker | worker keys (hashed, revocable, rotatable); a worker acts only on tasks it holds the lease and fencing token for; uploads are hash-verified; input artifacts served only to the lease holder of the same tenant | tested |78| Stale worker overwriting results | fencing tokens | tested |79| Interception | private network (WireGuard / LAN); **no mTLS** (residual, ADR-0006) | not implemented |80| Secret disclosure | secrets outside Git (0600 files, environment), secret scan before every commit and push; logs carry no key; console/network captures redacted | redaction tested |8182A compromised worker node can read the pages it is given and its worker key; it cannot read the83database or other tenants' stored artifacts. Revocation: `DELETE /v1/keys/{id}`.8485## Boundary 5 — SPIDER → sources (compliance)8687| Risk | Control | Status |88|---|---|---|89| Ignoring robots.txt | checked in the worker before every fetch and redirect hop; 5xx on robots = disallow | tested (zero requests to disallowed fixture paths) |90| Hammering a host | one request in flight per host for the whole fleet, minimum delay, `Crawl-delay`, `Retry-After`, adaptive back-off on 429 | tested |91| Working around a refusal | CAPTCHA, login wall, paywall, 401/403 → URL blocked; CAPTCHA or three consecutive denials → host suspended for everyone (1 h, doubling, 7 days max); no stealth, no solving, no rotation | tested |92| Unbounded exploration | budgets on pages, depth, states, actions, bytes, duration; trap heuristics and per-pattern budgets | tested |93| Personal data | no logged-in collection; `mask=pii` on exports; retention with deletion and garbage collection | masking and GC tested; **no automatic PII classifier** (residual) |94| Rights on content | captures and text are stored for the tenant that collected them; search indexes only what `noindex` does not exclude | partly tested |9596Kill switches: per source and global (`PUT /v1/policies`), effective at once for queued work and97propagated to workers at their next heartbeat.9899## Incident procedure (summary; runbook in `docs/RUNBOOKS.md`)1001011. Engage the global kill switch. 2. Revoke the suspected keys. 3. Drain or stop the affected102workers. 4. Read `/v1/audit` and the gateway logs by `request_id`. 5. Rotate the signing secret if103the gateway host is in doubt (invalidates sessions and signed URLs). 6. Restore from backup if data104integrity is in doubt (`scripts/restore.sh`).105106## Supply chain107108Dependencies are pinned by `uv.lock`; `scripts/sbom.sh` writes `docs/sbom.cdx.json` and a licence109table; `pip-audit` is run on the lock file. Browser binaries come from Playwright's distribution.110The vision model is loaded from the local cache only, offline.111
Files main
Menu

Theme