Skip to content

Security headers on cPanel — X-Frame-Options, CSP, Referrer-Policy

The Apache security headers worth deploying on a cPanel site by default, what each one stops, and the per-customer exceptions that will come up.

A handful of HTTP response headers reduce the attack surface for clickjacking, XSS, and information leakage at zero performance cost. cPanel does not deploy them by default. Adding them per-account in .htaccess is fast; deploying them globally via Apache include is durable. The careful operator does global with per-account exceptions.

What’s happening

Browsers honor security headers as the site’s instructions for how its content should be handled. X-Frame-Options: SAMEORIGIN prevents the site from being framed in another origin (clickjacking defense). Content-Security-Policy defines what resources may load (XSS defense). Referrer-Policy controls what the Referer header reveals on outbound clicks. X-Content-Type-Options: nosniff prevents MIME confusion attacks. Each is one line.

How to verify

curl -I https://example.com/ | grep -iE "X-Frame|Content-Security|Referrer|X-Content"
grep -ri "X-Frame-Options\|Content-Security-Policy" /etc/apache2/conf.d/
grep -ri "X-Frame-Options" /home/<user>/public_html/.htaccess

If the headers are not on the response, browsers default to the most permissive behavior.

The fix

  1. Global default in Apache — edit /etc/apache2/conf.d/security_headers.conf (or create it) with:
    <IfModule mod_headers.c>
        Header always set X-Frame-Options "SAMEORIGIN"
        Header always set X-Content-Type-Options "nosniff"
        Header always set Referrer-Policy "strict-origin-when-cross-origin"
        Header always set Permissions-Policy "interest-cohort=()"
    </IfModule>
    These four are safe defaults that break almost nothing.
  2. CSP is harder. A strict CSP breaks most existing sites. Start permissive: Content-Security-Policy-Report-Only: default-src 'self' https: data: and watch the violation reports. Tighten over weeks.
  3. Per-customer override: a customer who embeds their site in an iframe (a SaaS dashboard, a marketing tool) needs X-Frame-Options: ALLOW-FROM or a CSP frame-ancestors. Document the override in the per-account .htaccess with a comment.
  4. EasyApache rebuild: changes to global config files survive a rebuild only if added to the cPanel include system. Use /etc/apache2/conf.d/userdata/ includes or the Apache include editor in WHM.
  5. Test in stage: pre-prod environments should have the headers on first so CSP can be tuned without burning down production.
  6. Communicate CSP changes: a customer with a JavaScript framework that uses inline scripts will break. Either grant 'unsafe-inline' (defeats the purpose) or work with them to move scripts to external files with nonces.

Stack Harbor deploys security headers as part of the takeover baseline under cPanel server management.