← Back to Pull requests

feat: harden the HTTP edge (CSP, security headers, timeouts, panics) #290

Closed
unknown closed this pull request without merging on Nov 24, 2026 10:33 UTC
View on GitHub
unknown unknown commented on Nov 23, 2026 10:55 UTC
Author

What and why

Part of #180. Every platform-api response now carries a strict page CSP and baseline security headers. Requests time out per route group, and a handler panic answers a generic 500. The CSP is the main control against injected script driving the crypto worker's keys (THREAT_MODEL A3).

  • The policy lives in one file, backend/crates/platform-api/page-csp.txt. The backend compiles it in and vite preview reads it. Its only cross-origin entry is the exact URL of Google's attestation key set.

  • Headers on every response: CSP, X-Content-Type-Options: nosniff, Referrer-Policy: no-referrer, X-Frame-Options: DENY, Cache-Control: no-store.

  • Timeouts:

  • - query routes: QUERY_SLOT_WAIT_SECS + QUERY_TIMEOUT_SECS + 60 s
    - upload PUTs: a 30 s body gap (408), no total
    - everything else: 60 s (503)
  • Release builds refuse a non-empty VITE_API_BASE_URL (same origin, ADR 0005). No CORS layer.

  • Not in this PR: the exact key-set URL check and redirect: "error" on the key-set fetch. Both need #286's code and follow in a PR stacked on it. HSTS and static serving are #181.
  • How it was tested

  • tests/edge_api.rs and edge.rs unit tests:

  • - headers on 200, 401, 404, 405 and 413, and on timeouts and panics, each appearing exactly once
    - a handler's own headers are overridden
    - a hung read gets 503, a stalled upload body gets 408, and a slow but steady upload succeeds
    - query routes get the query timeout
    - a timed-out query frees its slot, and a cut upload commit leaves nothing visible
    - a panic gives a generic 500, a fixed log line and a metrics count
  • Frontend tests for the same-origin release check, and a check that the policy's connect-src matches the key-set URL.

  • scripts/check-page-headers.sh checks a release preview's headers on /, /index.html and the worker script. A Chromium smoke test in browser.yml runs a wasm operation in the worker under the policy.
  • Checklist

  • scripts/check.sh passes locally

  • Every new refusal has a negative test

  • Every new security decision emits a SECURITY_AUDIT_EVENT covered by audit_coverage.rs (none new: timeouts and panics aren't security decisions)

  • Fails closed on missing configuration, key material, or attestation

  • No new cryptographic primitives; suites stay behind their type aliases

  • Synthetic or public data only (docs/DATA_POLICY.md)

  • Docs and CHANGELOG.md updated for user-visible changes

  • Architectural decision recorded in docs/adr/ if one was made (none: the origin decision is ADR 0005)
  • Diff: 322 lines (+241 / -81) across 4 files Reviewer: gabrielzubovsky Review duration: 1417m
    All Vouch review confidence checks passed
    Residual risk 0.26 = Change Risk (0.65) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.65 · 322 lines diff across 4 files
    0.65
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.346
    Shallow Review Depth shallow_review_depth
    0.289
    Sensitive Paths sensitive_paths
    0.065
    Real PR Conversation Timeline
    1 comments
    "Review active on #290"
    general weight: 0.35
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed sensitive_module
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 65.1% (HIGH) · Higher = larger blast radius
    65.1%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 25.7% · Safe to merge
    25.7%