Skip to content
XSS Write-up Intermediate

Shaking the MCP Tree: a security deep dive

The post describes vulnerabilities in MCP servers that allow open Dynamic Client Registration (DCR), enabling attackers to register OAuth clients with arbitrary redirect URIs. This leads to DOM-based XSS, stored XSS on consent screens, and a full-read SSRF via path normalization and open redirect.

Amirmohammad Safari Follow

Published on blog.voorivex.team

In this post, I'll show you what happens when that tradeoff goes wrong. We'll look at how MCP servers handle authentication, why a feature called Dynamic Client Registration is often left wide open, and how attackers can exploit it.

Amirmohammad Safari, on blog.voorivex.team

The full write-up lives on its author's site

It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 13 min read.

MCP servers sit between AI assistants and the outside world: they translate a model's request into an action against Slack, Google Drive, Salesforce or a calendar, and hand the result back in a format the model understands. Most of them authenticate with OAuth 2.0, and many of them expose Dynamic Client Registration (DCR) without any gate in front of it. This write-up walks through what that means in practice: how to detect open DCR at scale, the XSS and consent-screen problems that follow from it, how to use a self-registered client to talk to an MCP server directly, and how a DCR endpoint became the open redirect that turned a whitelisted document fetcher into a full-read SSRF.

Context

MCP stands for Model Context Protocol. The useful mental model is a translator: the AI speaks one language, the app speaks another, and the MCP server sits in the middle. Without it, an assistant can only read what you type and write back; with it, the assistant can reach out and do things.

A typical request flows like this:

  1. Claude realises it needs your calendar data, which it does not have.
  2. Claude calls the Google Calendar MCP server.
  3. The MCP server logs into your calendar, grabs tomorrow's meetings and organises the information.
  4. It sends everything back to Claude in a format Claude understands.
  5. Claude shows you your schedule.
MCP server workflow diagram
MCP server workflow diagram From the original on blog.voorivex.team

The user only sees the answer. The authentication layer underneath is ordinary OAuth 2.0, and that is where the interesting decisions get made.

Dynamic Client Registration

Traditionally, becoming an OAuth client was a manual process: forms, review, and eventually a client_id and client_secret. The provider knows who you are, controls which redirect URIs you may use, and can revoke you at any time. Slow, but secure.

RFC 7591 changed that. With DCR, a client registers itself by sending a POST to the registration endpoint (/register) with its own details:

JSON
{
  "redirect_uris": ["https://legit-app.com/callback"],
  "client_name": "Totally Legit App",
  "token_endpoint_auth_method": "none",
  "grant_types": ["authorization_code", "refresh_token"],
  "response_types": ["code"]
}

The response contains a fresh client_id, and sometimes a client_secret as well. No questions asked, no humans involved, fully automatic.

DCR registration flow
DCR registration flow From the original on blog.voorivex.team

The motivation is flexibility: any AI tool should be able to connect quickly. The consequence is that anyone can become an OAuth client, and the redirect URI is whatever the client asked for.

Setup

The research used a Nuclei template for discovery and manual work against the endpoints it found.

For the later stage, connecting to an MCP server directly, the researcher used MCP Inspector, installed and run with:

Bash
npx -y @modelcontextprotocol/inspector npx @playwright/mcp@latest

That starts a local web interface, typically on http://localhost:6274.

Finding it

Manual testing does not scale, so the discovery step was automated. The first question is where registration endpoints live at all. OAuth and OIDC servers publish their configuration through well-known URIs: RFC 8414 defines /.well-known/oauth-authorization-server for OAuth 2.0 servers, and OpenID Connect uses /.well-known/openid-configuration. Both return a JSON document listing the server's endpoints, and when DCR is supported, a registration_endpoint field is right there in the document.

The template therefore hits the well-known paths first, extracts registration_endpoint from the response, and then fires a POST with minimal client metadata: a name, a redirect URI and a grant type.

Text
id: open-dcr-detection

info:
  name: Open Dynamic Client Registration Detection
  author: amirmsafari
  severity: info

requests:
  - method: GET
    path:
      - "{{BaseURL}}/.well-known/openid-configuration"
      - "{{BaseURL}}/.well-known/oauth-authorization-server"

    stop-at-first-match: true
    extractors:
      - type: json
        name: registration_endpoint
        internal: true
        json:
          - ".registration_endpoint"

  - method: POST
    path:
      - "{{registration_endpoint}}"

    headers:
      Content-Type: application/json

    body: |
      {
        "client_name": "Example App",
        "redirect_uris": ["https://example.com/callback"],
        "grant_types": ["authorization_code"],
        "response_types": ["code"]
      }

    matchers:
      - type: status
        status:
          - 200
          - 201

      - type: word
        part: header
        words:
          - "application/json"

      - type: word
        part: body
        words:
          - "client_id"

The first request tries the two well-known paths and pulls out the registration endpoint. The second posts the minimal client body and treats a 200 or 201 with a JSON content type and a client_id in the body as a hit.

Nuclei scan results showing open DCR endpoints
Nuclei scan results showing open DCR endpoints From the original on blog.voorivex.team

Each hit was then exploited by hand. The techniques themselves are not new: PortSwigger published research on hidden OAuth attack vectors back in 2021. What changed is volume. MCP servers have made these DCR endpoints far more common, which means more targets and better odds.

Exploitation

Step 1: DOM-based XSS through a client-side redirect gadget

