Vulnerability DatabaseGHSA-f4rf-6ghj-mhr6

GHSA-f4rf-6ghj-mhr6: 
PHP vulnerability analysis and mitigation

OAuth middleware endpoints bypass the request-body limit and allow unauthenticated memory exhaustion

Summary

StreamableHttpTransport documents and enforces a default 4 MiB upper bound for POST request bodies. However, middleware runs before the transport request handler, and the public OAuth /token and /register middleware endpoints consume their request bodies directly without any size limit. An unauthenticated remote client can therefore send a body larger than the configured maxBodyBytes value to either endpoint. The same oversized body is rejected with HTTP 413 on an ordinary MCP POST, but /register fully decodes it and invokes the registrar, while /token parses, rebuilds, and forwards it upstream. In an isolated container with PHP's memory limit set to 128 MiB, a single 16 MiB /token request terminated PHP in OAuthProxyMiddleware::handleToken(). A single 32 MiB /register request independently terminated PHP in ClientRegistrationMiddleware::handleRegistration().

Product and affected versions

  • Repository: modelcontextprotocol/php-sdk
  • Composer package: mcp/sdk
  • Affected releases: v0.8.0 and v0.8.1
  • Current reviewed commit: 16836d4e9a0f96831789ac6e64d5ec5238d2c833
  • Protection being bypassed was introduced by commit 5e736830795dfabe2f7cff83d0079589b11cf6a0
  • Runtime-confirmed: v0.8.0, v0.8.1, and the reviewed current commit The OAuth middleware classes existed in earlier releases and also read unbounded bodies, but those releases did not yet contain StreamableHttpTransport::DEFAULT_MAX_BODY_BYTES. This report conservatively scopes the affected range to releases where the SDK provides a configurable transport-wide POST body limit that these earlier middleware interceptors bypass.

Configuration preconditions

At least one affected middleware is enabled before the transport handler:

  • OAuthProxyMiddleware exposes unauthenticated POST /token; or
  • ClientRegistrationMiddleware exposes unauthenticated POST /register. The official OAuth examples enable OAuthProxyMiddleware. Dynamic client registration is optional. An upstream reverse proxy or web server with a lower independent body limit can mitigate exploitation, but the SDK does not require or enforce such a deployment control.

Root cause

StreamableHttpTransport::listen() builds the middleware pipeline around handleRequest(). The transport's bounded body reader executes only after every middleware has passed the request onward. ClientRegistrationMiddleware intercepts /register first and performs:

$body = $request->getBody()->__toString();
$decoded = json_decode($body, false, 512, JSON_THROW_ON_ERROR);
$data = json_decode($body, true, 512, JSON_THROW_ON_ERROR);

It materializes the complete body and decodes valid JSON twice without consulting maxBodyBytes. OAuthProxyMiddleware intercepts /token first and performs:

$body = $request->getBody()->__toString();
parse_str($body, $params);
// ...
$body = http_build_query($params);

It materializes, parses, and reconstructs the complete form body before forwarding it. These operations create multiple copies and decoded representations of attacker-controlled input.

Reproduction

The attached PHPUnit test uses the real Streamable HTTP transport and both real middleware implementations. It creates a value one byte larger than the default 4 MiB limit and performs three controls:

  1. Send the oversized value to an ordinary MCP POST. The transport returns 413.
  2. Send a valid oversized JSON object to /register. The middleware returns 201 and the registrar receives the complete value.
  3. Send an oversized form body to /token. The middleware returns 200 and the mock upstream receives a body larger than 4 MiB. Default proof:
vendor/bin/phpunit tests/Unit/Server/Transport/OAuthEndpointBodyLimitSecurityTest.php --testdox

Observed on v0.8.0, v0.8.1, and current main:

OAuth Endpoint Body Limit Security
 ✔ O auth endpoints bypass transport body limit
OK (1 test, 8 assertions)
Memory: 40.02 MB

Memory-exhaustion confirmation

The PoC accepts MCP_OAUTH_BODY_PROBE_BYTES so the resource effect can be confirmed locally without any external target. With a 16 MiB body and no PHP memory cap, the complete test succeeded but reached approximately 136 MiB peak memory:

MCP_OAUTH_BODY_PROBE_BYTES=16777216 vendor/bin/phpunit \
  tests/Unit/Server/Transport/OAuthEndpointBodyLimitSecurityTest.php --testdox

