AIDEFEND in Action AIA-0170 Validated Research

MCP SDK OAuth Flaw: A Malicious Server Could Choose Where the Client Sends Its Credentials

The official Python and TypeScript SDKs for the Model Context Protocol (MCP, the open protocol AI applications use to connect to external tools and data) include an OAuth client. In affected versions, the MCP server being connected to decided which authorization server (the service that signs users in and issues tokens) received the client's credentials. Two maintainer advisories say a malicious or compromised MCP server could therefore collect a client secret, a stored refresh token, an authorization code or a signed client assertion meant for the legitimate authorization server. Upgrading is required but not sufficient: some providers and previously stored credentials also need an explicit issuer. There is currently no public evidence that this technique has been used in a real attack.

Credential TheftClient SecurityCredential GovernanceMCP SecuritySoftware Dependencies
6 applicable AIDEFEND defenses
Source: OAuth client could send credentials to an authorization server chosen by the MCP server 
Authors: @maxisbey (Model Context Protocol maintainers); reporters credited: Aviral2642, AlexMelanFromRingo, Gal3m, mrostamipoor, YuvalElbar6, yuvalelbar, RoniGurvich, mahmoudalbustan1
Original article: Sep 28, 2026

Threat Analysis

  • The server decided where credentials went: An MCP client that signs in with OAuth learns which authorization server protects the MCP server from that server's protected resource metadata, a public document the server publishes for this purpose. It then reads that authorization server's metadata to find its issuer (the URL that identifies it) and its token endpoint, where credentials are exchanged for tokens. According to the Python SDK advisory, the affected client did not validate the metadata issuer on every discovery path and did not bind stored or pre-provisioned credentials to the authorization server they belong to. For example, a service holding a client_secret (the password a client uses to prove its identity to an authorization server) issued by https://auth.example.com connects to https://mcp.attacker.example, whose metadata names https://login.attacker.example. The client then posts its token request, secret included, to that host. These addresses are invented to show the sequence.
  • Python SDK, two ways to steer the client: The MCP server either names its own authorization server in its protected resource metadata, or publishes none and serves metadata that presents the user's real authorization server as the issuer. It would then receive the client_secret, the authorization code (the one-time code an authorization server returns after the user signs in) and the PKCE code_verifier (the random value a client must present to redeem that code) meant for the real server. With PrivateKeyJWTOAuthProvider it would receive a signed client assertion instead, a JWT the client signs with its private key in place of a secret.
  • TypeScript SDK, no user action needed: The TypeScript advisory states that once the MCP server names its own authorization server, the client would send it, with no user interaction, the refresh_token (used to obtain new access tokens without a new sign-in) and client_secret stored from an earlier sign-in, or the client_secret or signed assertion configured on a bundled provider. This applies to an authProvider on a transport, the withOAuth() middleware, and direct calls to auth() or fetchToken().
  • Affected versions and conditions: An application is affected when it uses the SDK's OAuth client over HTTP and may connect to an MCP server it does not fully trust while holding credentials for a legitimate authorization server. Python mcp, with OAuthClientProvider, ClientCredentialsOAuthProvider, PrivateKeyJWTOAuthProvider or the deprecated 1.x RFC7523OAuthClientProvider: 1.9.1 (inclusive) to 1.30.0 (exclusive), and 2.0.0a1 (inclusive) to 2.2.0 (exclusive). Releases 1.9.1 through 1.29.1 had neither check on any path. For 2.0.0 through 2.1.1 the advisory says both were missing when the server publishes no protected resource metadata or answers 403 insufficient_scope. On both lines and every path, ClientCredentialsOAuthProvider and PrivateKeyJWTOAuthProvider had no way to name the authorization server their credentials belong to. TypeScript: @modelcontextprotocol/sdk 1.12.0 (inclusive) to 1.31.0 (exclusive), and @modelcontextprotocol/client 2.0.0 (inclusive) to 2.2.0 (exclusive) only for bundled providers without expectedIssuer, credentials stored or supplied without issuer, direct fetchToken() calls, and providers that read storage back through OAuthTokensSchema or OAuthClientInformationSchema. MCP servers built with the SDKs and stdio clients (which talk to a local server process instead of HTTP) are not affected. The Python advisory also excludes clients that attach their own tokens or headers.
  • What the fixes change, and what stays with you: The fixed releases are mcp 1.30.0 and 2.2.0, @modelcontextprotocol/sdk 1.31.0 and @modelcontextprotocol/client 2.2.0. The Python client now determines the issuer it expects before fetching any authorization server metadata and refuses a mismatch with OAuthFlowError. The TypeScript client records issuer on saved credentials and will not send them to a different authorization server. Both advisories say upgrading is not enough in specific cases. Providers configured with a secret or signing key still follow the server-named authorization server until the expected issuer is passed in code. Credentials stored without an issuer, including everything the 1.x lines saved before the fix, stay unbound. A custom TypeScript OAuthClientProvider also has to store the issuer it is given. The TypeScript fix does not cover a new interactive sign-in, which still goes to the authorization server the MCP server names, direct refreshAuthorization() or exchangeAuthorization() calls, or 2.x with skipIssuerMetadataValidation: true.
  • Identifiers and evidence status: A CVE is a public identifier for a disclosed security vulnerability. The Python flaw is CVE-2026-115563 (GitHub advisory GHSA-qx49-fqc8-xw99) and the TypeScript flaw is CVE-2026-104850 (GHSA-6qxp-vccf-f47h). Both are rated High, with a CVSS 3.1 score of 7.5. The Python advisory notes that the score is for unattended providers and gives 6.5 for the interactive OAuthClientProvider, where a person has to start the sign-in. Both advisories were published by maintainer maxisbey. The Python advisory credits reporters Aviral2642, AlexMelanFromRingo, Gal3m, mrostamipoor, YuvalElbar6, yuvalelbar, RoniGurvich and mahmoudalbustan1. The TypeScript advisory credits Aviral2642, AlexMelanFromRingo, Gal3m, JosephDoUrden, Igfray, OriginalKazdov and lwebmedia. There is currently no public evidence that this technique has been used in a real attack. First-hand sources: Python SDK advisory and TypeScript SDK advisory.