Once a client is registered, the next stop is the authorization endpoint, which does three things: authenticates the user, shows a consent screen for the requested permissions, and redirects back to the registered redirect_uri with an authorization code.

OAuth authorization flow diagram
OAuth authorization flow diagram From the original on blog.voorivex.team

The question that matters is how that final redirect happens. If the server performs it client-side in JavaScript, the redirect URI may be able to carry a javascript: scheme.

The attack:

  1. Register a client with javascript:alert(location.origin);// as the redirect URI.
  2. Send a victim to the authorization URL:
HTTP
https://mcp.company.tld/authorize
    ?response_type=code
    &client_id=<client_id>
    &redirect_uri=javascript:alert(location.origin);//
    &scope=read+write
    &state=random
    &code_challenge=<code_challenge>
    &code_challenge_method=S256
  1. When the user completes authorization, the application tries to send them back to the client and instead executes the JavaScript payload.

Some applications try to defend against this by extracting the hostname from the URL and validating it. The following payload bypasses that check:

Text
javascript://pwnbox.xyz/%0aalert(location.origin);//

The validator sees pwnbox.xyz as the hostname, but the browser still executes the JavaScript after the encoded newline.

XSS payload bypass demonstration
XSS payload bypass demonstration From the original on blog.voorivex.team

Step 2: Stored XSS on the OAuth consent screen

The consent screen is where the user is asked whether to allow an app to access their account, and it usually displays data about the requesting client: app name, logo, description, and sometimes the redirect URI. All of that data comes from the client registration, which is under the attacker's control.

One authorization server encountered during the research reflected the redirect_uri directly inside a <script> tag on the consent page.

redirect_uri reflected in a script tag on the consent page
redirect_uri reflected in a script tag on the consent page From the original on blog.voorivex.team

That makes a script-tag breakout possible. The client was registered with this redirect URI:

Text
https://pwnbox.xyz/mcp/</script><script>alert(location.origin)</script>
XSS payload executing on the consent screen
XSS payload executing on the consent screen From the original on blog.voorivex.team

The </script> closes the existing script tag and the injected script executes.

Step 3: Missing or confusing consent screens

Many authorization servers found during the research show no consent screen at all. The flow becomes:

  1. The user clicks an authorize link.
  2. They authenticate with their credentials.
  3. The server immediately redirects to the redirect_uri, no questions asked.

The user never sees which application is requesting access, and the authorization code goes straight to whatever redirect URI was registered. An attacker who registers a client with their own redirect URI can therefore obtain account access with a single click: the victim believes they are logging into something legitimate, and the code ends up with the attacker.

Even where consent screens exist, some are vague enough that the user cannot tell what they are approving. A screen that does not clearly identify the requesting client is almost as bad as no screen.

Step 4: Direct access to the MCP server

Open DCR also allows a different play: complete the whole authentication flow as a client, then talk to the MCP server yourself.

  1. Register a client with your own redirect_uri.
  2. Obtain the authorization code.
  3. Exchange the code for an access token.
  4. Connect to the MCP server as a legitimate client.

This matters because MCP servers are built for AI assistants, not for humans probing them. Developers assume AI clients behave predictably and follow the documented usage patterns. A tool that imports projects from a URL, for example, may instruct the AI not to use local links.

MCP tool documentation that instructs the AI not to use local links
MCP tool documentation that instructs the AI not to use local links From the original on blog.voorivex.team

Those instructions bind an obedient assistant. A human holding a valid token is not bound by them and can call any tool with any input, including inputs the developers never anticipated.

This path also works when redirect URIs are restricted. One authorization server for an MCP integration only allowed chatgpt.com as a redirect URI, so a custom redirect was impossible. It was still possible to register a client with the allowed chatgpt.com URI, start the auth flow, capture the authorization code from the redirect, and exchange it for an access token. The result was direct access to an MCP server intended only for ChatGPT, with every tool and method reachable without AI-imposed restrictions.

Exchanging the code for an access token

Send the following to the token endpoint with the registered client details filled in:

HTTP
POST /oauth/token HTTP/2
Host: mcp.company.tld
Content-Type: application/x-www-form-urlencoded
Content-Length: 296

grant_type=authorization_code
&code=<code>
&redirect_uri=<redirect_uri>
&client_id=<client_id>
&code_verifier=random
&client_secret=<client_secret>

The parameters:

  • code: the authorization code received in the redirect.
  • code_verifier: the original random string generated before creating the code_challenge, part of PKCE.
  • client_secret: include only if one was issued during registration; some servers do not require it.
  • redirect_uri: the client's registered redirect URI.

If everything is correct, the response contains an access token.

Access token response example
Access token response example From the original on blog.voorivex.team

Configuring MCP Inspector

With the token in hand, configure the Inspector panel:

  1. MCP Server URL: the full URL of the MCP endpoint. Common paths are /mcp for Streamable HTTP transport and /sse for Server-Sent Events transport.

  2. Transport Type: Streamable HTTP for /mcp, SSE for /sse.

  3. Authentication: MCP servers typically use Bearer token authentication, so enter:

    Text
    Bearer <your_access_token>
    
  4. Click Connect.

Exploring the tools

Once connected, Tools → List Tools shows every available tool and its expected inputs, and each one can be tested directly.

MCP Inspector tool list interface
MCP Inspector tool list interface From the original on blog.voorivex.team

Step 5: Full-read SSRF through a document fetcher

One MCP server had a tool that takes a document URL, fetches it, converts the response to Markdown and returns it. The obvious first question is whether it can be pointed at an attacker's site.

