Skip to content

discovery(nginx): security-headers (CSP, X-Frame, etc.) duplicated at 3+ locations in autobot-slm.conf.j2 — DRY via include snippet #6842

Closed

Description

@mrveiss

Context

Multiple location blocks in autobot-slm.conf.j2 repeat the same set of add_header lines:

  • Line 44 (server-level default)
  • Line 269 (Grafana fallback)
  • Line 288 (Prometheus fallback)

Each block has CSP + X-Frame-Options + X-Content-Type-Options + X-XSS-Protection + Referrer-Policy. PR #6751 had to update CSP at all three sites; the next change will too.

Composable opportunity

# /etc/nginx/snippets/autobot-security-headers.conf
add_header X-Frame-Options "SAMEORIGIN" always;
add_header X-Content-Type-Options "nosniff" always;
add_header X-XSS-Protection "1; mode=block" always;
add_header Referrer-Policy "strict-origin-when-cross-origin" always;
add_header Content-Security-Policy "default-src 'self'; script-src 'self'; ..." always;

Each location: include /etc/nginx/snippets/autobot-security-headers.conf;

Constraint

CSP differs slightly per location (Grafana/Prometheus need 'unsafe-eval', blob:). Two snippets:

  • autobot-security-headers-strict.conf (server default)
  • autobot-security-headers-iframe-host.conf (Grafana, Prometheus)

Related

Acceptance

  • Two snippet files deployed via Ansible (template task)
  • All locations replaced with include directive
  • CSP header observable on /, /login, /api/*, /grafana/, /prometheus/

Activity

  1. mrveiss commented on May 16, 2026

    @mrveiss
    OwnerAuthor

    ✅ Closed — fix merged via PR #7736

    Commit: f853a15 — fix(nginx): DRY security headers via nginx snippets (#6842)

    Acceptance Criteria Met:

    • ✅ Two snippet files deployed via Ansible template tasks — autobot-security-headers-strict.conf.j2 + autobot-security-headers-iframe-host.conf.j2; Ansible ensures /etc/nginx/snippets/ directory exists
    • ✅ All duplicate locations replaced with include directive — server level (strict), /grafana/api/live/ (iframe-host), /grafana/ (iframe-host), and colocated / location (strict)
    • ✅ CSP observable on /, /login, /api/* via server-level strict snippet; /grafana/ via iframe-host snippet; /prometheus/ inherits server-level (no add_header override)

    Discovery filed: #7737 — /slm/index.html sub-location still drops security headers (pre-existing gap; requires this issue's snippets as prerequisite for fix)

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

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions