Repository navigation
feat: add bot rules, a 404 rate limit and an e2e bypass header - #1597
Merged
Merged
Conversation
github-merge-queue
Bot
removed this pull request from the merge queue due to failed status checks
Nov 27, 2026
crowlKats
enabled auto-merge
November 27, 2026 14:12
github-merge-queue
Bot
removed this pull request from the merge queue due to failed status checks
Nov 27, 2026
piscisaureus
added a commit
that referenced
this pull request
Nov 28, 2026
…1601) * `terraform/bots.tf`: manages the production zone's custom WAF ruleset (`http_request_firewall_custom`). Staging isn't managed. * Two rules challenge unverified bots on jsr.io requests whose Accept header starts with `text/html`: one for bot scores under 10 and for the Lightpanda headless browser (user agent and JA4), one for scores 10-29. The LB never serves module files to such requests, so module downloads, the Deno CLI, and npm clients aren't matched. The e2e tests (Deno user agent) and fediverse link-preview fetchers are exempt. * The existing "Singapore/China/Vietnam scrape" rule is carried over unchanged. * The rules, their order, and their refs are identical to what's live now, so the apply doesn't change behavior or rule IDs. * The zone already has this entrypoint ruleset (created in the dashboard), so it's adopted with an `import` block. The ruleset ID is set in `prod.tfvars`. The resource has `prevent_destroy`, since replacing it would delete every custom rule in the zone. * To stop managing the ruleset, use a `removed` block with `destroy = false`. Reverting this PR as is would delete the rules. * `terraform/db.tf`: prod Cloud SQL tier `db-custom-2-6144` -> `db-custom-4-6144`. It was raised to 4 vCPUs by hand on Nov 27 and reverted to 2 by the terraform apply on Nov 28 03:54 UTC. Changing the tier restarts the instance (about 30-60 seconds of database downtime). * CI: Terraform 1.4.2 -> 1.9.8, since `import` blocks with `for_each` need 1.7 or later. Context: on Nov 28 01:45-02:00 UTC a distributed headless-browser crawl pushed Hyperdrive past its origin connection limit and the site hung. Since the challenge rules went live, challenge solve rates are 0.08-0.1% and database load is down from 140-260k to 20-50k queries per 5 minutes. This overlaps with #1597; that PR will need to build on `cloudflare_ruleset.custom_firewall` instead of creating its own.
# Conflicts: # terraform/bots.tf
* Keep the managed_challenge rules from main and add the scraping detection rule and a rule for website requests without an HTML Accept header, both log-only and evaluated first. * Replace the Deno user agent exemption with the x-jsr-e2e header. * Make the 404 rate limit prod-only and fit it to the zone's plan: ip.src and cf.colo.id as characteristics, a 60 s mitigation timeout, and no request headers in its expressions. Import its entrypoint ruleset, which is created by hand first. * Drop cloudflare_bot_management: prod already has JS detections and model auto-updates on. * Keep the LB's FRONTEND_RATELIMIT and DOCS_RATELIMIT for now.
Bot Management detection 50331656 flags networks that scrape many zones. It catches a crawl of doc and diff pages from proxy and VPN IPs that score 30 or more, which the score rules miss.
github-merge-queue
Bot
removed this pull request from the merge queue due to failed status checks
Nov 28, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Most HTML traffic on jsr.io is unverified automation: about 3M
requests a day with a bot score under 30, against roughly 0.4M from
likely humans. The scrapers spread across thousands of IPs, so the
busiest single IP makes about 16 page requests a minute and never trips
the per-IP Worker limits.
This builds on the challenge rules that are already live (see #1601),
adds a challenge for scraping networks, and adds log-only rules to
measure the rest of the website before anything there is challenged.
Module files served from R2, api.jsr.io and npm.jsr.io are never
matched.
terraform/bots.tf, custom rules, in evaluation order:under 30. The challenge rules only see
text/htmlrequests, sothis covers what
website_requestsadds.managed_challengerules, unchanged apart fromthe e2e exemption below.
50331656 (networks that scrape many zones), whatever their score.
It catches a crawl of doc and diff pages from 1,000+ proxy and VPN
IPs, at most about 11 requests each, that scores 30 or more.
website_requestsmirrors the LB's routing: requests on jsr.ioexcept API, login and sitemap routes, badge endpoints (shields.io
fetches them server-side), the OG image route, static resources, and
module-file requests the LB would serve from R2. A new test in
lb/main_test.tschecks that the module path regex matchesisModuleFilePath, and CI now runs the LB tests.and colo. The zone's plan doesn't allow JA4 as a characteristic,
throttling (a mitigation timeout of 0), or request headers in rate
limiting expressions, so the rule matches by path and leaves out
module-file paths for every client.
x-jsr-e2eheader carrying theE2E_BYPASS_TOKENsecret, which replaces theDeno/user agentexemption.
e2e_bypass_tokenis sensitive, so the plan shows thecustom rules as
(sensitive value).@font-facefor the missingDMMono-Bold.woff2(about2.3k 404s an hour) and declares the existing
DMMono-Medium.woff2atweight 500.
The LB's
FRONTEND_RATELIMITandDOCS_RATELIMITstay for now; theycan go once the WAF rules have run for a while.
Bot Management settings aren't managed here: prod already has
JavaScript detections and model auto-updates on.
The new rules and the
http_ratelimitentrypoint were created on theprod zone through the API with the same refs, so the first apply updates
them in place. The hand-applied rules exempt
Deno/user agents insteadof the e2e header; the apply switches them over.
E2E_BYPASS_TOKENwasreset to a hex value in both environments so it passes the variable
validation.
The live ruleset also has two temporary log rules measuring detection
50331656. They aren't in terraform, so applying this removes them.