First attempt

Pointing it at the researcher's own domain failed with an error.

URL rejection error message
URL rejection error message From the original on blog.voorivex.team

The server was picky about which URLs it accepted.

Finding the rules

A legitimate document URL from the target site, of the form:

Text
https://company.tld/documents/{document-id}

worked. The server enforced a strict whitelist allowing only URLs matching https://company.tld/documents/.*. A bunch of tricks to bypass the domain check failed; the check held.

Escaping the path

The next idea was to find an open redirect on the same site and chain it with the fetcher. The obstacle was being confined to /documents, where an open redirect is hard or impossible to find. So the question became whether the path could be escaped first.

The test was whether the server normalises paths differently from how it validates URLs:

Text
https://company.tld/documents/..%2Fdocuments%2F{document-id}%23

It worked, returning the same content as before. This confirmed the encoded ../ could climb out of the /documents folder, making the search for an open redirect easier.

DCR as the open redirect

RFC 6749 (Section [redacted]) says that when an OAuth request fails, the authorization server redirects the user back to the client's redirect_uri with an error message:

HTTP
HTTP/1.1 302 Found
Location: https://client.example.com/cb?error=access_denied&state=xyz

Since DCR lets a client register any redirect_uri, including one on the attacker's own server, triggering an error produces an open redirect.

OAuth client registration with attacker-controlled redirect_uri
OAuth client registration with attacker-controlled redirect_uri From the original on blog.voorivex.team
OAuth error redirect to attacker-controlled URL
OAuth error redirect to attacker-controlled URL

Chaining the two

The path normalisation bypass and the redirect gadget combine into this payload:

The server then:

  1. Accepts the URL, because it starts with the whitelisted path.
  2. Normalises the path and hits the OAuth endpoint.
  3. Follows the redirect to the attacker's server.
SSRF payload execution showing fetch to attacker domain
SSRF payload execution showing fetch to attacker domain From the original on blog.voorivex.team

That is full SSRF. After that, the researcher redirected the server to localhost, did some port scanning, and found an application on port 8080 with a Swagger API endpoint that exposed all the client data.

Internal Swagger API endpoint exposing client data via SSRF
Internal Swagger API endpoint exposing client data via SSRF From the original on blog.voorivex.team

Root cause

The common thread is that DCR accepts client-supplied data without any gate: the redirect URI, the client name and the rest of the metadata are trusted and later used by the authorization server. That single design choice produces several distinct failures.

  • Client-side redirect handling. When the final redirect is performed in JavaScript, a javascript: redirect URI becomes script execution. Hostname-based validation of the URI is insufficient, because a URL can carry a hostname that satisfies the validator while the browser still executes the payload.
  • Unescaped client metadata on the consent page. Reflecting redirect_uri inside a <script> tag turns stored client metadata into stored XSS.
  • No consent, or a consent screen that does not identify the client. The user cannot make an informed decision, so a registered client with an attacker-controlled redirect URI collects codes silently.
  • Trusting the whitelist prefix before normalisation. The document fetcher validated the URL string against https://company.tld/documents/.* but then normalised the path before fetching. Encoded traversal passes the prefix check and resolves somewhere else entirely.
  • DCR as a redirect primitive. Because a failed authorization request redirects to the registered redirect_uri, any open DCR endpoint is also an open redirect, which is exactly the gadget the SSRF needed.

Impact

What an attacker gets depends on which of the above is present:

  • Script execution in the authorization server's origin through a javascript: redirect URI or through injection into the consent page, in the victim's browser, after the victim completes authorization.
  • Account access with a single click where no consent screen is shown: the victim authenticates, the code goes to the attacker's redirect URI, and the attacker can obtain account access.
  • Direct access to MCP tools as a legitimate client, bypassing the usage restrictions developers wrote for AI assistants. This works even when redirect URIs are locked to a specific domain, by registering with the allowed URI and capturing the code from the redirect.
  • Full-read SSRF where a tool fetches attacker-influenced URLs: in the observed case, reaching an internal application on port 8080 and reading all client data from its Swagger API.

Fix

  • Do not leave DCR open to unauthenticated registration. Require approval or verification before a client can be created, and restrict which redirect URIs a client may register.
  • Perform the post-authorization redirect server-side, and reject non-HTTP(S) schemes such as javascript: outright rather than validating the hostname of an arbitrary scheme.
  • HTML-escape all client-supplied metadata rendered on the consent page, including the redirect URI, and never place it inside a script context.
  • Always show a consent screen that clearly identifies the requesting client, so the user can see which application is asking for access.
  • For URL-fetching tools, validate the URL after normalisation, not before, and resolve and re-check the final destination rather than trusting a string prefix.
  • Treat any DCR endpoint as an open redirect and account for it when building allowlists.

Variants to test

  • CSRF on the consent page. Try to make a user approve an authorization request without realising it. A positive result is an approval that completes from a cross-site request with no user interaction beyond the visit.
  • SSRF via logo_uri. Register a client with a logo URL pointing at an internal address and see whether the server fetches it. A positive result is an outbound request from the server to the internal target, or the image content reflected back.
  • Session poisoning to steal authorization codes. Manipulate session handling so a code issued to a legitimate client is delivered to the attacker. A positive result is a valid code for another client's flow.
  • javascript: redirect URIs with hostname-validation bypasses. Register javascript://pwnbox.xyz/%0aalert(location.origin);// and complete the flow. A positive result is script execution in the authorization server's origin.
  • Script-tag breakout in consent metadata. Register a redirect URI such as https://pwnbox.xyz/mcp/</script><script>alert(location.origin)</script> and load the consent page. A positive result is the injected script running.
  • Path traversal against URL whitelists. Send https://company.tld/documents/..%2Fdocuments%2F{document-id}%23 to any fetcher with a prefix allowlist. A positive result is content from outside the allowed folder.
  • DCR as an open redirect. Register a client with a redirect URI on your own host, then trigger an authorization error. A positive result is a 302 to your host carrying error and state.