Applicable AIDEFEND Defenses (6)

AID-H-028.005
Client Request, Cache & Application-State Lifecycle Security
Very High
Keep the decision about which authorization server may receive credentials in the client team's own configuration, not in the metadata the MCP server returns. Local policy names one approved issuer per MCP resource; the client fetches authorization server metadata only from that issuer's own location and sends no secret, code, refresh token or assertion anywhere else. In the fixed SDKs this is issuer= (Python) or expectedIssuer (TypeScript). With the legitimate issuer known in advance, both ways of steering the client fail before a credential leaves. A general-purpose client that accepts arbitrary servers cannot name issuers ahead of time and relies on binding each stored credential to the issuer that issued it.
AID-H-003.010
Deployed AI Software Vulnerability Remediation Lifecycle
High
Roll the repair out to every running MCP client as three parts: the fixed SDK release, the expected issuer on providers that carry a secret or signing key, and stored credentials cleared or labeled with their issuer. Read completion back from the running environment, not from the dependency manifest. The upgrade is what makes the SDK bind stored credentials to their issuer, but both advisories state that a version change alone leaves those providers and previously stored credentials exposed.
AID-H-028.001
MCP Server Authenticity Validation & Connection Pinning
High
Check the MCP server address against an approved list before discovery starts, so an OAuth-enabled client never asks an unapproved server which authorization server to use. This turns the advisories' interim advice, connect only to MCP servers you trust, into a check the client enforces. It is also the main protection for new interactive sign-ins, which the TypeScript fix does not cover. It does not help when an approved server is later compromised, and a consumer client that accepts any address the user types cannot keep such a list.
AID-E-001.001
Root & Long-Lived Credential Object Eviction
High
If an affected client may have connected to an MCP server you do not trust, rotate its client secret at the authorization server, as both advisories instruct; the TypeScript advisory also names the signing key. Confirm the old secret is rejected and every instance uses the new one. A dynamically registered client that only registers again leaves its old registration usable until that registration is deleted or expires, so remove it too. This is a response step. It does not stop a client from sending credentials to the wrong server again.
AID-E-001.002
Issued Token, Authentication Session & Lease Revocation
High
The TypeScript advisory lists stored refresh tokens among what the client would send, and both advisories say to revoke the affected client's tokens. Authorization server administrators revoke the refresh tokens and access tokens issued to that client, then confirm a revoked refresh token can no longer be exchanged. Rotating the client secret does not revoke tokens that were already issued, and a public client has no secret to rotate, so this is a separate response step.
AID-D-011.004
Non-Human Identity & Delegated Token Abuse Detection
Medium
After credentials leave the client, the remaining signal is at the legitimate authorization server: a token or refresh request for this client with a client, audience, resource, scope or workload combination policy never approved, or use after revocation. Teams with access to that server's logs can correlate these events with later resource access. This is detection only. It cannot see the misdirected request itself, and it cannot be deployed when a third party runs the authorization server and does not share its logs.

