Repository navigation
Description
Summary
ResponseFilteringWriter.processSSEResponse in pkg/authz/response_filter.go writes the entire raw upstream response unfiltered whenever any data: line in the SSE stream either fails jsonrpc2.DecodeMessage or decodes to a message that is not a *jsonrpc2.Response (for example, an MCP notification interleaved on the stream).
When this happens on a tools/list reply, the client receives the full unfiltered tool catalog — bypassing the cedar authorization filter that should have removed tools the caller can't invoke.
The same code path emits a visible side-effect: http: superfluous response.WriteHeader call from … response_filter.go:191. That warning is how we noticed the bug.
Confirmed against v0.27.0 (commit 182a025).
Impact
Authorization bypass on tools/list. A caller whose cedar policy denies every action on a backend can still receive that backend's full tool list, as long as the backend's SSE reply contains a data: line that doesn't parse as *jsonrpc2.Response. The bypass is silent — no cedar decision log lines are produced for that response, because the per-tool evaluation never runs.
Observed on proxyrunner:v0.27.0 with two MCPServers configured identically — same authzConfig (cedar policy denies all actions for the caller), same middleware chain (auth → tokenexchange → mcp-parser → usagemetrics → authorization → audit → recovery), same incoming transport_type: streamable-http. They differ only in the upstream backend image:
ghcr.io/stackloklabs/mkp/server:0.2.4(nativestreamable-http, JSON responses): pod logscedar decision: denyper tool, response correctly filtered to an emptytoolsarray. Expected.ghcr.io/gorizond/mcp-rancher-multi:0.1.16(fronted by the npmmcp-proxystdio↔SSE adapter,text/event-streamresponses): zerocedar decisionlines in pod logs, ~700INFO http: superfluous response.WriteHeader call from … response_filter.go:191warnings (one pertools/list), client receives the full unfiltered tool list. Bug.
The differentiating factor is the upstream MCP server's response Content-Type, which selects between processJSONResponse (works) and processSSEResponse (broken). The bug lives entirely on the SSE side.
Reproduction
-
Deploy two
MCPServers with identicalauthzConfigcontaining a cedar policy that denies all actions for a given caller, e.g.permit(principal, action, resource) when { context has claim_groups && context.claim_groups.contains(\"/never-matches\") }; -
Pick backends that produce different response framings:
- Backend A (filter works):
ghcr.io/stackloklabs/mkp/server:0.2.4. Responds withapplication/json. - Backend B (filter bypassed):
ghcr.io/gorizond/mcp-rancher-multi:0.1.16. Fronted by the npmmcp-proxypackage as a stdio→SSE bridge; responds withtext/event-stream.
- Backend A (filter works):
-
Call
tools/liston both with a token that cedar denies. -
Backend A: filtered response (empty
tools), pod logscedar decision: denyper tool. ✅ -
Backend B: full unfiltered
toolslist returned, pod logs onehttp: superfluous response.WriteHeader call from … response_filter.go:191per call. ❌
Both pods run proxyrunner:v0.27.0 with transport_type: streamable-http on the toolhive side.
Root cause
pkg/authz/response_filter.go, processSSEResponse, lines ~188–201 (v0.27.0):
if data, ok := bytes.CutPrefix(line, []byte(\"data:\")); ok {
message, err := jsonrpc2.DecodeMessage(data)
if err != nil {
rfw.ResponseWriter.WriteHeader(rfw.statusCode) // line 191
_, err := rfw.ResponseWriter.Write(rawResponse) // writes ENTIRE raw payload
return err
}
response, ok := message.(*jsonrpc2.Response)
if !ok {
rfw.ResponseWriter.WriteHeader(rfw.statusCode) // line 198
_, err := rfw.ResponseWriter.Write(rawResponse) // writes ENTIRE raw payload
return err
}
...
}Two problems:
-
Per-line failure aborts filtering of the whole stream. When any single
data:line fails to decode as*jsonrpc2.Response— either because of a decode error (line 191) or because the decoded message is a non-Response (e.g. a notification, line 198) — the function writesrawResponse(the entire buffered SSE payload) and returns. The apparent intent is "fall back to pass-through for this line," but the implementation passes through the whole response, including any subsequentdata:lines containing the realtools/listpayload. A single unparseable or non-Response line defeats filtering for the entire reply.Notifications interleaved on the response stream are explicitly permitted by the MCP spec (progress updates, log messages,
notifications/message, etc.). So even a fully spec-compliant upstream MCP server using SSE would trip the line-198 branch and silently bypass cedar. -
Double
WriteHeader. The fallback explicitly callsWriteHeader(rfw.statusCode). The wrapped writer may already have emitted headers viaFlush()(lines 125–130) beforeFlushAndFilterruns, particularly whenhttputil.ReverseProxyusesFlushInterval: -1. The net effect is thesuperfluous WriteHeaderwarning and undefined behavior around when/if the filtered output actually reaches the wire.
Suggested fix direction
- In
processSSEResponse, treat undecodable or non-Responsedata:lines as pass-through for that line only: write the original line and the line separator, thencontinuethe loop. Do not writerawResponseand do notreturn. - Audit the same pattern in
processJSONResponse(lines 132–145) — there it's the whole response by definition, so probably already correct, but worth a second look. - Consider WARN-logging when filtering is skipped on a
tools/listresponse so future bypasses surface in audit logs rather than going silent.
A regression test covering an SSE stream that mixes a non-Response data: line (e.g. a notifications/message) with a real tools/list response would catch this. The current pkg/authz/response_filter_test.go does not appear to exercise that path.
Versions
- toolhive
proxyrunner: v0.27.0 - Toolhive incoming transport:
streamable-http - Backend images used in repro:
ghcr.io/stackloklabs/mkp/server:0.2.4(filter works —application/jsonresponses)ghcr.io/gorizond/mcp-rancher-multi:0.1.16(filter bypassed —text/event-streamresponses via the npmmcp-proxybridge)
Activity
authz: drop disguised result frames and fix SSE line termination
Close disguised-result bypass on decode-error and batch frames
Stop SSE filter from leaking tools/list on undecodable lines (stacklo…
Fail closed on tools-list filtering failures, not raw pass-through
Stop SSE filter from leaking tools/list on undecodable lines (#5304)
Fix tool-filter terminal drain dropping error bodies (#5816)
Parse SSE responses per event, not per line
Parse SSE responses per event, not per line
Parse SSE responses per event, not per line (#6088)
fix(authz): commit recorded status before flushing in ResponseFilteri… (