diff --git a/security/security-senior-secops.md b/security/security-senior-secops.md index b13d3ed9..3f9bb882 100644 --- a/security/security-senior-secops.md +++ b/security/security-senior-secops.md @@ -423,6 +423,15 @@ res.json({ message: "Authenticated" }); // NO token in body ### HTTP Security Headers (Nginx) ```nginx +# add_header directives are inherited from the parent level only when the child +# level declares none, so putting Cache-Control in a nested location would drop +# every security header above on exactly the auth routes. Apply it at the server +# level through a map instead (map lives in the http block). +map $uri $cache_control { + ~^/api/auth/ "no-store"; + default ""; +} + server { # Force HTTPS (1 year + subdomains + preload) add_header Strict-Transport-Security "max-age=31536000; includeSubDomains; preload" always; @@ -442,13 +451,15 @@ server { # CSP — adjust script/style sources to match your CDNs add_header Content-Security-Policy "default-src 'self'; script-src 'self'; style-src 'self'; img-src 'self' data:; font-src 'self'; object-src 'none'; base-uri 'none'; frame-ancestors 'none';" always; - # No-cache for auth routes - location /api/auth/ { - add_header Cache-Control "no-store" always; - } + # No-cache for auth routes (empty elsewhere, so the header is omitted there) + add_header Cache-Control $cache_control always; # Remove server version server_tokens off; + + location /api/auth/ { + # auth handlers; no add_header here — see the map above + } } ```