Repository navigation
Filter SSE list answers on the event stream - #6949
Conversation
Codex Review SummaryThis 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. |
f4289c8 to
17c0685
Compare
aponcedeleonch
left a comment
There was a problem hiding this comment.
Thanks for this, @rkb32. It follows the direction from #6926 closely: it's modeled on toolFilterWriter, covers all five list types, reuses the shared per-type filters so the semantics match the POST path, and the transparent-proxy test is there. I also appreciate how candid the description is about the limitations.
The main thing to fix is that the stream path re-implements the head of resolveSSEEvent instead of reusing it, and in doing so it drops some of the POST path's fail-closed checks. Two of them can leak an unfiltered list from a hostile backend. Details are inline, and each fix should be small.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #6949 +/- ##
=========================================
+ Coverage 0 82.15% +82.15%
=========================================
Files 0 932 +932
Lines 0 94889 +94889
=========================================
+ Hits 0 77957 +77957
- Misses 0 16927 +16927
- Partials 0 5 +5 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
17c0685 to
27113bf
Compare
5c86827 to
0702a94
Compare
aponcedeleonch
left a comment
There was a problem hiding this comment.
Thanks for the quick turnaround, @rkb32. Almost everything from the last two rounds is in. The split BOM, the SSE-framed mislabeled body and the mid-stream test all look good, and sniffBodyShape is a step in the right direction.
The main thing left is the reuse point. The per-event filtering is shared now, but the framing loop, the head of resolveSSEEvent, the mislabeled-body decision and the list mapping are still written twice, and one of them has already drifted. Details inline.
Two things that don't fit on a line:
- The PR body is out of date. It still says a mislabeled 2xx is "read as one JSON-RPC message, as the reviewer suggested" and that anything that isn't JSON-RPC is dropped, but a body with no result now passes through. The trade-off that a mislabeled body is held until the handler returns should be in there too, plus the POST path changes (see inline).
- The non-test change is around 680 lines, over the 400-line guideline. Moving the POST path fixes to their own PR would bring it closer and make both easier to review. Also, the test plan should use
task testrather thango test.
A POST body that carries a result past encoding/json's depth cap was written unfiltered. Reject it instead, answering with the request id, as the GET stream does. Also filter a result split across lone CR line breaks, and share the no-shape decision between the POST path and the GET stream so the two cannot drift apart.
|
@aponcedeleonch Thanks for the reviews. Two things before I reply to each thread: Correction: my earlier reply said the cap is 1 MiB. It's 16 MiB, matching the default in pkg/mcp/tool_filter.go. The docs and PR body say so. |
0702a94 to
375410e
Compare
b719112 to
42163f0
Compare
6497a3b to
1c6f188
Compare
The GET event stream carried list answers unfiltered. Filter each event as it arrives, choosing the filter from the shape of its result, with the same per-entry authorization as the streamable path. Answer rejected frames with a JSON-RPC error that carries the request id, so the client does not wait for a timeout. Document the limits: a 16 MiB cap on an open event, a held body sniffed before it is filtered, and a 101 upgrade through ReverseProxy, which is refused.
The POST path and the GET stream each decided how to handle a 2xx body with an unrecognised media type, in different orders. Move that decision into one classifier. Each caller still writes its own rejection and chooses its own request id, so no response changes.
1c6f188 to
c214582
Compare
aponcedeleonch
left a comment
There was a problem hiding this comment.
Decode each GET stream list response once instead of twice, and log filtering errors on the GET stream at WARN so the POST path keeps its ERROR level.
A tools/call answer from a non-find_tool tool with a named tools list is treated as a find_tool answer on the GET stream, because the stream cannot see the request. Pin that it fails closed, and document it in authz.md with the point where the caller's identity is read. The list-member test now loops over the list filter kinds, so a new kind that no listMembers entry reaches fails the test.
A tool answer whose content names a tools member anywhere, outside a readable find_tool answer, passed through the GET stream unfiltered. Such answers now fail closed. Log each filter failure once, and fix comments and docs that the change made stale.
Add a table test for the three tool answer shapes that named tools outside a readable find_tool output. Unwrap a JSON string literal when looking for a tools member, so a doubly encoded list fails closed too. Narrow the docs sentence to a tools member that names a tool.
A find_tool-shaped answer on the GET stream could carry tool names in _meta, an extra content member, or a member beside tools, and those reached the client unfiltered. Empty every tools list and fail closed if a tools name remains. Check the emptied copy so an authorized tool whose schema has a tools property still passes. POST is unchanged.
Only another tools member is checked, not a tool name under other keys. Make the beside-tools test depend on the fix by putting the extra member in both outputs. Correct the docs and comment to match.
Every GET now drops Accept-Encoding and ends a coded stream with 502, not 500. A role or token change during the stream applies on reconnect.
The 502 replaces the response before any event is sent. Describe every GET as the event stream and rewrap the paragraph.
Move the JSON-in-string branch into mentionsToolsString so the function is under the gocyclo limit of 15. Behavior is unchanged.
Define the list kinds once in listKinds and build listMembers from it, so a new list kind is added in one place. responseFilterForMethod reads the same table. Behavior is unchanged.
The event-stream writer supplies its shape rules to the shared filter as selectMethod, and both the event and sniffed-body paths ask the writer for the method. The find_tool and tools-member rules stay in the stream file. Behavior is unchanged.
|
Thanks for the review. Status by point:
|
Split the GET-stream paragraph into an intro and a list of observable behavior, state that permissions are taken at connect, and say why the duplicate result-key check exists only on the stream path.
Add the observable GET-stream behaviors that the review asked to see: non-MCP GETs on the transparent proxy, Cache-Control on filtered 2xx responses, and refused connection upgrades.
c214582 to
683dac0
Compare
The media-type, sniff and decide comments still described the earlier drop-everything behavior. Describe rejection, pass-through, and the held-body limit as the code does.
aponcedeleonch
left a comment
There was a problem hiding this comment.
Thanks for sticking with this, @rkb32. Everything from the last round is in, and the new find_tool checks look good to me.
Two small things before merging, neither blocking:
- The PR body is a bit behind the code. It still says 1 MiB instead of 16 MiB, says non-JSON-RPC bodies are dropped, and lists find_tool as a gap. It'd also help to mention that it depends on #7211, and the user-facing changes that are only in the docs today (every GET wrapped, Accept-Encoding stripped, the 502, tools/call answers with a tools list failing closed).
- nit: in docs/authz.md, "A frame with no readable id is dropped" reads like notifications get dropped too. Something like "A frame that fails closed but has no readable id is dropped" would be clearer.
Fixes #6926.
Includes the POST-path hardening first proposed in #7211 (closed unmerged).
Summary
Why: Over SSE, list answers (tools, prompts, resources, resource templates, skills) reached the client on the GET event stream, which was not filtered.
What: Each GET event is now filtered as it arrives, with the same per-entry authorization as the streamable path. The filter is picked from the shape of each result. find_tool answers are filtered too.
Does this introduce a user-facing change?
toolskey (other than a valid find_tool answer). Before: passed through. After: a JSON-RPC error carrying the request id.Accept-Encodingpassed through. After: stripped; a content-coded 2xx stream gets502 Bad Gateway. A filtered 2xx GET carriesCache-Control: private, no-store. Upgrade requests are refused.text/event-stream. Before: body passed through. After: read as one JSON-RPC message or as SSE. A list answer is filtered and sent; other clean answers are sent unchanged; a body that names a result it cannot read is rejected with an error carrying its id, or dropped if no id can be read. Bodies with no result pass through unchanged. Non-2xx bodies pass through unchanged.Special notes for reviewers
_meta.related) is not checked on the GET stream.Test plan
go testforpkg/authz/...,pkg/transport/proxy/httpsse,pkg/transport/proxy/transparent(run locally, not viatask)🤖 Generated with Claude Code