-
Notifications
You must be signed in to change notification settings - Fork 6
fix(mcp): make remote /api/v1/mcp data plane work for external agents #2309
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -39,7 +39,7 @@ | |
| * cannot recover the raw key by probing for partial matches. | ||
| */ | ||
| export function hashApiKey(raw: string): string { | ||
| return createHash('sha256').update(raw, 'utf8').digest('hex'); | ||
Check failureCode scanning / CodeQL Use of password hash with insufficient computational effort High
Password from
a call to generateApiKey Error loading related location Loading Password from an access to API_KEY_PREFIX is hashed insecurely. Password from a call to readHeader is hashed insecurely. Password from an access to apiKeyScheme is hashed insecurely. Password from a call to extractApiKey is hashed insecurely. Password from an access to apiKey is hashed insecurely. Password from an access to RAW_API_KEY is hashed insecurely. Password from a call to generateApiKey is hashed insecurely. |
||
| } | ||
|
|
||
| /** Result of {@link generateApiKey}. `raw` is shown to the user only once. */ | ||
|
|
@@ -69,18 +69,27 @@ | |
| } | ||
|
|
||
| /** | ||
| * Extract an API key from request headers. Accepts `X-API-Key: <token>` or | ||
| * `Authorization: ApiKey <token>` (case-insensitive scheme). Bearer tokens are | ||
| * deliberately NOT treated as API keys — those flow through the session path. | ||
| * Extract an API key from request headers. Accepts, in order: | ||
| * - `X-API-Key: <token>` | ||
| * - `Authorization: ApiKey <token>` (case-insensitive scheme) | ||
| * - `Authorization: Bearer <token>` ONLY when `<token>` carries the ObjectStack | ||
| * api-key prefix (`osk_`). Remote MCP clients (Claude Desktop / Cursor / | ||
| * Claude Code) authenticate to `/api/v1/mcp` with the key as a Bearer per the | ||
| * MCP spec, so rejecting Bearer outright made every standard MCP client fail. | ||
| * A better-auth *session* token never starts with `osk_`, so a session Bearer | ||
| * still falls through to the session path — this can't shadow it. | ||
| */ | ||
| export function extractApiKey(headers: any): string | undefined { | ||
| const x = readHeader(headers, 'x-api-key'); | ||
| if (x && x.trim()) return x.trim(); | ||
| const auth = readHeader(headers, 'authorization'); | ||
| if (!auth) return undefined; | ||
| const m = auth.match(/^ApiKey\s+(.+)$/i); | ||
| const token = m?.[1]?.trim(); | ||
| return token || undefined; | ||
| const apiKeyScheme = auth.match(/^ApiKey\s+(.+)$/i); | ||
Check failureCode scanning / CodeQL Polynomial regular expression used on uncontrolled data High
This
regular expression Error loading related location Loading library input Error loading related location Loading This regular expression Error loading related location Loading library input Error loading related location Loading This regular expression Error loading related location Loading library input Error loading related location Loading This regular expression Error loading related location Loading library input Error loading related location Loading This regular expression Error loading related location Loading library input Error loading related location Loading This regular expression Error loading related location Loading library input Error loading related location Loading |
||
| if (apiKeyScheme?.[1]?.trim()) return apiKeyScheme[1].trim(); | ||
| // Bearer is accepted only for prefixed api-keys (never for session tokens). | ||
| const bearer = auth.match(/^Bearer\s+(.+)$/i)?.[1]?.trim(); | ||
Check failureCode scanning / CodeQL Polynomial regular expression used on uncontrolled data High
This
regular expression Error loading related location Loading library input Error loading related location Loading This regular expression Error loading related location Loading library input Error loading related location Loading This regular expression Error loading related location Loading library input Error loading related location Loading This regular expression Error loading related location Loading library input Error loading related location Loading This regular expression Error loading related location Loading library input Error loading related location Loading This regular expression Error loading related location Loading library input Error loading related location Loading |
||
|
github-advanced-security[bot] marked this conversation as resolved.
Fixed
|
||
| if (bearer && bearer.startsWith(API_KEY_PREFIX)) return bearer; | ||
| return undefined; | ||
| } | ||
|
|
||
| /** Parse a `scopes` value that may be a JSON-string textarea or a real array. */ | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.