Topic 3 of 6 · 5 min read
Confused deputy attacks on MCP proxy servers
Goal: Find the step in an OAuth proxy flow that lets an attacker obtain an authorization code and state the required fix.
A confused deputy attack tricks an MCP proxy server, which holds real authority, into using that authority for an attacker's request. It happens when the proxy talks to a third-party authorization server with one fixed client id and trusts a consent the user gave earlier.
Check yourself · 1 of 3
What makes the proxy in a confused deputy attack the deputy?
Why it matters
Some MCP servers act as a proxy: the MCP client registers dynamically with the proxy, and the proxy sends the user to a third-party provider (for example a code host) using the proxy's own static OAuth client id. The MCP security best practices describe the weak point:
- A user signs in through the proxy once and approves access. The provider sets a consent cookie for the proxy's static client id.
- An attacker registers their own client with the proxy, using a redirect URI they control.
- The attacker sends the user a link to the provider's authorization page with that redirect URI.
- The provider sees the cookie, skips the consent screen and issues an authorization code.
- The code goes to the attacker's redirect URI, and the attacker exchanges it for access to the user's account.
The user was never asked about the attacker's client, because consent was tied to the proxy's single id, not to each client behind it.
How to review a proxy flow
- Find where consent is recorded. Is it per MCP client id or per proxy?
- Check the redirect URI against the exact URI registered for that client, with no prefix or wildcard match.
- Check
state. It must be random, tied to the user's session and checked on return. Set the cookie only after the user approves. - Require per-client consent in the proxy before it forwards to the provider, with a screen that names the client, the redirect and the scopes.
Before and after
// weak: trusts the provider's earlier consent
app.get("/authorize", (req, res) => {
const client = clients.get(req.query.client_id);
res.redirect(buildProviderUrl({ clientId: STATIC_ID, redirect: req.query.redirect_uri }));
});
// fixed: the proxy asks first, per client, and checks the redirect exactly
app.get("/authorize", (req, res) => {
const client = clients.get(req.query.client_id);
if (!client || !client.redirectUris.includes(req.query.redirect_uri)) return res.status(400).end();
if (!consent.has(req.session.user, client.id)) return renderConsentPage(res, client);
res.redirect(buildProviderUrl({ clientId: STATIC_ID, state: signState(req.session) }));
});
What goes wrong
- Skipping the proxy's own consent page because the provider already shows one.
- Matching redirect URIs loosely, so an attacker's URL passes.
- Setting the consent cookie before approval, which lets a crafted link reuse it.
Examples
The skipped consent screen
Dana approved a code-host login through a proxy last week. An attacker registers a client named Docs Helper with the proxy and emails Dana a link. Her browser still holds the provider's consent cookie for the proxy's static id, so no screen appears and the code goes to the attacker.
The fix is for the proxy to show Dana a consent page for Docs Helper, with its redirect URI and scopes, before any redirect to the provider.
Prefix match on the redirect
A proxy accepts any redirect URI that starts with the registered https://app.example.test/cb. An attacker uses https://app.example.test/cb.evil.example/x. Use exact string comparison against the registered value instead.
Key points
- A confused deputy attack makes a proxy with real authority act for an attacker's request.
- The hole opens when a proxy uses one static client id with a provider and relies on the provider's cached consent.
- The attacker registers a client with a redirect URI they control, and the user's earlier consent lets the code go there.
- The proxy must collect consent for each dynamically registered client before forwarding to the provider.
- Compare redirect URIs exactly and tie a random
stateto the user's session.
Common mistakes
- Assuming the provider's consent screen protects every client behind a shared id.
- Allowing wildcard or prefix matches on redirect URIs.
- Using a predictable or unverified
statevalue. - Storing consent per user instead of per user and client.
Check yourself · 2 of 3
An attacker registers a client with a proxy and gets a user to open a crafted authorization link. The user sees no consent screen. Why?
Check yourself · 3 of 3
Which fix does the MCP guidance require of a proxy that uses a static client id?
Practice items, not counted towards your mastery.
Start here
- MCP security best practices (opens in a new tab)DocsFree
The protocol's own list of attacks: confused deputy, token passthrough, SSRF, session hijacking and local server compromise.
- Invariant Labs: MCP tool poisoning attacks (opens in a new tab)ArticleFree
The original write-up of hidden instructions in tool descriptions, with a working example.
- Simon Willison: Model Context Protocol has prompt injection security problems (opens in a new tab)ArticleFree
Shows tool poisoning, shadowing and rug pulls in one short, readable survey.
More for this topic
- MCP specification: Authorization (opens in a new tab)StandardFree
The normative rules on audience binding, resource indicators and token handling.