Skip to content

tools/list is not filtered on the SSE transport #6926

Done

Description

@rkb32

Bug description

With an HTTP PDP, tools/list is not filtered on the SSE transport. The PDP receives no tools/list requests, and every tool is listed. tools/call is still denied correctly.

Steps to reproduce

  1. Run thv run osv --transport sse --authz-config <config>, where the HTTP PDP allows mcp:tool:call only for query_vulnerability.
  2. Send tools/list over the SSE connection.

Expected behavior

Only query_vulnerability is listed.

Actual behavior

All three tools are listed: get_vulnerability, query_vulnerabilities_batch, and query_vulnerability.

Environment

  • OS/version: Windows 11 with WSL2 (Ubuntu 24.04)
  • ToolHive version: v0.55.2

Additional context

Also reproduced on main, so this predates #6903. Streamable HTTP lists only the allowed tool, so the gap is specific to SSE.

I found this while reviewing #6903. I'd like to work on it if a maintainer agrees it's worth doing. Could you assign it to me once you've had a look? Thanks.

Activity

  1. added
    needs-triage
    on Oct 22, 2026
  2. removed
    needs-triage
    on Oct 23, 2026
  3. aponcedeleonch commented on Oct 23, 2026

    @aponcedeleonch
    Member

    Thanks for the report, @rkb32, and for checking it on main as well. This matches how the SSE transport works today: the tools/list result comes back over the event stream rather than in the POST response, so the authz response filter never gets to see it. Calls are still denied, so the gap is in what gets listed.

    It isn't on our roadmap right now, but we'd welcome a fix, and since you offered, I've assigned it to you. Before you go deep, you can either sketch the approach here in a few lines (where the filtering would hook into the SSE stream, and how it stays consistent with streamable HTTP), or open a draft PR directly and we'll look at the design there. Please link the PR with Fixes #6926 in the description.

    Thanks again for the clear write-up.

  4. rkb32 commented on Oct 23, 2026

    @rkb32
    ContributorAuthor

    Thanks for the review @aponcedeleonch I Reproduced on main (7970d58). The test is TestSSEToolsListIsFilteredByAuthz in pkg/transport/proxy/httpsse/tool_list_authz_test.go. It's a unit test over the legacy SSE proxy with an authz middleware, and it fails the same way on main.

    What happens: the caller can read only weather. The tools/list answer on the GET /sse stream still contains secret. The POST returns 202, and the authz middleware only filters the POST response, so the list on the stream is never checked.

    Approach:

    • Where it hooks in: the authz middleware sees the GET /sse request. When the response is text/event-stream, it wraps the response writer, buffers each complete SSE event, and filters any message whose result.tools is an array, then emits the event.
    • Consistency with streamable HTTP: it uses the same tool:read check and the same filter helper as the POST path. The difference is granularity: streamable HTTP filters one response per request, while SSE filters each message on the stream. The identity comes from the stream's own request, which is the session owner's.
    • Dependency: it builds on Make tool:call imply tool:read for tool listing #6903 (the tool:read decorator), which is still open. I'd rebase on it or merge it first.
    • Not in scope: the stdio-backed httpsse path and prompts, resources, and skills lists.

    I'll open a draft PR with Fixes #6926 once the approach is agreed.

  5. aponcedeleonch commented on Oct 27, 2026

    @aponcedeleonch
    Member

    Thanks @rkb32, this is a solid write-up. The diagnosis matches what I see on main, and hooking into the authz middleware on the GET /sse response is the right place for it.

    There's already a precedent for this that I'd like you to reuse. The --tools filter (NewListToolsMappingMiddleware in pkg/mcp/tool_filter.go) already wraps the GET /sse stream. It buffers complete events and rewrites any data: frame carrying result.tools. Its toolFilterWriter already handles the streaming details: holding back partial events until they're complete, the final drain when the handler returns, and refusing to pass a list through when it can't be filtered. I'd model the new writer on it rather than starting from scratch. The existing ResponseFilteringWriter won't work as-is, because it buffers until the handler returns, and on GET /sse that only happens when the client disconnects.

    That precedent only matches tools, but I don't think prompts, resources, resource templates, and skills should be out of scope. They leak on SSE exactly the same way. pkg/authz/response_filter.go already has a filter for each of them. So the stream writer can look at which member the result carries (tools, prompts, resources, resourceTemplates, skills) and hand it to the matching filter. Please also reuse the fail-closed handling in filterSSEEventData, so frames that try to sneak a result past the filter get rejected on the stream the same way they are on the POST path. Since the stream path picks the filter by result shape instead of the request method, please call that out in the PR as a deliberate difference from the POST path.

    On stdio, I'd also bring it into scope. The httpsse proxy wraps GET /sse in the same middleware chain as the transparent proxy, so the fix covers it with no extra work. Your test actually runs against httpsse, which is the stdio path. The original report (--transport sse with osv) goes through the transparent proxy in pkg/transport/proxy/transparent. Could you add a test there as well, so both are covered?

    One smaller note: I don't think you need to wait on #6903. If the stream path calls the same filterToolsResponse as the POST path, it'll check tool:call today and switch to tool:read automatically once #6903 merges.

    Happy to look at a draft PR whenever you're ready.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions