Repository navigation
fix(mcp): check the token's audience, cap body reads and batches - #45
Merged
Merged
Conversation
- Carry an app's RFC 8707 resource from the code onto its grant and its access and refresh tokens (renewals keep it), and expose it on the Principal. /mcp refuses an lo_ token whose resource names another server (Lens and its /mcp, on any address Lens is reached at, pass). - Check Content-Length and read the body as a capped stream, so a message over MAX_BODY is never held whole. - Cap JSON-RPC batches at 20 messages. - get_entity's mentions_offset gets search's 10000 maximum. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TUqMhwUCvF9dsP5JzVvMJf
Owner
Author
|
All five checks failed within seconds of starting on 90e9783: Conventional Commit title, pre-commit, Next.js, and FastAPI on both embedded SurrealDB and the SurrealDB server. That matches main and every other open PR today. The GitHub-hosted runners aren't starting jobs at all (no logs), and #27 moves CI onto the self-hosted runner. Nothing here is this PR's failure. The title is Conventional ( Generated by Claude Code |
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.
Requested by Adeel · project thread
Follow-up to #43 from its review.
Before: an app could name the server it wanted a token for (
resource, RFC 8707), but that was dropped once the code was swapped for tokens, so /mcp accepted a token asked for any server. /mcp also read the whole body before checking its size, took batches of any length, andget_entity'smentions_offsethad no upper bound.After: the token keeps its
resourcethrough every renewal, and /mcp refuses one that names another server with a 401 that points the app at where to sign in for this one. A token for Lens or its/mcp, on any address Lens is reached at, still works. Bodies over 1 MB get a 413 from Content-Length, or once the stream passes the limit, and are never held whole. Batches hold 20 messages at most, andmentions_offsetstops at 10000 likesearch's offset.How:
resourcegoes from the oauth_code onto the grant and both token rows in_issue.refreshpasses it on, andtoken_accountreturns it on thePrincipal. The check,_audience_ok, and the capped read,_read, are inapp/api/mcp.py. The REST API doesn't check the audience, as before.Validation: GitHub-hosted runners aren't available, so this was checked locally. Ruff, ruff format and mypy are clean, and the full backend suite ran on embedded SurrealDB and on a SurrealDB 3.2.4 server. New tests cover the audience across renewals, the batch cap, oversized bodies (with and without Content-Length) and the offset maximum.
🤖 Generated with Claude Code
https://claude.ai/code/session_01TUqMhwUCvF9dsP5JzVvMJf
Generated by Claude Code