July 18, 2026HeaderTest Team366 views

How to Add Security Headers with Cloudflare

Proxied through Cloudflare? Add HSTS, X-Frame-Options, Referrer-Policy and more at the edge with Managed Transforms and Transform Rules — no origin changes required.

Add security headers with Cloudflare

If your site is proxied through Cloudflare (orange cloud), you can add security headers at the edge without touching your origin, using Transform Rules.

Managed Transforms (fastest)

Cloudflare ships one-click toggles under Rules → Transform Rules → Managed Transforms for common headers like X-Content-Type-Options: nosniff. Enable those first.

Custom headers via Transform Rules

For everything else, create an HTTP Response Header Modification rule (Rules → Transform Rules → Modify Response Header) and Set each header:

  • X-Frame-OptionsDENY
  • Referrer-Policystrict-origin-when-cross-origin
  • Permissions-Policycamera=(), microphone=(), geolocation=()
  • Cross-Origin-Opener-Policysame-origin
  • X-XSS-Protection0

HSTS the safe way

Enable HSTS from SSL/TLS → Edge Certificates — Cloudflare warns you about the commitment and lets you set max-age and includeSubDomains from the UI. Only enable preload once every subdomain is HTTPS. See the HSTS guide.

Content Security Policy

Add Content-Security-Policy as another Set rule. Because CSP is site-specific, start with Content-Security-Policy-Report-Only and watch the reports before enforcing.

Verify

Scan your site with HeaderTest to confirm the edge headers are live. More: all header guides.

Topics

cloudflaresecurity headerstransform ruleshstsstrict-transport-securityx-frame-optionsreferrer-policypermissions-policy

Check Your Website's Security

Use our free scanner to analyze your CSP and security headers.

Scan Now - Free