The researcher did not have any luck finding the first three variants, but they remain worth trying.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 23 min read.

What happened, in plain words

Imagine you hire a translator to sit between you and a foreign office. You say what you want, the translator walks over, talks to the office, comes back and tells you the answer. You never see the paperwork. That translator is what this article is about: a piece of software called an MCP server that sits between an AI assistant and the apps you actually use, such as your calendar, your files or your work chat.

To do its job, the translator needs permission to enter those offices on your behalf. The standard way software asks for and receives that permission is called OAuth 2.0. Part of OAuth is a feature called Dynamic Client Registration, or DCR, which lets a new app sign itself up automatically, with no human checking the paperwork. That convenience is the door this research walks through.

The researcher explains that many MCP servers leave that sign-up door wide open. From there he found several ways to abuse it: making a victim's browser run attacker-controlled JavaScript, tricking users into handing over their account, connecting to an MCP server directly as if he were a legitimate AI assistant, and finally turning a harmless-looking document-fetching tool into a way to read data from inside the company's own network.

Nothing below requires you to have hacked anything before. Every term is explained where it first appears, and there is a glossary at the end.

Understanding MCP servers

What an MCP server is

MCP stands for Model Context Protocol. The comparison the author uses is a translator. You speak English, the other person speaks Japanese, and the translator in the middle makes the conversation possible. The AI speaks one language, the app speaks another, and the MCP server translates between them so they can understand each other.

Without MCP, an AI assistant is stuck in a bubble. It can read what you type and write a reply, but it cannot reach outside that bubble. It cannot check your email, look at your files or update your to-do list. With MCP, the bubble pops and the assistant can actually go and do things for you.

How a request flows

Suppose you ask Claude, "What meetings do I have tomorrow?" The steps are:

  1. Claude realises it needs your calendar data, which it does not have.
  2. Claude calls the Google Calendar MCP server.
  3. The MCP server logs into your calendar, grabs tomorrow's meetings and organises the information.
  4. It sends everything back to Claude in a format Claude understands.
  5. Claude shows you your schedule.

You just see the answer. All the behind-the-scenes work happens automatically.

MCP server workflow diagram
MCP server workflow diagram From the original on blog.voorivex.team

The diagram shows this round trip: the assistant on one side, the MCP server in the middle, and the app holding your data on the other side.

How MCP servers handle authentication

Authentication is simply the process of proving who you are, the same way a passport proves your identity at a border. Most MCP servers use OAuth 2.0 for this, which is normal and expected. The problem is that many of them leave Dynamic Client Registration wide open.

What does that mean in practice? Anyone can register as an OAuth client. There is no approval process and no verification. You just get access automatically. The reason is flexibility: the operators want any AI tool to be able to connect quickly and easily, without jumping through hoops. The trade-off is that convenience has been placed ahead of security.

Dynamic Client Registration: the unlocked door

This part matters, because everything later depends on it.

The old-school way

Traditionally, becoming an OAuth client was a manual process. You filled out forms, waited for someone to review your application, and eventually received your client_id and client_secret. Think of a client_id as a username for an application and a client_secret as its password. The service provider knew exactly who you were, controlled which redirect URIs you could use, and could kick you out whenever it wanted.

A redirect URI is the address the login service sends the user back to once they have approved access. It is like telling a receptionist, "when you are done with me, send me back to this room." If an attacker can choose that room, the receptionist may deliver something valuable to the wrong person.

Was the manual process annoying? Yes. Slow? Absolutely. Secure? Very.

Then came RFC 7591

RFC 7591 is the technical document that defines Dynamic Client Registration, and it threw the manual process out of the window. Instead of waiting for approval, clients can now register themselves automatically. They simply send a request to the registration endpoint, which lives at /register, containing their own details:

JSON
{
  "redirect_uris": ["https://legit-app.com/callback"],
  "client_name": "Totally Legit App",
  "token_endpoint_auth_method": "none",
  "grant_types": ["authorization_code", "refresh_token"],
  "response_types": ["code"]
}

Line by line:

  • The outer braces mark this as a JSON object, which is just a structured way of writing data as labelled fields, like a form.
  • redirect_uris is the list of addresses the login service may send the user back to. Here it is a made-up app called legit-app.com.
  • client_name is the display name of the application, the name a user might see on a consent screen.
  • token_endpoint_auth_method set to none says the client will not use a secret when it later asks for a token. A token is a short-lived pass that proves the holder has been granted access, similar to a wristband at an event.
  • grant_types lists the kinds of permission flows the client intends to use. authorization_code is the standard flow where the user logs in and the app receives a one-time code it swaps for a token. refresh_token lets the app renew its access later without asking the user again.
  • response_types set to code says the app expects to receive that one-time authorization code.

And just like that, you get a shiny new client_id, and sometimes a client_secret too. No questions asked, no humans involved, fully automatic.

