part…
Building governance for MCP?
The gateway applies what the guide teaches: policies on discovery, invocation and authorisation.
The gateway applies what the guide teaches: policies on discovery, invocation and authorisation.
The spec's Security Best Practices document is the reference for MCP-specific threats. This lesson walks through them one by one with their conditions, flow and normative mitigations. Read it with Part 9 alongside.
Conditions: an MCP proxy uses a static client_id with a third-party AS; it allows MCP clients to register dynamically; the third party's AS sets a consent cookie after the first authorization; the proxy does not ask for per-client consent before forwarding.
Attack: the user authorises once (cookie); the attacker registers a client with their own redirect_uri and sends the user an authorization link; the third party's AS sees the cookie and skips consent; the MCP code ends up on the attacker's server, which redeems it and impersonates the user.
Mitigation (MUST): per-client consent before forwarding to the third party: a registry of user-approved client_ids, checked before the flow; a consent page of your own that identifies the client, shows scopes and redirect_uri, with CSRF and anti-clickjacking protection (frame-ancestors/X-Frame-Options: DENY); consent cookies with the __Host- prefix, Secure, HttpOnly, SameSite=Lax, signed, bound to the client_id; redirect_uri by exact match; random state, stored only after consent is approved, set just before redirecting, verified in the callback, single-use and with a short expiry.
Accepting tokens not issued for the server and forwarding them to downstream APIs. Risks: bypassing controls (rate limiting, validation), loss of traceability and audit, broken trust boundaries, difficulty evolving. Mitigation: servers MUST NOT accept tokens not explicitly issued for them.
During discovery, the client visits URLs the server gives it (resource_metadata, authorization_servers, AS endpoints). A malicious server can point to internal IPs, the cloud metadata endpoint (169.254.169.254), local services, use DNS rebinding or redirect chains. Mitigations (server-deployed clients MUST consider it; SHOULD): HTTPS mandatory except loopback in development; block private and reserved ranges (10/8, 172.16/12, 192.168/16, 127/8, ::1, 169.254/16, fc00::/7, fe80::/10) with proven libraries (octal/hex/IPv6-mapped encoding tricks fool home-grown parsers); validate redirect destinations or disable automatic following; egress proxies (e.g. Smokescreen); pin DNS resolution between check and use. ASes that fetch CIMD face the same risk.
Without sessions, state between requests consists of handles (cart, workflow). An attacker who obtains or guesses a handle operates on someone else's state. Mitigation: servers with authorization MUST verify every request and MUST NOT treat possession of the handle as authentication; SHOULD use random high-entropy handles with expiry; SHOULD bind them server-side to the user (<user_id>:<handle> derived from the verified token).
Malicious launch commands in configurations, payloads in the server itself, access via DNS rebinding to local servers. Risks: arbitrary execution with the client's privileges, no visibility, obfuscation, exfiltration, data loss. Mitigation: clients with one-click installation MUST ask for prior consent showing the exact, untruncated command, identifying it as dangerous, with explicit approval and the option to cancel; SHOULD highlight dangerous patterns (sudo, rm -rf, network, sensitive paths), warn that it runs with the client's privileges, run in a sandbox with minimal privileges and explicit additional permissions. Local servers SHOULD use stdio or, over HTTP, require a token or restricted IPC.
javascript: URLs passed to window.open (XSS) or URLs with shell injection when opened via cmd.exe/PowerShell/sh (RCE). Mitigation: clients MUST admit only http (loopback) and https; MUST reject javascript:, data:, file:, vbscript:; SHOULD use an allowlist; MUST NOT open URLs via a shell; SHOULD use CSP in web clients; MUST sanitise and validate all URLs received from servers.
If a local proxy launches stdio servers and an XSS steals the token the client uses to talk to that proxy, the attacker can ask it to launch arbitrary commands. Mitigation: avoid the originating vulnerabilities (6), sandbox and file restrictions for launched processes, logging of all stdio use, additional authorization for dangerous commands, least privilege for the proxy.
See 9.8: iss validation.
With CIMD, anyone can use a legitimate client's client_id (URL) and listen on a local port. Mitigation at the AS: warnings for localhost-only redirects, optional attestation, display the host of the redirect URI.
Domain allowlists, accept any HTTPS, reputation, domain age, prominently display the CIMD host to avoid phishing.
See 9.6: omnibus tokens widen the impact of a theft; minimal scopes and step-up.
Validate Origin (403), bind to 127.0.0.1, authenticate (6.2).
Tool names and descriptions, instructions, results and resources are text the model reads as instructions. A server can hide directives that affect even the use of tools from other servers (tool poisoning, tool shadowing) and change them after approval (rug pull). Mitigations from the local server guide: review descriptions, clients that pin definitions and re-prompt on change, a small roster.
1. What is the key condition that enables the confused deputy in an OAuth proxy?
The combination allows consent to be bypassed with a client registered by the attacker.
2. When should the consent state/cookie be set in the proxy?
If it is set earlier, the consent is useless.
3. How do you prevent a home-grown IP parser from being fooled in SSRF mitigations?
Octal/hex/IPv4-mapped IPv6 tricks fool hand-written parsers.
4. What must a client show before launching a local server configured in one click?
SEP-1024 and the security guide require it (MUST).