Skip to content

docs(audits): triage the CodeQL js/missing-rate-limiting backlog (TASK-097) - #1832

Merged
lilyshen0722 merged 6 commits into
mainfrom
docs/codeql-rate-limit-triage
Sep 23, 2026
Merged

lilyshen0722 merged 6 commits into
mainfrom
docs/codeql-rate-limit-triage

Conversation

@lilyshen0722

Copy link
Copy Markdown
Contributor

Triage for TASK-097 — docs-only, one file: docs/audits/codeql-missing-rate-limiting-triage.md.

The row asked for two things: reconcile the disagreeing counts, then say which routes need a limiter and which get a documented exemption. This measures the first and frames the second; it does not touch a route.

Measurement (at 58232e6a)

open alerts, js/missing-rate-limiting, ref=refs/heads/main 349
same query with no ref filter 349 — the ref filter is a no-op; every alert's most-recent instance is already on main
distinct (path, start_line) sites 200 (33 files; 3 are test-file express apps)
created in 2026-04 / in September 322 / 3
the guard's own view of the same surface 232 baselined registrations, 204 limited, 0 fresh violations

The finding that matters: these are true positives, not indirection. Walking from each flagged line back to its enclosing registration (runtimeRouter/templatesRouter included) shows 0 of the 200 sites carry a limiter anywhere in the chain — while the 7 phase4RateLimit routes in agentsRuntime.ts are absent from the alert set entirely. So CodeQL does recognise our inline limiter shape, and the alert set is the burn-down list the repo already keeps, not a false-positive cloud. 349 is an instance count; the defect count is ~232 registrations, 197 of which the query also sees.

Instrument note, because a first pass was wrong: testing only the flagged line reported two auth.ts sites as limited and missed every registration under a non-router variable name. Its two hits were the next route's limiter, one line below. The chain walk is the measurement above.

Not mine to decide (Wren + Sam): a limiter on the agent-runtime family changes behaviour for every seat. The doc names four options with the existing budget (IP 3000/60s, token 120/60s), the blast radius, and the parameter the decision needs — the fleet's real per-token steady-state — and recommends per-route on the public surface first, then the mount-level stack once that rate is measured.

One count I could not reproduce: the row's "Vera counted 78 repo-wide". None of my shapes produce it; §7 asks for the query rather than guessing, because the answer decides whether the list is 232 or narrower.

No version slot: docs-only.

@lilyshen0722

Copy link
Copy Markdown
Contributor Author

Recut at 866eb01b per your two amendments (71374) and the §6 ruling (71373), plus vera's correction (71371).

What changed

  1. Status is no longer "open". §6 now records the ruling: (D) split — (B) per-route on the public/anon surface is a builder's row under TASK-097; (A) mount-level on /api/agents/runtime is Sam's own order, and not yet, with both preconditions named (per-token steady state measured against 120/60s; a runtime 429 reading as a named refusal in one seat's tool path).
  2. Callbacks and long-polls are no longer listed as exemptions. §5 now carries your treatment: IP tier on, token tier off — a retry storm from a third party is still an IP. Mechanically that is registering phase4IpRateLimit alone, which is worth writing down because the stack is two-tier and the natural call is to register phase4RateLimit.
  3. The 78 is reconciled, and it was a page, not a population (vera 71371): her query was the alerts call without --paginate — the first 100 open alerts of all rules, 78 of which happened to be this one; with --paginate it is 349. Her "38 in one file" comes from the same page and is unmeasured. §1 and §7 both corrected.
  4. Scope of (B) is measured rather than assumed. Public/anon = no auth/token/member/scope middleware anywhere in the registration chain, with string literals stripped so a path like /invite/:token cannot masquerade as a guard. 9 of the 200 flagged sites qualify; one is the test-file app — so 8 production sites, all GET. Of those only 3 are actionable:
route file budget
GET /x/oauth/callback admin/globalIntegrations.ts IP 600/60s
GET /registration-policy auth.ts IP 60/60s
GET /verify-email auth.ts IP 30/60s

The other five (health.ts ×2, pg-status.ts, docs.ts, stats.ts) are liveness/meta and stay exemption candidates. The remaining 190 flagged sites are authenticated — (A)'s or the burn-down list's, not this row's.

The 429-body gap, written down with its reason. The existing limiter bodies in agentsRuntime.ts are {message, code: 'rate_limited'} — no status, no named reason — so the current shape is not enough for #1823's reader and a seat would see raw text. Each new 429 carries status: 429 plus a named reason, and the name has to separate a PLATFORM 429 from an UPSTREAM one, because those are different facts to a seat deciding whether to retry. That also makes this shape precondition (2) of (A) rather than a separate convention.

One thing I would put in front of the (A) budget before it is set: the fleet's seats run on one host under the launchd supervisor, so they share a single egress IP — an IP-tier-only bucket is a fleet-aggregate bucket, not a per-seat one. 3000/60s is 50/s against ~30 seats reconnecting long-polls on the order of once per 30s, so the headroom is large; but that is headroom, not the per-token measurement (A) is gated on.

TASK-108 filed for (B) with the route list and a budget each. Structure re-run on 866eb01b please — the previous head acb474ae is still the first commit in the branch.

@lilyshen0722

Copy link
Copy Markdown
Contributor Author

Head moved 1bcd545f → d47ed3f2 (6 commits on 58232e6a, behind 0). Two folds, both requested:

1. The probes ruling (d47ed3f2, wren 71392 — carried as the outstanding fold in 71409/71422). §5's class row no longer calls health/status/read-only-meta wholly an exemption candidate; §6 lists GET /public with its budget instead of as a candidate. The deciding rule is now written down rather than re-litigated per route: does an anonymous hit do database work. Exempt: health.ts ×2, pg-status.ts ×2, docs.ts (a file read) — a limiter on a liveness probe can be the outage. Not exempt: GET /stats/public, three countDocuments per hit uncached, so IP tier 600/60s beside the OAuth callback. (B)'s actionable surface is therefore 4 routes, not 3.

2. The instrument's recorded shape (8f85f41d, vera 71402/71405/71406, tier recorded per wren 71410). §6 now states the exact line, what is deliberately absent, that it measures the token tier alone, that every count is per backend replica, that it is a lower bound because the limiter answers the crossing request, and that the row names its own removal.

…K-097)

Reconciles the two disagreeing counts and separates the defect from its
instances, then frames the enforcement choice for Wren + Sam.

Measured at 58232e6:
- 349 open alerts = 200 distinct sites in 33 files (3 of them test-file apps).
  The ref=refs/heads/main filter is a no-op: filtered and repo-wide both return
  349, because every alert's most-recent instance is already on main.
- 322 of the 349 were created in 2026-04 (3 in September) — a five-month-old
  backlog that re-attributes to any PR touching a shared dataflow node, which is
  why none of it may be dismissed per-PR.
- They are TRUE POSITIVES, not indirection: walking from each flagged line back
  to its enclosing registration shows 0 of 200 sites carry a limiter anywhere in
  the chain, while the 7 phase4RateLimit routes in agentsRuntime.ts are absent
  from the alert set entirely. The query recognises our inline limiter shape.
- The repo already owns a burn-down list for this surface: the route rate-limit
  guard's baseline, 232 registrations (204 limited, 0 fresh violations).
- Exemption candidates are narrow and named: 3 test-file apps, 6 health/status
  reads, 3 third-party-triggered callbacks, 2 long-poll reads.

The enforcement choice is not mine to take — a limiter on the agent-runtime
family changes behaviour for every seat — so the doc ends with four options and
a recommendation, plus the one count I could not reproduce (Vera's 78).

Docs-only: no version slot.
…097 triage

Recut per wren 71373/71374:

- Status is no longer "open": (D) was ruled, and the split is the point — (B)
  per-route on the public/anon surface is now a builder's row under this task,
  (A) mount-level on /api/agents/runtime is Sam's own order, gated on the
  per-token steady state being measured against the existing 120/60s and on a
  runtime 429 reading as a NAMED refusal in one seat's tool path.
- Callbacks and long-polls are NOT exemptions: they carry the IP tier with the
  token tier off, because a retry storm from a third party is still an IP.
  Registering phase4IpRateLimit alone is exactly that shape.
- Scope of (B), measured: public/anon means no auth/token/member/scope
  middleware in the registration chain with string literals stripped, so a path
  like /invite/:token cannot masquerade as a guard. 9 of 200 sites qualify, one
  of them a test-file app, so 8 production sites, all GET — and only 3 of those
  are actionable (the OAuth redirect target, /registration-policy,
  /verify-email); five are liveness/meta and stay exemption candidates.
- The 429-body requirement is written down with its gap: the existing bodies in
  agentsRuntime.ts are {message, code} with no status and no named reason, so
  the current shape is not enough for #1823's reader, and the name has to
  separate a PLATFORM 429 from an UPSTREAM one, which is a different fact.
- Flagged for the (A) budget: the fleet's seats share one egress IP (one host,
  launchd supervisor), so an IP-tier-only bucket is a FLEET-Aggregate bucket,
  not a per-seat one. 3000/60s is 50/s against ~30 seats reconnecting long-polls
  on the order of once per 30s, but that is headroom, not the measurement (A)
  needs.
- The 78 is reconciled and it was a page, not a population: vera's query was the
  alerts call without --paginate — the first 100 open alerts of all rules, 78 of
  which happened to be this one; with --paginate it is 349. Her "38 in one file"
  comes from the same page and is unmeasured.

Docs-only: no version slot.
Per wren 71383/71384/71385:

- §7 closes with both figures re-run today and the explicit statement that
  nothing about the list narrows: 349 records, 200 sites, 33 files, and the
  232-registration burn-down baseline all stand.
- §6 gains the two constraints (A) inherits. The store is in-memory and the
  backend runs replicaCount: 1 today, so the existing 120/60s budget is
  coherent only because there is one replica — at >1 it multiplies per replica
  unless the store is shared, and nothing in the config says so. And the
  derived floor of 12 requests/min per seat (daemon intervalMs default 5000,
  agent.js:850, before claims/renewals/heartbeats/tool calls) is labelled
  derived from source, which is why (A) waits on the sampled
  req.rateLimit.used instrument rather than on the derivation.

Docs-only: no version slot.
… scope (TASK-097)

Four changes, three of them other people's findings landing in the doc:

- §6 gains the trusted-proxy precondition (0) verbatim (vera 71399, TASK-110). Both
  tiers assume an IP key the caller cannot choose, and cf-connecting-ip is
  caller-supplied, so every "per IP" figure in the doc reads as "per key the caller
  may be able to choose" until that row lands.
- The three per-route budgets are labelled threat-model numbers (vera 71390): the
  ingress access log holds 5,417 requests over 24h with zero hits on /verify-email and
  /registration-policy, so nothing exists to confirm or contradict them. They stay.
- §6 records that nothing persists a per-token rate today (vera 71378) and that the
  counter instrument's shape is vera's scope while the build is Kai's under TASK-109,
  including her quoted scope: a watermark log registered immediately after
  phase4RateLimit, reading req.rateLimit, emitting only at
  used >= RATE_LIMIT_OBSERVE_WATERMARK (default 60).
- §7 credits the 78's reconciliation to vera (71371, restated 71385) rather than
  leaving it unattributed.

Docs-only: no version slot.
…al (TASK-097 §6)

The §6 entry for the instrument (built as TASK-109) now records what it
actually emits and what it deliberately does not:

- the line: key shortened to prefix + first 12 chars, route taken from
  `req.route.path` (pattern only, never `req.originalUrl`), `used`,
  `resetInSeconds`, `replica`; `limit` and `remaining` dropped because one
  restates the constant 120 and the other is arithmetic on the rest;
- that it measures the TOKEN tier alone, because it is mounted last and last
  wins in a stack, with the IP tier explicitly not observed (vera 71402,
  recorded rather than implied per wren 71410);
- that every count is per backend replica, the store being in-memory and
  per-process (vera 71406);
- that it is a lower bound by construction — the limiter answers the request
  that crosses the ceiling, so the observer never runs for it;
- that the row names its own removal (vera 71402).
…r (§5, §6)

wren 71392, carried as the outstanding fold on this PR (71409/71422).

The rule, stated so the next probe is decided rather than re-litigated: a
probe qualifies for exemption on "does an anonymous hit do database work".
health.ts (x2), pg-status.ts (x2) and docs.ts (a file read) stay exempt — a
limiter on a liveness probe can be the outage. GET /stats/public runs three
`countDocuments` per hit with no cache, so it does not qualify and takes the
IP tier at 600/60s, beside the OAuth callback.

§5's class row no longer calls the whole class an exemption candidate, and
§6 lists GET /public with its budget instead of as a candidate, which moves
(B)'s actionable surface from 3 routes to 4.
@lilyshen0722
lilyshen0722 force-pushed the docs/codeql-rate-limit-triage branch from d47ed3f to 5bb891a Compare September 23, 2026 07:18
@lilyshen0722
lilyshen0722 merged commit 45dc591 into main Sep 23, 2026
13 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.

1 participant