Part 10 of 17 · 1 min read
The confused deputy attack, step by step
What an MCP proxy needs to get wrong, all at once, before the attack works.
A server that wraps a third-party API is often an OAuth client of that API and an authorization server to its own clients at once. This is an MCP proxy. The attack needs four ingredients together. The first is one static client id with the third party. The second is self-registering clients. The third is a third party that remembers consent in a cookie per client id. The fourth is a proxy that skips its own consent step.
The attack: the victim signs in once through a legitimate client, and the third party sets a consent cookie for the proxy's client id. An attacker registers a client whose redirect address is theirs and sends the victim a link. The victim's browser still holds the cookie, so the third party skips its consent screen, and the proxy's authorization code goes to the attacker.
The proxy's requirements are as follows. It needs a registry of approved client ids per user, checked before the third-party flow. It needs a consent page naming the client, the scopes and the redirect address. Cookies must use the __Host- prefix, Secure, HttpOnly and SameSite=Lax, bound to the client id. Redirect addresses must match as exact strings. It needs a single-use, short-lived state stored only after consent is approved.