What Defenders Should Do Now

  • Find every place the SDK runs as an OAuth-enabled MCP client over HTTP (desktop apps, agent runtimes, backend services, CI jobs) and read the installed version from the running environment, not the version range in the manifest. Pass condition: mcp is 1.30.0 or later on 1.x, or 2.2.0 or later on 2.x; @modelcontextprotocol/sdk is 1.31.0 or later; @modelcontextprotocol/client is 2.2.0 or later, with @modelcontextprotocol/core at 2.2.0 or later if you import it directly.
  • Set the expected issuer on every provider that carries a secret or signing key. In Python, pass issuer= to ClientCredentialsOAuthProvider and PrivateKeyJWTOAuthProvider, and replace RFC7523OAuthClientProvider, which has no issuer option, with one of those two. On 1.30.0 a missing issuer only raises a DeprecationWarning that Python hides by default, so run tests with deprecation warnings shown and treat that warning as a failure. In TypeScript, pass expectedIssuer to ClientCredentialsProvider, PrivateKeyJwtProvider, StaticPrivateKeyJwtProvider and CrossAppAccessProvider, remove skipIssuerMetadataValidation: true, and confirm that direct calls to refreshAuthorization() or exchangeAuthorization() can only target an issuer your configuration approves.
  • Deal with what is already stored. In Python, clear stored OAuth client information once so the client registers again; for a pre-registered client you placed in storage yourself, set issuer on that record instead. In TypeScript, add issuer to tokens and client information persisted to a file, keychain or database before the upgrade, or clear them so users sign in again. A custom OAuthClientProvider must save exactly what saveTokens() and saveClientInformation() are given, including issuer, and pre-registered credentials need issuer in what clientInformation() returns. Pass condition: no stored token or registration record lacks an issuer.
  • Verify the result in an isolated test environment. Run a test MCP server that names a different authorization server (for Python, add the case that publishes no protected resource metadata while claiming your real issuer), and connect each client build using synthetic secrets, fake credentials created only for testing. Pass condition: the test token endpoint receives no secret, refresh token, authorization code or assertion, and the client raises an error or asks the user to sign in again. This test is our recommendation; the advisories do not describe running one.
  • Until every client is fixed, connect OAuth-enabled clients only to MCP servers on an approved list, and keep that rule for interactive sign-ins after the upgrade. If an affected client may have connected to an MCP server you do not trust, rotate its client secret or signing key and revoke its tokens at the authorization server. This is a precaution based on possible exposure. The advisories are not evidence that any client was compromised.

1 additional consideration

Refresh token rotation with reuse detection

Authorization server owners can additionally lower what a copied refresh token is worth by issuing a new refresh token on every use and detecting reuse of an old one. Where both the client and the authorization server support it, tokens can also be bound to a key the client holds (DPoP or mutual TLS).
Recommendation: Enable rotation with reuse detection for MCP client registrations, and test that replaying an already used refresh token revokes the whole grant. The first use of a copied token can still succeed, and a client secret is not protected this way, so issuer binding in the client stays the primary control.

Conclusion

The server a client is about to connect to must not also decide where that client's credentials go. AIDEFEND  maps this attack path to four defensive approaches: bind each OAuth authorization to an issuer approved by local policy; roll the fixed SDK, the issuer setting and the stored-credential cleanup out to every client and read the result back; check the MCP server against an approved list before discovery; and after possible exposure, rotate the client secret or signing key and revoke tokens at the authorization server.

Last updated: