Skip to content

refactor: harden nginx config with per-location security headers#767

Open
ital0 wants to merge 1 commit intomainfrom
italomenezes/security-nginx-hardening
Open

refactor: harden nginx config with per-location security headers#767
ital0 wants to merge 1 commit intomainfrom
italomenezes/security-nginx-hardening

Conversation

@ital0
Copy link
Copy Markdown
Collaborator

@ital0 ital0 commented Apr 24, 2026

Note

Low Risk
Low risk: nginx config refactor plus proxy header tweaks; main risk is unintended header/proxy behavior changes for /v1 and static routes if assumptions about SSE/Host handling are wrong.

Overview
Centralizes Cross-Origin-Embedder-Policy and Cross-Origin-Opener-Policy into a new security-headers.conf snippet and includes it from each relevant location block to avoid nginx add_header inheritance pitfalls.

Updates the /v1/ reverse proxy to set Host using $proxy_host and explicitly drops WebSocket Upgrade/Connection headers (documenting SSE intent). The frontend nginx image now copies the new headers snippet into /etc/nginx/snippets/.

Reviewed by Cursor Bugbot for commit ff43ac8. Bugbot is set up for automated code reviews on this repo. Configure here.

- extract COEP/COOP headers into security-headers.conf snippet
- include snippet in every location to avoid add_header inheritance trap
- drop Upgrade/Connection proxy headers (backend uses SSE, not WebSocket)
- use $proxy_host instead of $host for backend Host header
@github-actions
Copy link
Copy Markdown

Semgrep Security Scan

No security issues found.

@ital0 ital0 self-assigned this Apr 24, 2026
@github-actions
Copy link
Copy Markdown

PR Metrics

Metric Value
Lines changed (prod code) +14 / -9
JS bundle size (gzipped) 🟢 1.02 MB → 1.01 MB (-4.4 KB, -0.4%)
Test coverage 🟢 70.64% → 70.64% (+0.0%)
Performance (preview) Preview not ready — Render deploy may have timed out
Accessibility
Best Practices
SEO

Updated Fri, 24 Apr 2026 21:00:34 GMT · run #1206

@ital0 ital0 marked this pull request as ready for review April 24, 2026 21:00
Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit ff43ac8. Configure here.

Comment thread deploy/config/nginx.conf

proxy_pass http://backend:8000/v1/;
proxy_set_header Host $host;
proxy_set_header Host $proxy_host;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Proxy Host header changed to internal service name

Medium Severity

Changing proxy_set_header Host from $host to $proxy_host sends the internal Docker service name (backend:8000) to the backend instead of the client-facing hostname. This can break BetterAuth's cookie domain handling, CSRF validation, or any logic comparing the request host against the configured BETTER_AUTH_URL (which is set to the public-facing URL). This behavioral change appears unrelated to the PR's stated goal of per-location security headers.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit ff43ac8. Configure here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant