From f3a5607cfe5b9e8734cdb55df439c0259c67b2de Mon Sep 17 00:00:00 2001 From: RAM PRASAD ATLURI <116977270+ATLURI0001@users.noreply.github.com> Date: Wed, 11 Nov 2026 09:48:16 +0530 Subject: [PATCH] fix(nginx): preserve security header inheritance on /health and add CSP --- nginx/conf.d/edge.conf | 4 +++- tests/test_project.py | 8 ++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/nginx/conf.d/edge.conf b/nginx/conf.d/edge.conf index 206c8a8..b813d2d 100644 --- a/nginx/conf.d/edge.conf +++ b/nginx/conf.d/edge.conf @@ -17,13 +17,15 @@ server { add_header X-Content-Type-Options nosniff always; add_header Referrer-Policy strict-origin-when-cross-origin always; add_header X-Frame-Options DENY always; + add_header Permissions-Policy "geolocation=(), microphone=(), camera=()" always; + add_header Content-Security-Policy "default-src 'self'; object-src 'none'; frame-ancestors 'none'; base-uri 'self'" always; # Enable HSTS only on a real HTTPS hostname after confirming rollout. limit_conn client_conn 50; location = /health { access_log off; - add_header Content-Type text/plain; + default_type text/plain; return 200 'routekernel ok\n'; } diff --git a/tests/test_project.py b/tests/test_project.py index eecc99f..d7add6d 100644 --- a/tests/test_project.py +++ b/tests/test_project.py @@ -47,9 +47,17 @@ def test_security_headers_and_hardening(self): self.assertIn('add_header X-Content-Type-Options nosniff always;', cfg) self.assertIn('add_header Referrer-Policy strict-origin-when-cross-origin always;', cfg) self.assertIn('add_header X-Frame-Options DENY always;', cfg) + self.assertIn('add_header Permissions-Policy "geolocation=(), microphone=(), camera=()" always;', cfg) + self.assertIn("add_header Content-Security-Policy \"default-src 'self'; object-src 'none'; frame-ancestors 'none'; base-uri 'self'\" always;", cfg) self.assertIn('http2 on;', cfg) self.assertIn('limit_conn client_conn 50;', cfg) + def test_health_location_preserves_inherited_security_headers(self): + cfg = load('nginx/conf.d/edge.conf') + health_block = cfg.split('location = /health {')[1].split('}', 1)[0] + self.assertIn('default_type text/plain;', health_block) + self.assertNotIn('add_header', health_block) + def test_proxy_forwarding_invariants(self): proxy = load('nginx/snippets/proxy.conf') self.assertIn('proxy_http_version 1.1;', proxy)