docs(rate-limits): a WAF test that reaches the threshold (#169)
The runbook's WAF test now uses a Node fetch one-liner (connection pool): xargs curl only reached ~20 requests/s, below the rule's 300 per 10 s. Measured 2026-10-27: 800 requests in 4.9 s -> 111 x 200, 201 x Worker 429, 488 x WAF 1015. [skip-discuss] Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
45f64e6c39
commit
435af85983
2 files changed
+7
-5
No files matched your search
@@ -152,7 +152,7 @@ Code **MIT** (`LICENSE`); catalog data **CC BY 4.0** for the maintainer's contri
|
||||
40. **The Python requirements are hash-locked pip-tools compiles** — `requirements.txt` ← `requirements.in`, `requirements-dev.txt` ← `requirements-dev.in` (`-c requirements.txt`) — installed everywhere with `--require-hashes --only-binary :all:`, so a new release of any dependency, indirect ones included, can't reach the jobs that push to `main`, and no sdist build script runs. After editing a `.in`, recompile with **pip-tools on Python 3.14**: `pip-compile --generate-hashes --allow-unsafe --strip-extras requirements.in`, then the same for `requirements-dev.in`. Dependabot takes the Python version from the `# … autogenerated by pip-compile with Python X.Y` header and supports ≤ 3.14 (gotcha 39); the hashes cover every file of a release, so CI's 3.15 still finds its cp315 wheels. `colorama` is listed in `requirements-dev.in` because pytest needs it on Windows only: a lock compiled on Linux (Dependabot's) would otherwise leave it out and the hash-checked local install would fail. Keep those pip commands in a block scalar (`run: |`): in a plain YAML scalar the `: ` of `:all: -r` makes the whole workflow file invalid — GitHub then records a 0-job failed push run named after the file, and a PR simply shows no check for that workflow.
|
||||
41. **SonarQube Cloud analyses in CI** (`sonarcloud.yml` + `sonar-project.properties`; project `poli0981_free-games-itchio-list`, public). Automatic Analysis is switched off on sonarcloud.io — switched back on, it makes the CI scan fail. PRs get a "SonarCloud Code Analysis" check from the SonarQube Cloud app; Dependabot and fork PRs get no `SONAR_TOKEN`, so their analysis is skipped with a notice (a Dependabot secret of that name would enable it). Tests run in the `coverage` job without the token; besides the `token` job's presence check, only the `scan` step gets it, in a job that runs no project code. Binary images and the D1 migrations (SQLite, claimed by the Oracle PL/SQL analyzer, which then warned on every run) are excluded from the analysis. Coverage: `pytest --cov` (`[tool.coverage.run]` in `pyproject.toml`) and `npm run test:coverage` (`test.coverage` in `vite.config.ts`; the lcov reporter's `projectRoot` is the repo root, so the scanner resolves the paths); `@vitest/coverage-v8` needs vitest's exact version (Dependabot group `vitest`). The built-in "Sonar way" gate fails a PR under 80 % coverage on new code (from 20 new lines up), so code without unit tests by design is in `sonar.coverage.exclusions` — keep that list in step with what the tests reach. `sonar.projectVersion` comes from `webapp/package.json`: on `main`, "new code" (previous version) starts over at each version bump. `sonar.python.version` stays 3.14 until SonarQube Cloud's analyzer supports 3.15 (it warns "No explicit support for version 3.15"). The free plan keeps only `main` and PRs: a manual run on another branch uploads a branch analysis nobody can open ("not allowed to access data from non main branches"). Mark a false positive on the issue itself. Two of its suggested fixes are wrong here: S2871 wants `localeCompare` in `.sort()`, but chunk names, migration files and `unblocked.json` keep code-unit order (= Python's `sorted()`) — pass `compareCodeUnits` (`worker/text.ts`); S8906 wants `select_one('div.a.b')` for bs4's `class_=[a, b]`, which means *either* class — write a selector list `div.a, div.b`. Trim trailing characters with `trimEnd()` (`worker/text.ts`), not `/x+$/` (S8786: quadratic backtracking on a long run). Known false positive: css:S8776 on Tailwind v4's `@utility … { &::-webkit-scrollbar … }` (the `&` is required for variants).
|
||||
42. **`overrides.undici` in `webapp/package.json` is a stopgap**: miniflare (wrangler's local runtime) pins `undici` exactly — 7.29.1 in wrangler 4.152, three advisories fixed in 7.30.1, so Dependabot could not raise it — and the override lifts it to `^7.30.1`. Only miniflare uses undici; nothing of it reaches the site, the Worker or the apps. Remove the override once `npm ls undici` without it shows ≥ 7.30.1, and before miniflare moves to undici 8 (the override would hold it on 7).
|
||||
43. **The Workers rate-limit binding counts per machine, not per data centre.** Measured on production right after the 4.5.0 deploy (CDG): 1,000 requests in 53 s, each `curl` on a new connection, against `RL_SITE` 120/60 s → **no 429 at all**; 200 requests on **one** keep-alive connection → 93 × 200, then 429s. A data centre has many machines, each counts locally and syncs late, so a client that keeps one connection (browsers over HTTP/2, scripts with keep-alive) is held to the limit, while one that opens a new connection per request is spread across machines and barely counted. The zone's WAF rule counts across the data centre: it is the limit that holds against floods. Test the Worker limits over one connection (`curl URL URL …` in one invocation, or `--next`), never with `xargs curl`; under `wrangler dev` (miniflare: one process) every request counts.
|
||||
43. **The Workers rate-limit binding counts per machine, not per data centre.** Measured on production right after the 4.5.0 deploy (CDG): 1,000 requests in 53 s, each `curl` on a new connection, against `RL_SITE` 120/60 s → **no 429 at all**; 200 requests on **one** keep-alive connection → 93 × 200, then 429s. A data centre has many machines, each counts locally and syncs late, so a client that keeps one connection (browsers over HTTP/2, scripts with keep-alive) is held to the limit, while one that opens a new connection per request is spread across machines and barely counted. The zone's WAF rule counts across the data centre: it is the limit that holds against floods. Test the Worker limits over one connection (`curl URL URL …` in one invocation, or `--next`), never with `xargs curl`; under `wrangler dev` (miniflare: one process) every request counts. The WAF rule (300 / 10 s, set 2026-10-27) needs > 30 requests a second, which `xargs curl` doesn't reach from a home line: use the runbook's Node `fetch` one-liner (800 requests in 4.9 s → 111 × 200, 201 × Worker 429, 488 × WAF 1015).
|
||||
|
||||
## Safe-edit rules
|
||||
|
||||
|
||||
+6
-4
@@ -182,12 +182,14 @@ Do these once (and again with the `-staging` names for the staging Worker).
|
||||
curl -s https://freeitchgames.win/api/health # {"error":"rate_limited"} → the Worker; "error code: 1015" → the WAF rule
|
||||
```
|
||||
About 120 answer 200 and the rest 429 (fewer pass if you sent requests in the last minute). The
|
||||
WAF rule, with a new connection per request, more than its threshold within 10 s:
|
||||
WAF rule needs more than 300 requests within 10 s — faster than `xargs curl` gets from a home
|
||||
connection (~20 a second). Node's `fetch` keeps a pool of connections and does it:
|
||||
```sh
|
||||
seq 400 | xargs -P 60 -I{} curl -s -o /dev/null -w "%{http_code}\n" https://freeitchgames.win/api/health | sort | uniq -c
|
||||
node -e "let n=0,t={};const go=async()=>{while(n++<800){const r=await fetch('https://freeitchgames.win/api/health');const b=await r.text();const k=r.status==200?'200':b.includes('1015')?'WAF 1015':b.includes('rate_limited')?'Worker 429':r.status;t[k]=(t[k]||0)+1}};Promise.all(Array.from({length:100},go)).then(()=>console.log(t))"
|
||||
```
|
||||
Past ~300 the answers turn into 429 `error code: 1015` (Security → Events lists them); without
|
||||
the rule all 400 answer 200. Worker 429s show up in Workers Logs (sampled,
|
||||
Measured on 2026-10-27 with the rule above: 800 requests in 4.9 s → 111 × 200, 201 × Worker 429,
|
||||
488 × WAF 1015 (from 1.4 s on), and the site answered normally again 10 s later. Security →
|
||||
Events lists the WAF blocks; Worker 429s show up in Workers Logs (sampled,
|
||||
`head_sampling_rate` 0.1).
|
||||
|
||||
## 2. GitHub
|
||||
|
||||
Reference in new issue
Block a user