Repository navigation
fix(mcp): harden OAuth and permission flows - #286
NeerajCodz wants to merge 3 commits into
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
@codex review |
Codex Review Summary: ❌ FailedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 46c742043e
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| const scopes = await client.mutation(api.mcpOAuth.restrictRefreshGrantScopes, { | ||
| refreshToken: grant.refreshToken, | ||
| clientId, | ||
| requestedScopes, | ||
| }); |
There was a problem hiding this comment.
Narrow private-key refresh scopes before rotating
When a private_key_jwt client supplies scope, the preceding action has already rotated and invalidated the old refresh token before this second mutation runs. If this mutation encounters a transient Convex/network failure, the route returns server_error without revealing the newly issued token, so retrying with the old token produces invalid_grant and permanently disconnects the client. Pass the requested scopes through the assertion action and apply them atomically in the same mutation that rotates the token.
Useful? React with 👍 / 👎.
| }); | ||
|
|
||
| /** Applies a validated scope subset to a private-key client's live grant after rotation. */ | ||
| export const restrictRefreshGrantScopes = mutation({ |
There was a problem hiding this comment.
Keep refresh-scope restriction off the public API
This is exported as a public Convex mutation and performs no user or client-assertion authentication. Anyone who obtains a refresh token belonging to a private_key_jwt client can therefore call Convex directly and permanently strip scopes from its live grant without possessing the client's private key, bypassing the client authentication enforced by /oauth/token; make this helper internal and invoke it only through the authenticated server flow.
Useful? React with 👍 / 👎.
| let update = scopeUpdates.current.get(grantId); | ||
| if (!update) { | ||
| update = { scopes: [...grant.scopes], pending: Promise.resolve() }; | ||
| scopeUpdates.current.set(grantId, update); |
There was a problem hiding this comment.
Rebase queued changes on the current grant scopes
The map entry is initialized once and never synchronized when the reactive grant.scopes value changes. If another device, a refresh-token scope reduction, or another settings session changes this grant while the page remains mounted, the UI renders the new scopes but the next toggle is computed from the stale cached array and can silently restore permissions that were just removed. Refresh or discard the cached entry once pending work completes and the server value changes.
Useful? React with 👍 / 👎.
| fixture.t.mutation(internal.mcpOAuth.refreshAccessGrant, { | ||
| refreshToken: initial.refreshToken, | ||
| clientId: fixture.registration.client_id, | ||
| requestedScopes: ['finapp:read', 'finapp:write:social'], | ||
| }), |
There was a problem hiding this comment.
Pass the public-client transport in refresh tests
This newly added test invokes refreshAccessGrant without authTransport: 'none', but authenticateClient now rejects a public client unless that exact transport is supplied. Consequently the first assertion receives INVALID_CLIENT instead of the expected INVALID_SCOPE, and the regression test fails before exercising scope narrowing; the subsequent refresh calls in this test need the same transport argument.
Useful? React with 👍 / 👎.
| const grants = await ctx.db | ||
| .query('mcpOAuthGrants') | ||
| .withIndex('by_client', (index) => index.eq('clientId', clientId)) | ||
| .take(500); | ||
| .collect(); |
There was a problem hiding this comment.
Bound client deletion instead of collecting every grant
A dashboard client can be authorized repeatedly and there is no cap on grants per client, so replacing the bounded query with collect() makes this mutation perform an unbounded read followed by one write per active grant. Once a shared or repeatedly authorized client accumulates enough grants to exceed Convex mutation read/write limits, deletion rolls back and the owner can no longer delete or revoke that client through this path; process the grants in bounded batches instead.
Useful? React with 👍 / 👎.
| if (message.includes('INVALID_GRANT')) | ||
| return Response.json({ error: 'invalid_grant' }, { status: 400 }); | ||
| return Response.json({ error: 'server_error' }, { status: 503 }); | ||
| } |
There was a problem hiding this comment.
Align the invalid-grant regression with the new error contract
The existing bounded-form test mocks the mutation failure as new Error('Invalid authorization code') and expects HTTP 400, but this changed catch now recognizes only messages containing the exact uppercase INVALID_GRANT; that test therefore falls through to HTTP 503 and fails. Update the regression mock to use the backend's new sentinel error, or retain compatible classification for the mocked legacy message.
Useful? React with 👍 / 👎.
| const deployKey = process.env.CONVEX_DEPLOY_KEY?.trim(); | ||
| if (!deployKey) throw new Error('CONVEX_DEPLOY_KEY is required'); |
There was a problem hiding this comment.
Supply the deploy key in the credential-boundary test
The credential-boundary test's environment setup never defines CONVEX_DEPLOY_KEY. After this change, even its retry with a valid signing key throws here before reaching the stubbed Convex fetch, so the test receives another 503 instead of the expected successful token response. Stub a test deploy key in that suite or inject the admin client so the test can exercise the intended boundary.
Useful? React with 👍 / 👎.
- Expose internal mutation typing only on the admin-authenticated server client. - Guard the SDK internal admin-auth method at runtime.
|
@codex review |
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
- Model the no-secret token client transport in refresh grant tests.
Changes
Issues
Fixes #223
Fixes #224
Fixes #225
Fixes #226
Fixes #227
Fixes #240
Fixes #241
Fixes #251
Fixes #282