Repository navigation
fix(mcp): don't panic when a transport has no request echo - #14
Open
S3DFX-CYBER wants to merge 1 commit into
Open
S3DFX-CYBER wants to merge 1 commit into
S3DFX-CYBER wants to merge 1 commit into
Conversation
RawResult.Exchange() documents that it returns nil when ReqMethod is empty —
"e.g. a WebSocket transport, which has no per-message HTTP request to
curl-replay" — and WSSession honours that. Two anyTransport probes then
dereference the result anyway:
reqExch := raw.Exchange()
reqExch.Expected = "..."
A WebSocket MCP endpoint that answers tools/list anonymously therefore
crashes reap with a nil pointer dereference at checks.go:650 (and the same in
resourcesPromptsExposureProbe). WSSession also sets StatusCode 200 on every
dispatched frame, so the status guard that would otherwise stop the probe
never fires on that transport. In batch mode the panic happens inside a
worker goroutine, which is unrecoverable: one hostile host takes down the
whole run and discards every other report.
Fix, three parts:
- guard the two dereferences, since annotating the reproduction is optional
and recording the finding is not;
- teach WSSession to populate the echo it can know (ReqMethod "WS-FRAME",
the target URL, and the frame body), where the outgoing body is in scope,
so a WebSocket finding carries the same request-side evidence an HTTP
finding does;
- return "" from Curl/ReproScript for a non-HTTP scheme rather than
rendering a curl command that cannot work.
Tests: TestAnyTransportProbesSurviveEmptyRequestEcho runs every anyTransport
probe against a stub session whose results have an empty ReqMethod, and
TestFindingsSurviveNilExchange asserts the finding is still recorded.
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.
What happens
A WebSocket MCP endpoint that answers
tools/listanonymously crashesreap:Exit code 2, no report written.
mcp-resources-prompts-exposurecrashes the same way a few lines further down.Why
RawResult.Exchange()documents its nil case precisely — it returnsnilwhenReqMethodis empty, "e.g. a WebSocket transport, which has no per-message HTTP request to curl-replay".WSSessionhonours that:handleMessagebuilds&probe.RawResult{StatusCode: 200, Body: payload}with noReqMethod.Two
anyTransportprobes then do:Every other call site is safe — the rest assign
Exchange()straight intoFinding.Request, where nil is fine, or sit behindhttpOnlyTransports. These two are the only ones that dereference it, and they are reachable over WebSocket.WSSessionalso setsStatusCode: 200on every dispatched frame, so theraw.StatusCode != 200guard that would otherwise stop the probe never fires on this transport.Impact
Availability of the scan, which for a recon tool is the whole product: a target that can abort the scan can also hide everything else it exposes. In batch mode the panic happens inside a worker goroutine, which is unrecoverable in Go — one hostile host in a
--targets-fileof a thousand takes down the run and discards every other report, since results are only written afterwg.Wait().Reproduction
A minimal MCP-over-WebSocket server is enough: complete the upgrade, answer
initialize, then answertools/listwith at least one tool. No auth, no interaction.Discovery resolves
websocketvia themcp-websocketdetector,newSessionForTransportbuilds aWSSession, and the process dies inunauthToolsListProbe.The fix
Three parts:
WSSessionto populate the echo it can know — a smallfillEchohelper setsReqMethod: "WS-FRAME",ReqURL: s.targetURL,ReqBody: body. This is done inDo, where the outgoing frame body is in scope, so it costs nothing, and it means a WebSocket finding carries the same request-side evidence an HTTP finding does.HTTPExchange.Curl()andReproScript()return""for a non-HTTP scheme, so a WS finding showsEvidence WS-FRAME ws://… → 200 • 229 Binstead of acurlcommand that cannot work. SARIF already omitsproperties.reproducewhen the string is empty.The guard alone stops the panic but leaves the finding with no reproduction evidence at all, which is the opposite of what the rest of this codebase optimises for — hence part 2.
Verification
TestAnyTransportProbesSurviveEmptyRequestEchoruns everyanyTransportprobe against a stub session whose results have an emptyReqMethod— the exact shapeWSSessionused to produce — and asserts no panic. It fails onmain(both probes) and passes with the patch.TestFindingsSurviveNilExchangeasserts the anonymoustools/listfinding is still recorded over such a transport.tools/listfinding carriesWS-FRAME … → 200 • 229 B.go test ./...green (122 tests),go vet ./...clean.Not in scope, noticed while here
WSSession.runReadercaps each frame at 4 MB but accumulates continuation fragments intoaccwith no total bound (session_ws.go:160), so a server can stream fragments until the scanner exhausts memory. Same class, lower likelihood — happy to send a follow-up that applies the existingmaxResponseBytescap to the reassembled message if you'd like it in the same release.