Skip to content

Commit d0e3077

Browse files
simonchrzchr-hertel
authored andcommitted
fix: reject JSON array bodies in metadata enrichment
Treat JSON list arrays (e.g. [] or ["..."]) as invalid metadata in enrichAuthServerMetadata() to prevent corrupting the response shape by adding registration_endpoint to a non-object.
1 parent 51dce3f commit d0e3077

2 files changed

Lines changed: 15 additions & 1 deletion

File tree

src/Server/Transport/Http/Middleware/ClientRegistrationMiddleware.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ private function enrichAuthServerMetadata(ResponseInterface $response): Response
127127
return $response;
128128
}
129129

130-
if (!\is_array($metadata)) {
130+
if (!\is_array($metadata) || ([] !== $metadata && array_is_list($metadata))) {
131131
if ($stream->isSeekable()) {
132132
$stream->rewind();
133133
}

tests/Unit/Server/Transport/Http/Middleware/ClientRegistrationMiddlewareTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,20 @@ public function testMetadataEnrichmentRewindsStreamOnNonObjectJsonBody(): void
274274
$this->assertSame('"just a string"', $response->getBody()->getContents());
275275
}
276276

277+
#[TestDox('GET /.well-known/oauth-authorization-server with JSON array body passes through unchanged')]
278+
public function testMetadataEnrichmentPassesThroughJsonArrayBody(): void
279+
{
280+
$registrar = $this->createStub(ClientRegistrarInterface::class);
281+
$middleware = $this->createMiddleware($registrar);
282+
283+
$request = $this->factory->createServerRequest('GET', 'http://localhost:8000/.well-known/oauth-authorization-server');
284+
$handler = $this->createPlainTextHandler(200, '["not","an","object"]');
285+
286+
$response = $middleware->process($request, $handler);
287+
288+
$this->assertSame('["not","an","object"]', $response->getBody()->getContents());
289+
}
290+
277291
#[TestDox('GET /.well-known/oauth-authorization-server with non-200 status passes through unchanged')]
278292
public function testMetadataNon200PassesThrough(): void
279293
{

0 commit comments

Comments
 (0)