Repository navigation
fix(routes): phase4RateLimit ahead of auth on the 11 agentsRuntime routes; close the guard's three blind spots (B3 first shrink) - #1689
Merged
Conversation
…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]>
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.
Summary
Readiness plan §3B row B3, first baseline shrink (follow-up to #1682, per 68059 / 68122).
routes/agentsRuntime.ts: the 11 registrations still orderedagentRuntimeAuth, phase4RateLimit/dualAuth, phase4RateLimitnow 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.jsonshrinks by exactly those 11 rows (254 → 243). No other row moves.__tests__/utils/routeRateLimitScan.jscloses 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:router.use(auth)ahead of a route's limiter classifies aslimiter-after-auth(file-level use calls are prepended to the chain in file order, souse(limiter)beforeuse(auth)still covers);getLimitsno 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.mdauthoring rule and the plan row B3 updated.Verification
agentsRuntime*unit and service suites that load locally pass (97 tests); six suites fail to load locally on clean main too (the localjsonwebtokenload 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).
phase4RateLimitis now a two-tier stack, IP first:phase4IpRateLimit(Cloudflare-keyed, 3000/60s) thenphase4AgentRateLimit(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.jsdrives 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