You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[SECURITY] Bind MCP approval retries to the original action and document client trust #827
Constituent of #769. Reviewed current main at 1de4135 on 2026-10-08; this issue proposes work, no implementation is included.
CWEs: CWE-863; CWE-639 is related but no tenant-key isolation claim is made.
Finding and evidence
pkg/mcp_server/gate.go accepts inputResponses.stackql_approval with action=accept before checking elicitation support. It neither emits nor verifies RequestState tying that answer to a previous prompt, tool, SQL or session/context.
Current in-memory MCP test sent a first-call mutation with an unsolicited accept response, no RequestState and no elicitation capability. The backend executed it under safe mode. The fixed input key is sufficient to reach this branch.
MCP approval is a cooperating-client workflow: a malicious client can claim a human accepted even if retries are bound correctly. This finding does not imply an HMAC can prove human consent or create RBAC.
Required outcome
Require a valid pending approval context bound to the exact action and arguments. Reject unsolicited, altered, expired and replayed responses using a design that supports both stateful and sessionless transports.
Verify elicitation capability/protocol handling on the approval path, including the older SDK-mediated round trip.
Document that safe/delete_safe trust the MCP client to present prompts faithfully; use server operator capabilities/read_only for actual restrictions against untrusted clients.
Validation and acceptance
Add protocol tests for an unsolicited accept, changed SQL/tool/arguments, replay, expiration, cross-session/context substitution, legitimate retry and unsupported elicitation. Assert no backend execution on rejection. Cover both pre-2026-07-28 and sessionless HTTP operation.
Scope and related work
Independent of semantic SQL classification and HTTP bearer authentication. Treat this as workflow-integrity hardening, not a claim of an independent human-authorization boundary.
I would like to take this one. Before writing it, this is the shape I have in mind.
On the first pass the gate returns a RequestState holding the tool name, a SHA-256 of the canonical arguments and SQL, the session or context id, a nonce and an expiry, signed with HMAC-SHA256 under a server key. On retry it rejects an accept with missing, altered or expired state, or with a digest that no longer matches the call, before approvalOutcome reads the answer. The key is random per process by default and configurable, so sessionless deployments behind several instances can share it. A consumed-nonce set blocks replay inside the expiry window. Without shared state across instances, replay is bounded only by expiry, and I would document that next to the cooperating-client note.
Tests would follow your acceptance list. Does a configurable key fit how you deploy the MCP server?
On deployment: stdio is the primary transport and the default, one process per client spawned by the host, so a random per-process key is the right default and needs no config. Streamable HTTP is supported and that is where a configurable key matters, for sessionless deployments (stateless: true or protocol_version: 2026-07-28) behind more than one instance. Follow the existing secret pattern: auth_token_env_var names an env var the server reads at startup, so an approval_key_env_var next to it would fit. Keep the key out of logs and the audit sink.
One thing to note: the stdio connection reports an empty session id (resilientStdioConn.SessionID()), so bind to the session id where there is one and let the per-process key carry stdio. In-process nonce tracking is fine there; the expiry-only bound for multi-instance HTTP is acceptable if documented as you suggest.
Keep the elicitation check ahead of reading the accept so the SDK-mediated round trip for older clients hits the same validation, and add a stateless HTTP case alongside the in-memory tests. Happy to review the PR.
Activity
aeoess commentedon Oct 17, 2026
I would like to take this one. Before writing it, this is the shape I have in mind.
On the first pass the gate returns a RequestState holding the tool name, a SHA-256 of the canonical arguments and SQL, the session or context id, a nonce and an expiry, signed with HMAC-SHA256 under a server key. On retry it rejects an accept with missing, altered or expired state, or with a digest that no longer matches the call, before
approvalOutcomereads the answer. The key is random per process by default and configurable, so sessionless deployments behind several instances can share it. A consumed-nonce set blocks replay inside the expiry window. Without shared state across instances, replay is bounded only by expiry, and I would document that next to the cooperating-client note.Tests would follow your acceptance list. Does a configurable key fit how you deploy the MCP server?
jeffreyaven commentedon Oct 17, 2026
Go for it, that would work.
On deployment:
stdiois the primary transport and the default, one process per client spawned by the host, so a random per-process key is the right default and needs no config. Streamable HTTP is supported and that is where a configurable key matters, for sessionless deployments (stateless: trueorprotocol_version: 2026-07-28) behind more than one instance. Follow the existing secret pattern:auth_token_env_varnames an env var the server reads at startup, so anapproval_key_env_varnext to it would fit. Keep the key out of logs and the audit sink.One thing to note: the
stdioconnection reports an empty session id (resilientStdioConn.SessionID()), so bind to the session id where there is one and let the per-process key carry stdio. In-process nonce tracking is fine there; the expiry-only bound for multi-instance HTTP is acceptable if documented as you suggest.Keep the elicitation check ahead of reading the accept so the SDK-mediated round trip for older clients hits the same validation, and add a stateless HTTP case alongside the in-memory tests. Happy to review the PR.
test(mcp): echo requestState on input_required approval retries
mcp_server: bind approval retries to the original action (#848)