Fix Missing Security Headers on Cloudflare

Last updated: April 2026

Cloudflare does not add security headers by default. Add them using Transform Rules (no code) or Workers (full control). Transform Rules is the recommended approach for most sites.

Scan your Cloudflare site for missing headers โ†’

Transform Rules โ€” no code required

Cloudflare Dashboard โ†’ Your domain โ†’ Rules โ†’ Transform Rules โ†’ Modify Response Header โ†’ Create rule.

Add each header as a Set action:

Header: Strict-Transport-Security
Value:  max-age=31536000; includeSubDomains

Header: X-Frame-Options
Value:  SAMEORIGIN

Header: X-Content-Type-Options
Value:  nosniff

Header: Referrer-Policy
Value:  strict-origin-when-cross-origin

Header: Permissions-Policy
Value:  camera=(), microphone=(), geolocation=()

Cloudflare Worker โ€” full control

export default {
  async fetch(request, env) {
    const response = await fetch(request);
    const newHeaders = new Headers(response.headers);

    newHeaders.set('Strict-Transport-Security', 'max-age=31536000; includeSubDomains');
    newHeaders.set('X-Frame-Options', 'SAMEORIGIN');
    newHeaders.set('X-Content-Type-Options', 'nosniff');
    newHeaders.set('Referrer-Policy', 'strict-origin-when-cross-origin');
    newHeaders.set('Permissions-Policy', 'camera=(), microphone=(), geolocation=()');
    newHeaders.set('Content-Security-Policy',
      "default-src 'self'; script-src 'self'; style-src 'self' 'unsafe-inline'; frame-ancestors 'none'; object-src 'none'");

    return new Response(response.body, {
      status: response.status,
      statusText: response.statusText,
      headers: newHeaders,
    });
  }
};

HSTS โ€” Cloudflare built-in toggle

Cloudflare Dashboard โ†’ SSL/TLS โ†’ Edge Certificates โ†’ HTTP Strict Transport Security (HSTS). Enable and set max-age. Start with 5 minutes before increasing to 1 year.

โš  Do not enable HSTS preload until all subdomains support HTTPS. Removing a domain from the preload list takes 6-12 months.

Verify your headers

curl -sI https://yoursite.com | grep -iE "strict|x-frame|x-content|referrer|permissions|content-security"
📚 HttpFixer Blog โ€” fix guides, explainers, and references โ†’