pub async fn security_headers(request: Request, next: Next) -> ResponseExpand description
Middleware that adds the framework’s default security response headers.
Applied to every response (success and Problem alike):
X-Content-Type-Options: nosniff— no MIME sniffing.X-Frame-Options: DENYandContent-Security-Policy: default-src 'none'; frame-ancestors 'none'— the response is not framed and loads nothing; a JSON API needs no richer policy, and a route that does sets its own first.Referrer-Policy: no-referrer— no referrer leakage.Strict-Transport-Security: max-age=63072000; includeSubDomains— HSTS, meaningful once served over TLS (the assumed edge); a browser ignores it over plain HTTP, so it is harmless in local development.X-XSS-Protection: 0— disables the deprecated legacy auditor.
Mount it with axum::middleware::from_fn.