DCR registration flow
DCR registration flow From the original on blog.voorivex.team

The image shows this registration flow: a request goes to the registration endpoint and a client identity comes back.

Detecting open DCR at scale

We know what DCR is. The next question is how many MCP servers actually leave it open. Testing one server by hand is fine; testing thousands is not, so the researcher wrote a Nuclei template to automate discovery.

Nuclei is a free tool that sends predefined requests, called templates, to many targets and reports which ones respond in a particular way. Think of it as a checklist that a robot runs against a long list of websites.

But first, where do these registration endpoints even live? OAuth and OpenID Connect servers publish their configuration through well-known addresses. RFC 8414 defines /.well-known/oauth-authorization-server for OAuth 2.0 servers, and OpenID Connect uses /.well-known/openid-configuration. Both return a JSON document listing all the server's endpoints. If DCR is supported, a field called registration_endpoint sits right there in that document.

So the template first visits those well-known addresses, pulls the registration_endpoint out of the response, and then sends a registration request with minimal client details: a name, a redirect URI and a grant type.

Text
id: open-dcr-detection

info:
  name: Open Dynamic Client Registration Detection
  author: amirmsafari
  severity: info

requests:
  - method: GET
    path:
      - "{{BaseURL}}/.well-known/openid-configuration"
      - "{{BaseURL}}/.well-known/oauth-authorization-server"

    stop-at-first-match: true
    extractors:
      - type: json
        name: registration_endpoint
        internal: true
        json:
          - ".registration_endpoint"

  - method: POST
    path:
      - "{{registration_endpoint}}"

    headers:
      Content-Type: application/json

    body: |
      {
        "client_name": "Example App",
        "redirect_uris": ["https://example.com/callback"],
        "grant_types": ["authorization_code"],
        "response_types": ["code"]
      }

    matchers:
      - type: status
        status:
          - 200
          - 201

      - type: word
        part: header
        words:
          - "application/json"

      - type: word
        part: body
        words:
          - "client_id"

What each part does:

  • id is the template's internal name, and the info block holds metadata: a human-readable name, the author and a severity label of info, meaning this check only reports a finding rather than claiming a vulnerability.
  • The first request uses GET, the method a browser uses when you simply open a page. It tries two paths: the OpenID Connect well-known address and the OAuth well-known address. {{BaseURL}} is a placeholder that Nuclei fills in with each target it is scanning.
  • stop-at-first-match: true tells Nuclei to stop trying the second path once the first one answers, which saves time.
  • The extractors block reads the JSON response and pulls out the value of the registration_endpoint field, storing it under that name. internal: true means the value is kept for later use in the template rather than printed in the output.
  • The second request is a POST, the method used to submit data. It goes to {{registration_endpoint}}, the address just extracted.
  • The headers block sets Content-Type: application/json, which tells the server that the body is JSON data.
  • The body is the registration request itself: a client name, one redirect URI, the authorization_code grant type and the code response type.
  • The matchers decide whether a response counts as a hit. A status of 200 or 201 means success. The header must contain application/json, and the body must contain the word client_id. All three together mean the server accepted the registration.
Nuclei scan results showing open DCR endpoints
Nuclei scan results showing open DCR endpoints From the original on blog.voorivex.team

The screenshot shows the scan results.

Hunting for bugs in open DCR endpoints

Now the interesting part. A quick note first: these techniques are not brand new. People have been poking at open DCR and authorization servers for years, and PortSwigger published a well-known article about hidden OAuth attack vectors back in 2021. What is different now is volume. MCP servers have made these DCR endpoints far more common, which means more targets and better odds of finding something.

Client-side redirect gadget, DOM-based XSS

Once your client is registered, you have a client_id and a client_secret. The next stop is the authorization endpoint, which handles three jobs:

  1. It authenticates the user, checking their identity, usually through a login form.
  2. It shows a consent screen, asking the user to approve the permissions being requested.
  3. It redirects back to your application, sending the user to your registered redirect_uri with an authorization code.

The diagram below illustrates this complete flow:

OAuth authorization flow diagram
OAuth authorization flow diagram From the original on blog.voorivex.team

Here is the key question: how does that final redirect from the user back to the client actually happen? If the server performs it on the client side, meaning inside the browser using JavaScript, there may be a problem. JavaScript is the programming language that web pages run in your browser. If the redirect is done with JavaScript, perhaps we can register a client whose redirect URI uses the javascript: scheme, which tells the browser to run whatever follows as code instead of navigating to a page.

This kind of flaw is called DOM-based XSS. XSS stands for cross-site scripting: an attacker gets their own JavaScript to run inside a page belonging to someone else, in the victim's browser. DOM-based means the flaw lives in how the page's JavaScript handles data in the browser, rather than in what the server sends back.

The attack

  1. Register a client with javascript:alert(location.origin);// as the redirect URI.
  2. Send a victim to the authorization URL:
HTTP
https://mcp.company.tld/authorize
    ?response_type=code
    &client_id=<client_id>
    &redirect_uri=javascript:alert(location.origin);//
    &scope=read+write
    &state=random
    &code_challenge=<code_challenge>
    &code_challenge_method=S256
  1. Once the user completes authorization, the app tries to send them back to the client. Instead of a normal address, it triggers the JavaScript payload.

