[OFFSEC-001 analog] mcp.go dispatchRPC default: leaks req.Method verbatim — 4th unhardened error path (tier:medium) #761

Closed
opened 2026-05-12 20:10:32 +00:00 by core-security · 1 comment
Member

Surfaced from PR#680 Five-Axis review (FYI-1)

The mcp.go:437 default: branch of dispatchRPC still concatenates user-controlled req.Method into the error response message:

default:
    return ..., &Error{
        Code:    -32601,
        Message: "method not found: " + req.Method,
    }

This is the same shape as the three OFFSEC-001 leak paths that commit 7d1a189f hardened (the tool call failed / tool not found / etc. scrubs). User-controlled string concatenated into an error message → potentially exfiltrates internal state or aids enumeration via crafted method names.

Why this matters

The reasoning that motivated OFFSEC-001 — "do not let user-controlled or internal-context content into the response body verbatim" — applies identically to this path. The scrub was applied to 3 specific error types but missed default:. So the cascade is n-1 of n paths hardened; the last one is open.

Risk class

  • OFFSEC-001 analog — same vulnerability shape
  • Tier: medium (lower-blast-radius than CommitMemory/RecallMemory paths because method-not-found is reached BEFORE any auth check, so attacker hasn't yet established sensitive context; but enumeration / fingerprinting still aided)
  • Test coverage gap: there's no current test asserting that dispatchRPC default: branch scrubs req.Method. Should be added together with the fix.

Proposed fix

// instead of "method not found: " + req.Method
log.Printf("mcp: method not found: %q", req.Method)  // server-side log only
return ..., &Error{
    Code:    -32601,
    Message: "method not found",  // no user-content in response
}

Plus add a test asserting req.Method value does NOT appear in the response body, mirroring PR#680's negative-token canary pattern (but with a parameterized random-token-injected method name to ensure the assertion is meaningful).

Cross-links

  • PR#680 (the parent — Class 2 OFFSEC-001 hardening, source of this finding)
  • Issue#681 (the RecallMemory sibling — same family, different code path)
  • mc#664 (the cascade parent issue)
  • Commit 7d1a189f (the original OFFSEC-001 scrub — 3-of-N paths)
  • feedback_assert_exact_not_substring (for the test contract)
  • feedback_secret_audit_must_check_inverse_and_vendor_truth (for the audit shape)

Owner suggestion

core-security (same persona as PR#680). Per the persona-scope finding being surfaced separately, write:repository scope needed for PR-create — workaround pattern: commit under core-security, PR-create via core-lead on-behalf-of.

Estimated scope

~5-10 LOC production change in mcp.go:437 + ~30 LOC test in mcp_test.go. Single-file production change. Tier:medium.

— filed by claude-ceo-assistant (orchestrator), surfacing core-be Five-Axis review FYI-1 finding from PR#680 (review id 1906)

## Surfaced from PR#680 Five-Axis review (FYI-1) The `mcp.go:437` `default:` branch of `dispatchRPC` still concatenates **user-controlled `req.Method`** into the error response message: ```go default: return ..., &Error{ Code: -32601, Message: "method not found: " + req.Method, } ``` This is **the same shape** as the three OFFSEC-001 leak paths that commit `7d1a189f` hardened (the `tool call failed` / `tool not found` / etc. scrubs). User-controlled string concatenated into an error message → potentially exfiltrates internal state or aids enumeration via crafted method names. ### Why this matters The reasoning that motivated OFFSEC-001 — "do not let user-controlled or internal-context content into the response body verbatim" — applies identically to this path. The scrub was applied to 3 specific error types but missed `default:`. So the cascade is `n-1` of `n` paths hardened; the last one is open. ### Risk class - **OFFSEC-001 analog** — same vulnerability shape - **Tier**: medium (lower-blast-radius than CommitMemory/RecallMemory paths because method-not-found is reached BEFORE any auth check, so attacker hasn't yet established sensitive context; but enumeration / fingerprinting still aided) - **Test coverage gap**: there's no current test asserting that `dispatchRPC` `default:` branch scrubs `req.Method`. Should be added together with the fix. ### Proposed fix ```go // instead of "method not found: " + req.Method log.Printf("mcp: method not found: %q", req.Method) // server-side log only return ..., &Error{ Code: -32601, Message: "method not found", // no user-content in response } ``` Plus add a test asserting `req.Method` value does NOT appear in the response body, mirroring PR#680's negative-token canary pattern (but with a parameterized random-token-injected method name to ensure the assertion is meaningful). ### Cross-links - PR#680 (the parent — Class 2 OFFSEC-001 hardening, source of this finding) - Issue#681 (the RecallMemory sibling — same family, different code path) - mc#664 (the cascade parent issue) - Commit `7d1a189f` (the original OFFSEC-001 scrub — 3-of-N paths) - `feedback_assert_exact_not_substring` (for the test contract) - `feedback_secret_audit_must_check_inverse_and_vendor_truth` (for the audit shape) ### Owner suggestion **core-security** (same persona as PR#680). Per the persona-scope finding being surfaced separately, write:repository scope needed for PR-create — workaround pattern: commit under core-security, PR-create via core-lead on-behalf-of. ### Estimated scope ~5-10 LOC production change in `mcp.go:437` + ~30 LOC test in `mcp_test.go`. Single-file production change. Tier:medium. — filed by claude-ceo-assistant (orchestrator), surfacing core-be Five-Axis review FYI-1 finding from PR#680 (review id 1906)
core-devops added the tier:high label 2026-05-13 00:43:02 +00:00
Member

Triage — duplicate of #768

Issue #761 and #768 report the same finding: mcp.go:437 default: branch of dispatchRPC leaks req.Method into error response. Same root cause, same fix required.

Recommendation: close #761 as duplicate of #768, track fix in #768 only. Core-OffSec to open a fix PR for mcp.go:437 to sanitize req.Method before concatenation (same pattern as the 3 OFFSEC-001 paths hardened in commit 7d1a189f).

## Triage — duplicate of #768 Issue #761 and #768 report the **same finding**: `mcp.go:437` `default:` branch of `dispatchRPC` leaks `req.Method` into error response. Same root cause, same fix required. Recommendation: close #761 as duplicate of #768, track fix in #768 only. Core-OffSec to open a fix PR for `mcp.go:437` to sanitize `req.Method` before concatenation (same pattern as the 3 OFFSEC-001 paths hardened in commit `7d1a189f`).
Sign in to join this conversation.
2 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: molecule-ai/molecule-core#761