Skip to content

feat: add bot rules, a 404 rate limit and an e2e bypass header - #1597

Merged
piscisaureus merged 12 commits into
mainfrom
bot-protection
Nov 28, 2026
Merged

piscisaureus merged 12 commits into
mainfrom
bot-protection

Conversation

@crowlKats

@crowlKats crowlKats commented Nov 27, 2026 •

Copy link
Copy Markdown
Member

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:
    • Log: Cloudflare's scraping detection IDs on website requests.
    • Log: website requests without an HTML Accept header that score
      under 30. The challenge rules only see text/html requests, so
      this covers what website_requests adds.
    • The two existing managed_challenge rules, unchanged apart from
      the e2e exemption below.
    • Challenge: page requests carrying Bot Management detection
      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_requests mirrors the LB's routing: requests on jsr.io
    except 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.ts checks that the module path regex matches
    isModuleFilePath, and CI now runs the LB tests.
  • Rate limiting, log only: more than 20 website 404s a minute per IP
    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.
  • The post-deploy e2e tests send an x-jsr-e2e header carrying the
    E2E_BYPASS_TOKEN secret, which replaces the Deno/ user agent
    exemption. e2e_bypass_token is sensitive, so the plan shows the
    custom rules as (sensitive value).
  • Removes the @font-face for the missing DMMono-Bold.woff2 (about
    2.3k 404s an hour) and declares the existing DMMono-Medium.woff2 at
    weight 500.

The LB's FRONTEND_RATELIMIT and DOCS_RATELIMIT stay for now; they
can 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_ratelimit entrypoint were created on the
prod zone through the API with the same refs, so the first apply updates
them in place. The hand-applied rules exempt Deno/ user agents instead
of the e2e header; the apply switches them over. E2E_BYPASS_TOKEN was
reset 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.

@igorbdl igorbdl left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🚀

@crowlKats
crowlKats added this pull request to the merge queue Nov 27, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Nov 27, 2026
@crowlKats
crowlKats enabled auto-merge November 27, 2026 14:12
@crowlKats
crowlKats added this pull request to the merge queue Nov 27, 2026
@github-merge-queue
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.
Comment thread terraform/bots.tf Resolved
Comment thread terraform/bots.tf Resolved
* 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.
@piscisaureus piscisaureus changed the title feat: replace worker rate limits with bot management WAF rules feat: add log-only bot rules and a 404 rate limit next to the challenge rules Nov 28, 2026
@piscisaureus piscisaureus changed the title feat: add log-only bot rules and a 404 rate limit next to the challenge rules feat: add log-only bot rules, a 404 rate limit and an e2e bypass header Nov 28, 2026
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.
@piscisaureus piscisaureus changed the title feat: add log-only bot rules, a 404 rate limit and an e2e bypass header feat: add bot rules, a 404 rate limit and an e2e bypass header Nov 28, 2026
@piscisaureus
piscisaureus added this pull request to the merge queue Nov 28, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Nov 28, 2026
@piscisaureus
piscisaureus added this pull request to the merge queue Nov 28, 2026
Merged via the queue into main with commit 96d8bd4 Nov 28, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants