Skip to content

fix(routes): phase4RateLimit ahead of auth on the 11 agentsRuntime routes; close the guard's three blind spots (B3 first shrink) - #1689

Merged
lilyshen0722 merged 2 commits into
mainfrom
wren/b3-first-shrink
Sep 12, 2026
Merged

lilyshen0722 merged 2 commits into
mainfrom
wren/b3-first-shrink

Conversation

@lilyshen0722

@lilyshen0722 lilyshen0722 commented Sep 12, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Readiness plan §3B row B3, first baseline shrink (follow-up to #1682, per 68059 / 68122).

  • routes/agentsRuntime.ts: the 11 registrations still ordered agentRuntimeAuth, phase4RateLimit / dualAuth, phase4RateLimit now run the limiter first, as the note above the limiter has specified since 2026-08-04. Pre-auth the key generator takes its header-hash branch (same per-caller isolation, different key prefix); no key-generator change.
  • routeRateLimitGuard.baseline.json shrinks by exactly those 11 rows (254 → 243). No other row moves.
  • __tests__/utils/routeRateLimitScan.js closes the three blind spots Vera probed at test(routes): rate-limiter-ahead-of-auth guard for every router.<verb> registration (B3) #1682 (68057), each with a classification test:
    • a file-level router.use(auth) ahead of a route's limiter classifies as limiter-after-auth (file-level use calls are prepended to the chain in file order, so use(limiter) before use(auth) still covers);
    • the last argument is the handler and is never classified, so a handler named getLimits no longer passes as a limiter;
    • router.route(path).all(…).get(…) chains are scanned per verb, with .all() middleware ahead of the verb's own.
  • TESTING.md authoring rule and the plan row B3 updated.

Verification

  • Guard suite: 16/16 (12 existing + 4 new classification tests).
  • Scan against this head: 431 registrations, 243 violations, matches the shrunk baseline exactly (no fresh, no stale rows).
  • The agentsRuntime* unit and service suites that load locally pass (97 tests); six suites fail to load locally on clean main too (the local jsonwebtoken load error), so CI is the check for those.

Second commit (2a51e0c) — Vera's gate finding

Pre-auth the per-token limiter keys on sha256(Authorization), so a rotated header minted a fresh bucket per request (300 rotating headers reached auth 300 times). phase4RateLimit is now a two-tier stack, IP first: phase4IpRateLimit (Cloudflare-keyed, 3000/60s) then phase4AgentRateLimit (120/60s) — the B2 webhook shape. Every registration in the file picks it up, including the routes that were already pre-auth on main with the same hole. agentsRuntime.rateLimitTiers.test.js drives the real router: fixed header → 120 of 300 reach auth; 3000 rotating headers from one IP → 3000 reach auth, the 3001st is 429.

🤖 Generated with Claude Code

lilyshen0722 and others added 2 commits September 12, 2026 04:40
…utes; close the guard's three blind spots (B3 first shrink)

Readiness plan §3B row B3, first baseline shrink.

routes/agentsRuntime.ts: every remaining `agentRuntimeAuth, phase4RateLimit`
/ `dualAuth, phase4RateLimit` registration now runs the limiter first, as the
note above the limiter has specified since 2026-08-04. Pre-auth the key
generator takes its header-hash branch (same per-caller isolation, different
key prefix); no key-generator change. The 11 `limiter-after-auth` rows leave
routeRateLimitGuard.baseline.json (254 → 243).

__tests__/utils/routeRateLimitScan.js closes the three blind spots Vera
probed at #1682 (68057), each with a classification test:
- a file-level `router.use(auth)` ahead of a route's limiter now classifies
  as limiter-after-auth (file-level use calls are prepended to the chain in
  file order, so `use(limiter)` before `use(auth)` still covers);
- the last argument is the handler and is never classified, so a handler
  named `getLimits` no longer passes as a limiter;
- `router.route(path).all(…).get(…)` chains are scanned per verb, with
  `.all()` middleware ahead of the verb's own.

None of the three changes any current row: the scan against main matches the
shrunk baseline exactly (431 registrations, 243 violations). TESTING.md and
the plan row updated.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Pre-auth, agentRateLimitKeyGenerator keys on sha256(Authorization), so a
caller rotating the header minted a fresh bucket per request (Vera's gate
on #1689: 300 rotating headers reached auth 300 times). phase4RateLimit is
now [phase4IpRateLimit (Cloudflare-keyed, 3000/60s), phase4AgentRateLimit
(120/60s)] — the same two-tier shape as the B2 webhook routes — so every
registration in agentsRuntime.ts picks up the IP tier first, including the
routes that were already pre-auth on main with the same hole.

agentsRuntime.rateLimitTiers.test.js drives the real router: a fixed header
reaches auth 120 times of 300; 3000 rotating headers from one IP reach auth
3000 times and the 3001st is 429.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
@lilyshen0722
lilyshen0722 merged commit 4078d5f into main Sep 12, 2026
18 of 19 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