Repository navigation
fix(nginx): DRY security headers via nginx snippets (#6842) - #7736
Merged
Merged
Conversation
Before: 5 add_header lines duplicated verbatim at 3+ locations in autobot-slm.conf.j2 (server level, /grafana/api/live/, /grafana/). Any CSP change required editing all sites. After: Two snippet files deployed by Ansible to /etc/nginx/snippets/: - autobot-security-headers-strict.conf: server default (frame-ancestors 'none') - autobot-security-headers-iframe-host.conf: Grafana/dashboard embedding (frame-ancestors 'self', unsafe-eval/blob: for chart rendering) Each location now uses `include` instead of inline add_header blocks. Also wires strict snippet into the colocated `/` location which previously dropped server-level security headers via its own add_header directives. Co-Authored-By: Paperclip <noreply@paperclip.ing>
3 tasks
Contributor
✅ SSOT Configuration Compliance: Passing🎉 No hardcoded values detected that have SSOT config equivalents! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Thinking Path
autobot-slm.conf.j2had 5add_headerlines copy-pasted verbatim at the server level,/grafana/api/live/, and/grafana/location blocks. Because nginxadd_headerin a childlocationblock replaces all parent-leveladd_headerdirectives, each block had to re-declare the full header set — causing PR #6751 to update CSP at three independent sites.Fix: two nginx snippet files, one strict (server default) and one permissive (iframe-host for Grafana/Prometheus), deployed via Ansible before the main nginx site config.
What Changed
templates/autobot-security-headers-strict.conf.j2: new — X-Frame-Options SAMEORIGIN, CSP with frame-ancestors 'none'templates/autobot-security-headers-iframe-host.conf.j2: new — CSP with frame-ancestors 'self', unsafe-eval/blob: for Grafanatasks/main.yml: 3 new tasks — ensure snippets dir exists, deploy strict snippet, deploy iframe-host snippet (all taggedslm,nginx, all notify test+reload)templates/autobot-slm.conf.j2: replace duplicateadd_headerblocks at server level,/grafana/api/live/, and/grafana/withincludedirectives; add strict include to colocated/location (which previously dropped server-level security headers via its ownadd_header)Verification
After Ansible playbook run:
Risks
/slm/index.htmlsub-location still has only Cache-Control + Pragma headers — security headers are dropped at that specific path. Pre-existing gap, filed as discovery below./grafana/remain as-is (optional, CORS_ENABLED guard).Model Used
Claude Sonnet 4.6 (claude-sonnet-4-6)
Issue Link
Closes #6842
Checklist
CLAUDE.mdnginx -ton deploy; no unit tests for Jinja2 templates)git commitruns them automatically)Dev_new_gui(notmain)