Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/demo/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
1 change: 1 addition & 0 deletions nginx/conf.d/edge.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions nginx/snippets/proxy.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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;
5 changes: 5 additions & 0 deletions tests/test_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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')
Expand Down
Loading