With memory_limit=128M, the /token leg terminated the PHP process:

Fatal error: Allowed memory size of 134217728 bytes exhausted
(tried to allocate 50335744 bytes)
in OAuthProxyMiddleware.php on line 149

Using MCP_OAUTH_PROBE_STOP_AFTER_REGISTER=1 to isolate /register, a 32 MiB JSON request under the same 128 MiB limit terminated independently:

Fatal error: Allowed memory size of 134217728 bytes exhausted
(tried to allocate 33554464 bytes)
in ClientRegistrationMiddleware.php on line 83

All tests were performed locally in disposable PHP containers.

Impact

The affected endpoints are intentionally reachable before bearer-token authentication. A remote unauthenticated attacker can force a PHP worker to allocate multiple times the supplied request size. Depending on the PHP SAPI and process model, one or repeated requests can terminate workers, exhaust a shared memory budget, increase upstream traffic, and degrade or deny the MCP service. The demonstrated request-to-peak ratio for the combined 16 MiB proof was approximately 8.5x (about 136 MiB peak), although exact amplification varies by PHP version, SAPI, allocator, and which endpoint is exercised. This report does not claim a limit bypass where an independently configured reverse proxy rejects the request before PHP receives it.

Severity

Suggested CVSS v3.1: CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H — 7.5 High Suggested weaknesses:

  • CWE-400: Uncontrolled Resource Consumption
  • CWE-770: Allocation of Resources Without Limits or Throttling

Enforce a shared request-body limit before any route-specific middleware can consume a body. The safest design is an outermost body-limiting middleware used by every POST endpoint, including /token, /register, and future well-known or proxy handlers. The limiter should:

  1. Reject a declared Content-Length above the configured limit before reading.
  2. Still stream and count the body with a hard cutoff, because chunked requests can omit or lie about Content-Length.
  3. Return HTTP 413 without parsing, decoding, rebuilding, logging, or forwarding the oversized body.
  4. Apply one documented configuration consistently across the transport and OAuth endpoints.
  5. Avoid decoding registration JSON twice.
  6. Add regression tests showing that oversized /token and /register requests receive 413 and neither the registrar nor upstream HTTP client is called. Reverse-proxy limits remain useful defense in depth but should not be the SDK's only protection.

Duplicate check

On 2026-09-17, public issue searches for body size, request size, payload limits, memory exhaustion, and OAuth denial of service did not reveal this issue. The repository's only published advisory was unrelated.

AI assistance disclosure

AI-assisted tooling was used to inspect the source, construct isolated local proofs, compare tagged releases, and draft this report. The reporter reviewed and reproduced the behavior locally and takes responsibility for the submission. php-sdk-oauth-body-limit-bypass-poc.zip


Source: NVD

Related PHP vulnerabilities:

CVE ID

Severity

Score

Technologies

Component name

CISA KEV exploit

Has fix

Published date

CVE-2026-104883HIGH7.2
  • PHP logoPHP
  • contao/core-bundle
NoYesNov 20, 2026
GHSA-vw9g-2c4c-g767MEDIUM6.8
  • PHP logoPHP
  • livewire/livewire
NoYesNov 21, 2026
CVE-2026-104882MEDIUM6.5
  • PHP logoPHP
  • cpe:2.3:a:contao:contao
NoYesNov 20, 2026
GHSA-2g6w-c7gx-fxj8MEDIUM5.4
  • PHP logoPHP
  • guzzlehttp/guzzle
NoYesNov 21, 2026
CVE-2026-104884MEDIUM5.4
  • PHP logoPHP
  • composer://contao/contao
NoYesNov 20, 2026

Free Vulnerability Assessment

Benchmark your Cloud Security Posture

Evaluate your cloud security practices across 9 security domains to benchmark your risk level and identify gaps in your defenses.

Request assessment

Additional Wiz resources

Get a personalized demo

Ready to see Wiz in action?

"Best User Experience I have ever seen, provides full visibility to cloud workloads."
David EstlickCISO
"Wiz provides a single pane of glass to see what is going on in our cloud environments."
Adam FletcherChief Security Officer
"We know that if Wiz identifies something as critical, it actually is."
Greg PoniatowskiHead of Threat and Vulnerability Management