Reading the URL:

  • https://mcp.company.tld/authorize is the authorization endpoint, the page that starts the login and consent process.
  • response_type=code asks for an authorization code back.
  • client_id=<client_id> identifies which registered application is asking.
  • redirect_uri=javascript:alert(location.origin);// is the malicious part. Instead of a web address, it is a piece of JavaScript. alert(location.origin) opens a pop-up box showing the address of the page it is running on, which proves the code executed in that page's context. The // turns the rest of the line into a comment so nothing after it breaks the code.
  • scope=read+write lists the permissions being requested.
  • state=random is a value the client sends and expects back unchanged, used to tie the response to the request that started it.
  • code_challenge=<code_challenge> and code_challenge_method=S256 belong to PKCE, a protection that makes a stolen authorization code useless to anyone who does not hold the original random string that generated the challenge.

Some applications try to be smart about this. They extract the hostname from the URL and check it. A hostname is the part of an address like example.com. The following payload bypasses that check:

Text
javascript://pwnbox.xyz/%0aalert(location.origin);//

This tricks the validator into thinking pwnbox.xyz is the hostname, but the browser still executes the JavaScript. The %0a is an encoded newline character, which ends the comment-like part of the address and lets the code after it run.

XSS payload bypass demonstration
XSS payload bypass demonstration From the original on blog.voorivex.team

The image shows the bypass in action: the validator accepts the address because it sees a familiar hostname, while the browser runs the payload.

OAuth consent screen gadget, stored XSS

You know the screen that pops up asking, "Do you want to allow this app to access your account?" That is the OAuth consent screen, and it is a goldmine for XSS hunters.

The consent screen usually displays information about the client requesting access: the app name, logo, description and sometimes the redirect URI. All of this data comes from the client registration, which we control.

While exploring different authorization servers, the researcher found one that reflected the redirect_uri directly inside a <script> tag on the consent page. A <script> tag is the HTML element that tells a browser to run the code between its opening and closing tags.

redirect_uri reflected in a script tag on the consent page
redirect_uri reflected in a script tag on the consent page From the original on blog.voorivex.team

The screenshot shows the redirect URI appearing inside a script tag on the consent page.

If you can inject into a script tag, you can break out of it. The client was registered with this redirect URI:

Text
https://pwnbox.xyz/mcp/</script><script>alert(location.origin)</script>

This is stored XSS: the malicious value is saved on the server as part of the client registration and reflected on the consent page. The </script> closes the existing script tag, and then the injected <script>alert(location.origin)</script> runs as a new script.

XSS payload executing on the consent screen
XSS payload executing on the consent screen From the original on blog.voorivex.team

The image shows the payload executing on the consent screen.

Missing or confusing consent screen, OAuth misuse

Some authorization servers skip the consent screen entirely, or do not mention the client information at all. The researcher found a lot of authorization servers that show no consent screen whatsoever. Here is what happens:

  1. The user clicks an authorize link.
  2. They authenticate with their credentials.
  3. The server immediately redirects them to the redirect_uri, no questions asked.

The user never gets a chance to see which application is requesting access. They just log in, and their authorization code is sent straight to wherever the attacker specified. If an attacker registers a malicious client with their own redirect URI, they can trick users into giving up account access with a single click. The victim thinks they are logging into something legitimate, but their authorization code ends up in the attacker's hands.

Even when consent screens do exist, some are so vague that users have no idea what they are approving. If the screen does not clearly show which client is requesting access, it is almost as bad as having no screen at all.

Other attack vectors worth trying

Open DCR in authorization servers is a well-known attack surface, and there is plenty of material out there if you want to go deeper. Other attack types worth trying on your targets:

  • CSRF on the consent page. CSRF stands for cross-site request forgery: tricking a logged-in user's browser into sending a request they did not intend. Can you make users approve authorization requests without realising it?
  • SSRF via the logo_uri field. SSRF stands for server-side request forgery: making a server send a request to a destination of the attacker's choosing. When you register a client you can specify a logo URL. What if the server fetches that image from an internal network?
  • Session poisoning to steal authorization codes. A session is the server's memory of your logged-in state, usually tied to a cookie, which is a small piece of data your browser stores and sends back with each request. Messing with session handling might let an attacker hijack a code meant for a legitimate client.

The researcher did not have any luck finding these, but that does not mean they are not out there.

Going beyond authentication attacks

So far the focus has been on hijacking tokens and stealing user sessions. Open DCR in MCP servers opens up another avenue.

Direct access to the MCP server

If we can register our own OAuth client, we can complete the full authentication flow ourselves:

  1. Register a client with our own redirect_uri.
  2. Get the authorization code.
  3. Exchange that code for an access token.
  4. Connect directly to the MCP server as a legitimate client.

Why does this matter? Because MCP servers are designed to interact with AI assistants, not with humans probing them manually. Developers assume AI clients will behave predictably and follow the intended usage patterns.

For example, look at this tool from an MCP server that imports projects from a URL. Notice how it instructs the AI not to use local links:

MCP tool documentation that instructs the AI not to use local links
MCP tool documentation that instructs the AI not to use local links From the original on blog.voorivex.team

The screenshot shows tool documentation telling the AI to avoid local links.

These instructions work fine for AI assistants that follow rules. But as direct users of the MCP server, we are not bound by them. We can call any tool and provide whatever input we choose, including inputs the developers never anticipated.

Even when token hijacking fails because the server restricts redirect URIs to specific domains, this technique still works. The researcher found an authorization server for an MCP integration that only allowed chatgpt.com as a redirect URI, so registering his own redirect URI was impossible. He could still register a client with the allowed chatgpt.com URI, start the auth flow, capture the authorization code from the redirect, and exchange it for an access token himself. The result was direct access to an MCP server designed only for ChatGPT, with every available tool and method reachable without any AI-imposed restrictions.

Connecting to an MCP server

Once authentication is complete and you are redirected back to the client, you have an authorization code. The next step is exchanging that code for an access token.

Step 1: exchange the code for an access token

Send the following request to the token endpoint, filling in your registered client details:

HTTP
POST /oauth/token HTTP/2
Host: mcp.company.tld
Content-Type: application/x-www-form-urlencoded
Content-Length: 296

grant_type=authorization_code
&code=<code>
&redirect_uri=<redirect_uri>
&client_id=<client_id>
&code_verifier=random
&client_secret=<client_secret>

Line by line:

  • POST /oauth/token HTTP/2 sends a request to the token endpoint using HTTP/2, the version of the web protocol used for the connection.
  • Host: mcp.company.tld names the server being contacted.
  • Content-Type: application/x-www-form-urlencoded says the body is formatted like a web form, with fields joined by &.
  • Content-Length: 296 states the size of the body in bytes.
  • grant_type=authorization_code says we are redeeming an authorization code.
  • code=<code> is the authorization code received in the redirect.
  • redirect_uri=<redirect_uri> must match the redirect URI registered for the client.
  • client_id=<client_id> identifies the client.
  • code_verifier=random is the original random string generated before creating the code_challenge, part of PKCE.
  • client_secret=<client_secret> is included only if one was issued during registration; some servers do not require it.

If everything is correct, the response contains an access token.

Access token response example
Access token response example From the original on blog.voorivex.team

The screenshot shows a successful token response.

Step 2: install MCP Inspector

With a token in hand, you can connect to the MCP server using a tool called MCP Inspector, which provides a user-friendly interface for interacting with MCP servers directly. Install and run it with:

Bash
npx -y @modelcontextprotocol/inspector npx @playwright/mcp@latest

npx is a command that downloads and runs a Node.js package without a separate install step. The -y flag answers yes to any prompt. The command starts a local web interface, typically available at http://localhost:6274. localhost means your own computer, and 6274 is the port, the numbered door the interface listens on.

Step 3: configure the connection

In the MCP Inspector panel, configure the following:

  1. MCP Server URL: the full URL of the MCP endpoint. Common paths include /mcp for Streamable HTTP transport and /sse for Server-Sent Events transport. A transport is simply the way messages travel between the client and the server.

  2. Transport Type: choose Streamable HTTP if the endpoint uses /mcp, or SSE if it uses /sse.

  3. Authentication: MCP servers typically use Bearer token authentication. In the authentication header field, enter:

    Text
    Bearer <your_access_token>
    

    A header is extra information sent alongside a request. Bearer means "the holder of this token is authorised", like showing a wristband at the door.

  4. Click Connect to establish the connection.

Step 4: explore the tools

Once connected, navigate to Tools → List Tools to see all available tools and their expected inputs. You can browse through them and test each one directly.

MCP Inspector tool list interface
MCP Inspector tool list interface From the original on blog.voorivex.team

The screenshot shows the Inspector's tool list.

Discovering a full-read SSRF vulnerability

While poking around an MCP server and loading its tools, one particular tool caught the researcher's eye. It takes a document URL, fetches it, converts the response to Markdown and hands it back. Markdown is a simple way of writing formatted text, the same format used in many note-taking apps. The obvious first thought: can it be made to fetch the researcher's own site? That is the classic SSRF question, where a server is tricked into making a request on the attacker's behalf.

First attempt: the easy way

Pointing it at the researcher's own domain failed with an error:

URL rejection error message
URL rejection error message From the original on blog.voorivex.team

The screenshot shows the rejection message. The server was picky about which URLs it accepted.

Finding the rules

Next, a legitimate document URL from the target website, of the form:

Text
https://company.tld/documents/{document-id}

This worked. {document-id} is a placeholder for an identifier of a real document. The server enforced a strict whitelist, meaning an allowlist of permitted addresses, matching only https://company.tld/documents/.*. The .* means "anything after this point". A bunch of tricks to bypass the domain check failed; the check held.

The path normalisation trick

The next idea was to find an open redirect somewhere on the same website. An open redirect is a link on a site that will send visitors to any address an attacker chooses. If one could be found, it could be chained with the fetcher to send requests to any host.

The obstacle was being stuck inside the /documents path, where finding an open redirect is hard or even impossible. So the question became whether the path could be escaped first. The test was whether the server normalises paths differently from how it validates URLs. Normalisation is the process of tidying up an address, for example turning .. into "go up one folder".

Text
https://company.tld/documents/..%2Fdocuments%2F{document-id}%23

It worked, returning the same content as before. %2F is an encoded slash, so ..%2F means "go up one folder". %23 is an encoded #. This confirmed the server could be made to climb out of the /documents folder, which made finding an open redirect much easier.

Dynamic Client Registration as the secret weapon

An open redirect was needed, and DCR provided exactly that. According to RFC 6749, Section [redacted], when an OAuth request fails, the authorization server redirects the user back to the client's redirect_uri with an error message:

HTTP
HTTP/1.1 302 Found
Location: https://client.example.com/cb?error=access_denied&state=xyz

302 Found is the status code a server uses to say "the thing you asked for is somewhere else, go there instead". Location is the address to go to. Here it carries error=access_denied and the original state value.

