Cloudflare Pages Security Headers Generator

Generates a Cloudflare Pages _headers snippet focused purely on the common security header set, HSTS, Content-Security-Policy (with a report-only toggle), Referrer-Policy, X-Content-Type-Options, X-Frame-Options, and Permissions-Policy, pre-filled with sensible defaults you can adjust before copying. A free online tool from Staaarter, right in your browser.

Runs locallyUpdated 2026-07-26

Overview

Introduction

Rolling out a solid security header baseline on a new Cloudflare Pages project usually means looking up the same half-dozen headers and their recommended values every single time.

This tool skips that lookup: it's pre-loaded with sensible defaults for HSTS, CSP, Referrer-Policy, X-Content-Type-Options, X-Frame-Options, and Permissions-Policy, and outputs the exact _headers snippet to paste in.

What Is Cloudflare Pages Security Headers Generator?

A focused _headers generator covering only the commonly recommended security response headers, each with a toggle or default value rather than a blank field, so getting a reasonable baseline takes seconds.

It includes a report-only toggle for CSP specifically, since rolling out a new Content-Security-Policy safely almost always starts in report-only mode.

How Cloudflare Pages Security Headers Generator Works

Each header is built independently from its own toggle/value and only included in the output if enabled or non-empty, so unused headers don't clutter the generated snippet.

The CSP report-only toggle simply swaps the emitted header name between Content-Security-Policy and Content-Security-Policy-Report-Only, everything else about how the policy string is written stays the same.

When To Use Cloudflare Pages Security Headers Generator

Use it when standing up a new Cloudflare Pages project and you want a solid security-header starting point without researching each header individually.

It's also useful for auditing an existing project's headers, toggle through the options here and compare against what's actually deployed.

Features

Advantages

  • Pre-filled with sensible, commonly recommended defaults (a one-year HSTS max-age, nosniff, SAMEORIGIN) so you're not starting from a blank slate.
  • Keeps the output minimal, only headers you've enabled or given a value appear in the generated snippet.
  • The CSP report-only toggle makes it easy to generate a safe testing version before switching to full enforcement.

Limitations

  • Only outputs the _headers snippet for the single path pattern you specify (defaulting to /*), for multiple different rules per path use the general _headers Generator.
  • Doesn't validate that your CSP value string is syntactically correct, only that it's non-empty, use the dedicated CSP Generator to build that string carefully.

Examples

Default security headers for the whole site

Input

path: /*, HSTS: enabled (max-age 31536000, includeSubDomains), Referrer-Policy: strict-origin-when-cross-origin, X-Frame-Options: SAMEORIGIN

Output

/*
  Strict-Transport-Security: max-age=31536000; includeSubDomains
  Referrer-Policy: strict-origin-when-cross-origin
  X-Content-Type-Options: nosniff
  X-Frame-Options: SAMEORIGIN

Each enabled header appears as its own indented line under the /* path pattern, ready to paste into a Cloudflare Pages _headers file.

Best Practices & Notes

Best Practices

  • Roll out a new CSP in report-only mode first, review actual violation reports or console warnings, then switch to enforced once you're confident it's not breaking anything.
  • Only enable HSTS preload after you've confirmed every subdomain serves valid HTTPS, since preload list removal can take months to propagate across browsers.
  • Pair X-Content-Type-Options: nosniff with correct Content-Type headers on all your assets, it prevents MIME-sniffing but doesn't fix a genuinely wrong content type.

Developer Notes

Output is a single Cloudflare Pages _headers rule block for one path pattern; each header line is only emitted when its corresponding toggle is on or its value field is non-empty, keeping the generated snippet limited to headers you've deliberately chosen rather than emitting a fixed template with commented-out lines.

Cloudflare Pages Security Headers Generator Use Cases

  • Establishing a security-header baseline on a brand-new Cloudflare Pages project
  • Testing a new CSP in report-only mode before enforcing it site-wide
  • Auditing which recommended security headers an existing deployment is missing

Common Mistakes

  • Enabling HSTS preload before verifying every subdomain supports HTTPS, since undoing preload status is slow and largely out of your control once submitted.
  • Shipping a Content-Security-Policy directly as enforced without first checking it in report-only mode against real traffic.

Tips

  • Use the dedicated Cloudflare CSP Generator to build a well-formed policy string first, then paste it into this tool's CSP value field.

References

Frequently Asked Questions