Skip to content

fix: validate resource URIs and cap subscriptions per session - #1095

Open
ez-lbz wants to merge 1 commit into
modelcontextprotocol:mainfrom
ez-lbz:validate-resource-subscriptions
Open

ez-lbz wants to merge 1 commit into
modelcontextprotocol:mainfrom
ez-lbz:validate-resource-subscriptions

Conversation

@ez-lbz

@ez-lbz ez-lbz commented Aug 16, 2026

Copy link
Copy Markdown

The spec's server resources security guidance requires servers to validate all resource URIs. The read path validates URIs against the registered resources and resource templates, but resources/subscribe accepted any string URI into an unbounded map, so an authenticated client could grow memory without limit.

This change makes the subscribe handler resolve the URI through the same resource/template lookup as the read path and reject unknown URIs with the same Resource Not Found error (-32002). It also caps the number of resource subscriptions per session (1024); further subscribe requests are rejected with Invalid Params (-32602).

Tests cover subscribing to a registered URI (success), an unregistered URI (Resource Not Found), and exceeding the per-session cap (Invalid Params).

@ez-lbz
ez-lbz force-pushed the validate-resource-subscriptions branch from aecaf5f to 740e6df Compare September 16, 2026 02:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant