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

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

Explore more Henakab Knowledge Hub guides

Safe configuration checks you can reproduce

These checks are for a website you own or administer. Examples below show methods, not an assertion that any specific production setting is already enabled on Henakab. Record a baseline before changing DNS, response headers or Pages configuration.

Check the delivered response

curl -sSI https://example.com/
curl -sS -o /dev/null -w '%{http_code} %{url_effective}\n' https://example.com/privacy.html

Read the actual final URL, status code and response headers. A 200 response does not by itself prove that the expected page was returned: single-page-app fallbacks can serve the homepage for a nonexistent route. Compare the returned title and content as well.

Static Pages versus Pages Functions

Static Pages files can use an _headers configuration for some response headers. Responses generated by Pages Functions may need headers applied in function code instead; confirm the effective response with curl -I. A Content Security Policy must account for the real scripts, forms, Turnstile and AdSense integration in use. Deploying a restrictive policy without testing can break legitimate functionality.

Safe preview and rollback workflow

  1. Copy or version the current published source. Record the exact project name and production branch.
  2. Use a separate preview project, or explicitly select a nonproduction preview branch. Never assume the default branch is safe.
  3. Inspect homepage, articles, forms and 404 responses in the preview before requesting a production deployment.
  4. To roll back, redeploy the last verified build or use Cloudflare Pages deployment controls. Confirm the live response after rollback.

When making sensitive changes, keep API tokens and Pages secrets out of HTML, Git repositories, chat messages and screenshots. Limit Cloudflare Access policies to the administrator area instead of unintentionally blocking Googlebot from public articles.

Verification matrix

AreaWhat to verify
DNS/TLSExpected hostname resolves and HTTPS certificate is valid
Security headersHeaders are present on static pages and Function responses as appropriate
Admin routesUnauthenticated requests cannot read private information
404 behaviorUnknown paths return a real not-found page and status
PreviewTest URL differs from production and no live change occurred

Cloudflare Pages preview documentation