how-to deployersecurity-reviewer

Runbook — Security headers and transport security

Every OpenGov response carries a content policy — a header that tells the browser exactly which scripts, fonts, and connections a page may use — and deployments serving HTTPS also tell browsers to never come back over plain HTTP. Both are on by default and need no operator action in the standard topology. The one decision an operator may face is the private-certificate-authority opt-out below, and the one verification worth doing after go-live is checking the sign-in host, which these headers do not cover.

Pairs with docs/specs/2026-07-29-content-security-policy.md (the design, §5.3/§5.4) and the threat-catalog row it closes in docs/specs/2026-05-03-applicant-vault.md §7.1.

What ships on every response

The security-headers middleware (src/opengov/platform/security_headers.py) stamps exactly one content policy per response:

Response kindPolicyMeaning
HTML pages (the SPA shells)page policyfirst-party scripts and fonts only; the identity server’s origin named for connections and form posts; payment checkout origins named from the enabled-provider cache; Trusted Types required
Everything else (JSON, errors, files)API policyforbids everything — no browser should ever render these
/docs + /redoc onlydocs policydeliberately loose, and only reachable when the docs flag is on

No policy contains 'unsafe-eval', ever. Always-on headers (X-Content-Type-Options: nosniff, Referrer-Policy, Permissions-Policy, X-Frame-Options: DENY) ride every response.

Transport security (HSTS)

The transport-security header (Strict-Transport-Security, HSTS) is on by default: one year, includeSubDomains, sent only when the request provably arrived over HTTPS. A plaintext-only deployment simply never sends it (RFC 6797 forbids it on plaintext hops and browsers ignore it), so the default cannot lock anyone out of an HTTP install.

Which case are you in?

  • Standard topology (Coolify/Traefik with automatic public certificates): leave it on. Nothing to do.
  • Private certificate authority (step-ca, air-gapped installs): opt out with OPENGOV_HSTS_ENABLED=false (owner decision H4). A browser that trusts your authority stores the header on the very first visit, and any later trust problem with that authority is then not dismissible — on every device, for the header’s full lifetime, with no way to clear it at scale. A lapsed public certificate renews itself; a private-authority trust problem does not.

OPENGOV_HSTS_MAX_AGE lowers the one-year lifetime if a deployment wants a shorter commitment. There is no ramp-up schedule — a host that cannot serve HTTPS is a host that is already down.

preload is never set, and must never be added. Preloading requires includeSubDomains on the registrable domain and takes months to reverse. A single preload submission binds every deployment sharing that domain to a decision none of the others made — so the day several countries run under one shared domain, no operator may submit it. (OpenGov has no fixed platform suffix: each country sets its own wildcard_base. The <country>.singlewindow.dev fleet is a different, unrelated UNCTAD product, not OpenGov.)

Interactive API documentation

The interactive API docs (/docs, /redoc) load third-party bundles and an inline script, so they sit outside the strict policies and are off by default. Developers turn them on per environment with OPENGOV_API_DOCS_ENABLED=true. Do not enable the flag on country deployments.

The switch covers the machine-readable schema at /openapi.json as well — the file that describes every endpoint the application serves. With the switch off all three addresses answer 404. This was ruled on 2026-08-20 (discovery ledger L-8) after a deployment with its documentation off was found still serving the complete description of its staff-only endpoints to anonymous callers. Tooling that needs to read the schema (the schema fuzz gate, a support session) turns the switch on in its own environment.

Verify after go-live: the sign-in host

These headers protect the hosts the application serves (applicant., smartrules., and so on). The sign-in page — where a citizen actually types a password — lives at login.<deployment> and is routed by the proxy to the identity server, which has its own transport-security setting that this middleware never touches (spec §5.4). Keycloak’s documented default is one year with includeSubDomains, but that is a claim about a default, not a measurement of your deployment. Measure it on a running instance:

curl -sI https://login.<deployment>/realms/opengov/.well-known/openid-configuration \
  | grep -i strict-transport-security

Expect max-age=31536000; includeSubDomains. If it is missing or shorter, fix it in the identity server’s configuration, not in OpenGov.

Environment variables

Set on the app service (declared in src/opengov/config.py::Settings; extra='forbid' means an undeclared OPENGOV_ var crashes boot).

VarDefaultNotes
OPENGOV_HSTS_ENABLEDtrueset false for private-CA (step-ca / air-gapped) deployments — owner decision H4
OPENGOV_HSTS_MAX_AGE31536000one year; may be lowered; no ramp-up
OPENGOV_API_DOCS_ENABLEDfalsedeveloper tooling; never on country deployments
OPENGOV_TRUSTED_PROXIES10.0.0.0/8 in the shipped stack filescomma-separated proxy addresses or CIDR ranges whose X-Forwarded-Proto is believed; without it HSTS is never sent behind a proxy. Write a narrower range when the host uses another Docker address pool