The key insight: a new OAuth client could be registered with any redirect_uri, including one on the attacker's own server. Then, by triggering an error, the result is an open redirect.

OAuth client registration with attacker-controlled redirect_uri
OAuth client registration with attacker-controlled redirect_uri From the original on blog.voorivex.team

The image shows a client registration with an attacker-controlled redirect URI.

OAuth error redirect to attacker-controlled URL
OAuth error redirect to attacker-controlled URL From the original on blog.voorivex.team

The image shows the resulting error redirect pointing at the attacker's address.

Putting it all together

The path normalisation bypass and the redirect gadget combine into this payload:

This made the server:

  1. Accept the URL, because it starts with the whitelisted path.
  2. Normalise the path and hit the OAuth endpoint.
  3. Follow the redirect to the attacker's server.
SSRF payload execution showing fetch to attacker domain
SSRF payload execution showing fetch to attacker domain From the original on blog.voorivex.team

The image shows the server fetching the attacker's address as a result.

Full SSRF achieved. After that, the researcher redirected the server to localhost and did some port scanning, which means probing numbered doors on the machine to see which ones answer. He discovered an application running on port 8080. Even better, it had a Swagger API endpoint, and he could read all the client data through it. An API is a way for one piece of software to talk to another, and Swagger is a tool that documents such APIs, often with a browsable page.

Internal Swagger API endpoint exposing client data via SSRF
Internal Swagger API endpoint exposing client data via SSRF From the original on blog.voorivex.team

The image shows the internal Swagger page and the client data it exposed.

Conclusion

MCP servers sit at a critical point between AI and the real world. They handle authentication, manage permissions and give AI assistants the power to take real actions. That responsibility comes with risk.

Open Dynamic Client Registration was designed for flexibility, but it opens the door to XSS, token theft, SSRF and direct access to tools that were never meant for manual interaction. If you are building these integrations, think carefully about who can register as a client and what they can access. If you are a security researcher, MCP servers are fresh ground worth exploring.

Glossary

  • API: a defined way for one piece of software to talk to another, like a menu of requests a service accepts.
  • Authentication: proving who you are, for example by logging in.
  • Authorization code: a short-lived one-time value a login service hands back, which an app swaps for an access token.
  • Authorization endpoint: the page where a login and consent flow begins.
  • Bearer token: an access token sent in a header, where simply holding it is enough to be treated as authorised.
  • Client (OAuth client): an application that asks a login service for permission to act on a user's behalf.
  • client_id: the public identifier of an OAuth client, like a username for an application.
  • client_secret: the private password of an OAuth client, when one is issued.
  • Consent screen: the page that asks a user to approve an app's access to their account.
  • Cookie: a small piece of data a browser stores for a site and sends back with later requests.
  • CSRF (cross-site request forgery): tricking a logged-in user's browser into sending a request the user did not intend.
  • DCR (Dynamic Client Registration): a feature that lets an app register itself as an OAuth client automatically, without human review.
  • DOM-based XSS: cross-site scripting where the flaw is in how a page's own JavaScript handles data in the browser.
  • Header: extra information sent alongside a web request or response, such as the content type or an authentication token.
  • Hostname: the part of an address that names a machine, such as example.com.
  • HTTP / HTTP/2: the protocol browsers and servers use to exchange requests and responses; HTTP/2 is a newer version.
  • JSON: a structured text format for data, written as labelled fields inside braces.
  • Markdown: a simple way of writing formatted text using plain characters.
  • MCP (Model Context Protocol): a protocol that lets an AI assistant call external tools and apps through a middleman server.
  • MCP Inspector: a tool with a local web interface for connecting to and testing MCP servers.
  • Nuclei: a tool that runs predefined request templates against many targets and reports matches.
  • OAuth 2.0: the standard system apps use to obtain limited access to a user's account without seeing their password.
  • Open redirect: a link on a site that will forward a visitor to any address an attacker chooses.
  • OpenID Connect: a layer on top of OAuth 2.0 that adds identity information about the user.
  • Path normalisation: tidying up an address, for example resolving .. to mean "go up one folder".
  • PKCE: a protection that ties an authorization code to the client that requested it, so a stolen code is useless on its own.
  • Port: a numbered door on a machine that a particular service listens on.
  • Redirect URI: the address a login service sends the user back to after they approve access.
  • RFC: a numbered document that defines an internet standard.
  • Scope: the list of permissions an app is requesting.
  • Session: a server's memory of your logged-in state, usually tied to a cookie.
  • SSRF (server-side request forgery): making a server send a request to an address of the attacker's choosing, often inside a private network.
  • State: a value a client sends and expects back unchanged, used to tie a response to the request that started it.
  • Stored XSS: cross-site scripting where the malicious value is saved on the server and served to later visitors.
  • Swagger: a tool that documents an API, often as a browsable page.
  • Token: a short-lived pass proving that access has been granted.
  • Transport: the way messages travel between a client and a server, such as Streamable HTTP or Server-Sent Events.
  • Whitelist (allowlist): a list of things that are permitted, with everything else refused.
  • XSS (cross-site scripting): getting attacker-controlled JavaScript to run inside another site's page in a victim's browser.

More by Amirmohammad Safari

View all

5 more disclosed reports, best first.

Similar reports

View all

Same bug class and techniques, clearest first.

Cross-site scripting (XSS)

The lesson behind this report.

Script an attacker supplies runs in another user's browser, on the target's origin, with that user's session.