(janitor/dedupe): Consolidate Authorization: Bearer token extraction - #5491
Merged
Conversation
Five call sites reimplemented Authorization: Bearer <token> parsing instead of importing the existing @kilocode/worker-utils helper: - services/db-proxy/src/utils/auth.ts had drifted to be case-sensitive on the "Bearer" scheme and returned "" instead of null for an empty token, unlike every other copy. - apps/web/src/lib/mcp-gateway/http.ts, and the two auto-routing-benchmark route handlers, each carried a byte-for-byte copy of the same case-insensitive parsing logic. Expose the existing dependency-free extract-bearer-token.ts as its own subpath export (./extract-bearer-token), following the pattern already used for kilo-model-id etc., so Next.js/Jest and Cloudflare Worker consumers can pull in just this helper without the package's jose dependency. Update all five call sites to delegate to it and adjust the db-proxy test expectations to match the corrected (RFC 6750 case-insensitive, null-for-empty) behavior. Co-authored-by: kiloconnect[bot] <240665456+kiloconnect[bot]@users.noreply.github.com>
Contributor
Code Review SummaryStatus: No Issues Found | Recommendation: Merge Files Reviewed (6 files)
Reviewed by grok-4.6 · Input: 67.3K · Output: 9.3K · Cached: 377.5K Review guidance: REVIEW.md from base branch |
iscekic
approved these changes
Aug 25, 2026
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
extractBearerToken(parseAuthorization: Bearer <token>) was independently reimplemented in five places instead of using the existing@kilocode/worker-utilshelper:services/db-proxy/src/utils/auth.ts— already drifted: case-sensitive'Bearer 'match (no lowercase support) and returned''instead ofnullfor an empty token.apps/web/src/lib/mcp-gateway/http.tsapps/web/src/app/api/internal/auto-routing-benchmark/decider-candidates/route.tsapps/web/src/app/api/internal/auto-routing-benchmark/token/route.ts— explicitly avoided importing@kilocode/worker-utilsbecause the root export pulls injose, which broke under Jest's CJS transform.All five represent the same domain concept (RFC 6750 §2.1 bearer-token parsing) and are the kind of security-relevant logic that should have one owner — the
db-proxydrift is a concrete example of behavior silently diverging.Change
@kilocode/worker-utils/extract-bearer-token, for the existing zero-importextract-bearer-token.ts, following the same pattern already used for./kilo-model-idetc. so consumers don't need to pull in the package'sjosedependency.token/route.ts).db-proxytest expectations to match the corrected (case-insensitive,null-for-empty) behavior, and added a case-insensitivity regression test.Verification
services/db-proxy:npx jest— 35/35 passing.packages/worker-utils:npx vitest run— 355/355 passing.services/db-proxy,packages/worker-utils:npx tsgo --noEmit— clean.oxfmt --list-differenton all changed files — clean.apps/webtypecheck/test run was not completed in this environment (no local Postgres available for the Jest DB fixtures, and the whole-repotsgorun exceeded the sandbox time budget); the two changedapps/webroute files andlib/mcp-gateway/http.tsare simple, type-equivalent delegations to the same shared function signature (string | null | undefined -> string | null).