HENAKAB.

← All guides

Web security / Cloudflare

How to secure a Cloudflare Pages website without breaking production

A secure website is not one setting: it combines account security, DNS hygiene, safe deployment practices, carefully chosen response headers and a clear recovery plan. This guide concentrates on non-intrusive checks you can perform on sites you administer.

What you need

1. Secure the account first

Use multi-factor authentication, protect your recovery methods and review who can access the account. Team members should receive only the privileges they actually need. Review API tokens and revoke those no longer used.

2. Inventory DNS records

List DNS records and identify mail delivery, ownership verification, Pages and other services. Do not delete unfamiliar TXT, MX or CNAME records until you understand them. A change to mail DNS can interrupt email or sender verification.

3. Check HTTPS and redirects

Use a browser and a read-only curl check to inspect the actual responses for your apex domain and www subdomain. Confirm the intended canonical address, and investigate inconsistent content rather than assuming HTTP 200 is sufficient.

4. Use dedicated preview deployments

Test HTML, CSS, JavaScript, legal-page links and Functions in a non-production Pages branch. A successful upload does not prove all application routes work. Verify the actual page title and content, not just the status code.

5. Review HTTP security headers

Cloudflare Pages supports a _headers configuration file for static responses. Consider X-Content-Type-Options and Referrer-Policy as straightforward starting points. More restrictive policies such as Content-Security-Policy need testing against every required service, including external advertising and verification scripts.

6. Understand Pages Functions

Functions routes such as /api/... require function files and deployment from the correct project folder. Check that the API returns the expected JSON. Avoid putting private API keys in static HTML or JavaScript.

7. Make missing pages return real errors

A missing 404.html may cause Cloudflare Pages to fall back to SPA-style routing for unknown URLs. On a normal multi-page static site, a dedicated 404.html helps prevent broken links from silently returning the homepage. Test deployment routes and redirects before adding it.

8. Inspect robots.txt, sitemap.xml and ads.txt separately

A valid XML sitemap and a real plain-text ads.txt file are different from a website homepage accidentally returned for those URLs. Preserve legitimate verification and advertising records throughout deployments.

9. Maintain a rollback plan

Keep a known-good full release and a local backup. Record the last functioning Pages deployment. If a new release breaks important routes, use the deployment controls to roll back after checking your account permissions.

Commands to keep handy

Run these only in the context described above. Review each command and understand its effects.

curl -sIL https://YOUR-DOMAIN.example/ | grep -Ei "^HTTP/|^location:|^content-type:"
curl -fsSL https://YOUR-DOMAIN.example/robots.txt
curl -fsSL https://YOUR-DOMAIN.example/ads.txt
Editorial checkpoint: Before publishing, insert an original screenshot or diagram from an authorized test environment at the relevant step. Do not present an untested example as a result from Henakab's own laboratory.

Frequently asked questions

Does enabling every security header automatically improve security?

No. A misconfigured CSP can block legitimate scripts, while unrelated headers cannot fix compromised credentials or unsafe application logic.

Should I disable Cloudflare security when a bot receives 403?

Not globally. First inspect Cloudflare Security Events and the exact request, then make a narrow adjustment only if legitimate traffic is blocked.

Does a 200 response prove a page exists?

No. If Pages returns the homepage for an unknown URL, a broken link can still show HTTP 200.

Official resources

Editorial note: This guide is a general walkthrough. Commands and interfaces may vary by version, system and environment. Review and test changes before relying on them in production.

Explore more Henakab Knowledge Hub guides

Hands-on Cloudflare Pages verification

Start with the domain's DNS records and confirm the hostname is attached to the intended Pages project. Compare the production deployment and preview deployments before changing a live build. In the dashboard, enable multi-factor authentication for accounts with administrative access and review which members can deploy.

Check HTTP responses

From a terminal, run curl -I https://example.com/, replacing the example domain with yours. Verify the status code, redirect behavior and security headers. Run curl -I https://example.com/a-page-that-does-not-exist; a static site with a custom 404 page should usually return 404. Check the actual page body as well as its status.

Prevent accidental release of private files

Deploy a clean output directory rather than your entire development folder. Exclude backup copies, database credentials, development caches and temporary drafts. Confirm that robots.txt and sitemap.xml point to intended public pages. Use a Pages preview URL to validate the build before promotion.

When something breaks

Check the deployment ID, compare the last known good build, and restore it from the Pages dashboard if needed. Avoid changing DNS and application code simultaneously when diagnosing a failure.