Skip to main content

Module security

Module security 

Source
Expand description

Secure-by-default response headers and configurable CORS.

The framework’s threat model treats a Seiva service as a JSON API sitting behind a TLS-terminating edge. Two transport-level controls address OWASP API Security API8 (Security Misconfiguration):

  • security_headers — a tower middleware that adds a conservative set of response headers (content-type sniffing off, framing denied, a locked-down Content-Security-Policy, HSTS) to every response, problems included. It only ever adds a header that is absent, so a handler that deliberately set its own value (a UI route relaxing the CSP, say) keeps it — no hidden override.
  • cors_layer — builds a CorsLayer from an explicit allowlist of origins (HttpSecurity::cors_allowed_origins). An empty allowlist means no CORS layer at all, i.e. browsers enforce same-origin — the secure default. A cross-origin caller is admitted only when its Origin is on the list.

Neither control changes a same-origin, non-browser caller’s behaviour beyond the added response headers, so wiring them into router does not break an existing request path.

Structs§

HttpSecurity
The transport’s security configuration: the knobs a deployment turns that are not safe to hard-code. Read from the environment by the server runtime (see seiva-server) and handed to router_with_security.

Functions§

cors_layer
Builds the CORS layer from the configured allowlist, or None when the allowlist is empty (same-origin only — the secure default).
security_headers
Middleware that adds the framework’s default security response headers.