Skip to content

cloudflare

Cloudflare Pages and Workers: valid headers and redirects files and current binding types. Level all adds security rules for worker code. It requires javascript.

A scope has filenames wrangler.toml, wrangler.json, wrangler.jsonc, or _worker.js, or a dependency on wrangler or @opennextjs/cloudflare, or a file path **/functions/_middleware.{js,ts}.

Checks that _headers holds only blocks of a path followed by indented name-value lines, and that the /* block sets X-Content-Type-Options, Referrer-Policy, and X-Frame-Options or a CSP frame-ancestors.

Runs at the commit stage, once per scope.

Cloudflare skips a line it cannot read, and a static site has no server code to set these protections, so a typo or a missing line silently drops a security header.

Write each block as a path, then indented lines of a name, a colon, and a value. Add each missing security header to the block for /*.

An indented X-Frame-Options: DENY at the top of _headers reports a header with no path. Put a path such as /* on an unindented line above it.

Rule What it checks What to do
missing-header The /* block of _headers sets X-Content-Type-Options: nosniff, a Referrer-Policy, and X-Frame-Options or a frame-ancestors policy. Add the missing headers to the /* block.
syntax A file that the check reads parses without errors. Fix the syntax at the reported line.
gspot ignore cloudflare/headers --paths "<path>" --reason "<why>"
gspot ignore cloudflare/headers --rule missing-header --reason "<why>"

Checks each redirect source, destination, and optional status: 200, 301, 302, 303, 307, or 308, without a force suffix.

Runs at the commit stage, once per scope.

Cloudflare drops a redirect it cannot parse, and the old address starts to answer 404.

Write the rule as source, destination, and status.

The _redirects line /old /new 999 reports an unsupported redirect status. For a permanent redirect, change it to /old /new 301.

gspot ignore cloudflare/redirects --paths "<path>" --reason "<why>"

Checks that the environment types file, when the scope has one, is tracked and matches what wrangler writes.

Runs at the push stage, once per scope, with wrangler.

Stale binding types let code compile against a binding the configuration dropped.

Run wrangler types and commit the file.

A Worker types file that differs from the output of wrangler types reports drift. Run wrangler types, and commit the new file.

Rule What it checks What to do
stale Each committed file holds what the generator command writes now. Run the generator command, and commit the new file after you read the diff.
missing Each file that the check compares with the generator output exists. Run the generator command, then add the file to Git.
untracked Git tracks each file that the generator writes. Add the file with git add, and commit it.
gspot ignore cloudflare/stale-types --paths "<path>" --reason "<why>"
gspot ignore cloudflare/stale-types --rule stale --reason "<why>"
Setting What it sets
cloudflare.types_file The committed file that holds the Worker types. gspot sets it to cloudflare-env.d.ts in an OpenNext project.
cloudflare.types_interface The environment interface name that wrangler types writes. gspot sets it to CloudflareEnv in an OpenNext project.
Rule file Installed when
.gspot/rules/CLOUDFLARE.md Always
Tool Version
wrangler 3.78.3 or later, install it yourself

**/.wrangler/**. repository/local-files reports a tracked file at these paths.