fix(rate-limit): fail open when the bearer-identity DB lookup errors#9224
Merged
Conversation
…9223) validateBearerForRateLimit only classifies which rate-limit bucket a caller lands in, not the real authorization decision -- but its session-token DB read was unguarded, so any driver error there escaped the whole middleware chain uncaught and surfaced as a bare non-JSON 500 for whatever route was hit. Wrap it in the same fail-open try/catch already used for the Durable Object call in this file (#5000).
Contributor
|
Superagent didn't find any vulnerabilities or security issues in this PR. |
❌ 2 Tests Failed:
View the top 2 failed test(s) by shortest run time
To view more test analytics, go to the Test Analytics Dashboard |
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
validateBearerForRateLimit(src/auth/rate-limit.ts) runs on every request ahead of route handlers to decide whether a bearer token should get its own rate-limit bucket or fall back to IP-keying. It calls intoauthenticatePrivateToken→authenticateSessionToken, which does a real D1/Drizzle read againstauth_sessions.app.use("*", ...)middleware uncaught (noapp.onErroris registered anywhere in the app), and Hono falls back to a bare, non-JSONInternal Server Errorfor whatever route happened to be hit — indistinguishable from a bug in that route's own handler, even though the request's actual authorization check (later, dedicated middleware) never even ran yet.checkRateLimitBucketis explicitly wrapped in try/catch for the same reason (fix(orb): /v1/orb/token still returns 500 after the #orb-broker-500 fix (95 Sentry events) #5000 — no global error handler exists, so a rate-limiting side-channel must never be able to take down an otherwise-healthy request).Scope
type(scope): short summaryConventional Commit format.CONTRIBUTING.mdand does not reintroduce GitHub Pages, VitePress,site/, orCNAME.Closes #9223
Validation
npx vitest run test/integration/orb-ingest.test.ts— 47/47 pass, including the previously-failing"tolerates a list query that omits results (rows.results ?? [])"regression test, which reproduces this exact failure mode (a DB stub missing.bind()now degrades gracefully instead of throwing an uncaught 500).npm audit --audit-level=moderate— pre-existing high-severity findings in theeslint/brace-expansiondevDependency chain only; unrelated to this change (nopackage.json/lockfile diff).npm run test:ci(typecheck, coverage, workers, mcp/miner pack, ui suite, etc.) was not run for this PR.If any required check was skipped, explain why:
test:cisuite was skipped to land this fix quickly.Safety
Notes