From 2c729f6a5072172e66d566309b9c441033d15607 Mon Sep 17 00:00:00 2001 From: RAM PRASAD ATLURI <116977270+ATLURI0001@users.noreply.github.com> Date: Sun, 15 Nov 2026 19:38:22 +0530 Subject: [PATCH] feat(edge): configure proxy buffers, add client X-Request-ID header, and bound trace length --- apps/demo/app.py | 2 +- nginx/conf.d/edge.conf | 1 + nginx/snippets/proxy.conf | 4 ++++ tests/test_project.py | 5 +++++ 4 files changed, 11 insertions(+), 1 deletion(-) diff --git a/apps/demo/app.py b/apps/demo/app.py index b507805..8461cad 100644 --- a/apps/demo/app.py +++ b/apps/demo/app.py @@ -8,7 +8,7 @@ def sanitize_header_val(val: str | None) -> str | None: if not val: return None - cleaned = val.replace("\r", "").replace("\n", "").strip() + cleaned = val.replace("\r", "").replace("\n", "").strip()[:128] return cleaned if cleaned else None async def health(request): diff --git a/nginx/conf.d/edge.conf b/nginx/conf.d/edge.conf index 9d1a805..e1718e2 100644 --- a/nginx/conf.d/edge.conf +++ b/nginx/conf.d/edge.conf @@ -28,6 +28,7 @@ server { 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; + add_header X-Request-ID $request_id always; # Enable HSTS only on a real HTTPS hostname after confirming rollout. limit_conn client_conn 50; diff --git a/nginx/snippets/proxy.conf b/nginx/snippets/proxy.conf index dab90e0..b524ca4 100644 --- a/nginx/snippets/proxy.conf +++ b/nginx/snippets/proxy.conf @@ -12,3 +12,7 @@ proxy_hide_header X-Powered-By; proxy_next_upstream error timeout http_502 http_503 http_504; proxy_next_upstream_tries 2; proxy_next_upstream_timeout 10s; +proxy_buffering on; +proxy_buffer_size 4k; +proxy_buffers 8 16k; +proxy_busy_buffers_size 32k; diff --git a/tests/test_project.py b/tests/test_project.py index a1d9ad6..2e91dc4 100644 --- a/tests/test_project.py +++ b/tests/test_project.py @@ -52,6 +52,7 @@ def test_security_headers_and_hardening(self): 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('add_header X-Request-ID $request_id always;', cfg) self.assertIn('http2 on;', cfg) self.assertIn('limit_conn client_conn 50;', cfg) @@ -77,6 +78,10 @@ def test_proxy_forwarding_invariants(self): self.assertIn('proxy_next_upstream error timeout http_502 http_503 http_504;', proxy) self.assertIn('proxy_next_upstream_tries 2;', proxy) self.assertIn('proxy_next_upstream_timeout 10s;', proxy) + self.assertIn('proxy_buffering on;', proxy) + self.assertIn('proxy_buffer_size 4k;', proxy) + self.assertIn('proxy_buffers 8 16k;', proxy) + self.assertIn('proxy_busy_buffers_size 32k;', proxy) def test_rate_limiting_and_http_status(self): nginx_cfg = load('nginx/nginx.conf')