Skip to content

Commit f07b4f9

Browse files
committed
fix: address second Copilot review round
- Reject empty JSON array body by decoding with assoc=false and checking for stdClass instead of relying on array_is_list - Remove stale Content-Length header after mutating response body in enrichAuthServerMetadata
1 parent 8ec1cfa commit f07b4f9

9 files changed

Lines changed: 297 additions & 3 deletions

File tree

.idea/.gitignore

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/laravel-idea.xml

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/modules.xml

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/php-sdk.iml

Lines changed: 106 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/php.xml

Lines changed: 105 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/phpunit.xml

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/vcs.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,21 +72,24 @@ private function handleRegistration(ServerRequestInterface $request): ResponseIn
7272
$body = $request->getBody()->__toString();
7373

7474
try {
75-
$data = json_decode($body, true, 512, \JSON_THROW_ON_ERROR);
75+
$decoded = json_decode($body, false, 512, \JSON_THROW_ON_ERROR);
7676
} catch (\JsonException) {
7777
return $this->jsonResponse(400, [
7878
'error' => 'invalid_client_metadata',
7979
'error_description' => 'Request body must be valid JSON.',
8080
]);
8181
}
8282

83-
if (!\is_array($data) || ([] !== $data && array_is_list($data))) {
83+
if (!$decoded instanceof \stdClass) {
8484
return $this->jsonResponse(400, [
8585
'error' => 'invalid_client_metadata',
8686
'error_description' => 'Request body must be a JSON object.',
8787
]);
8888
}
8989

90+
/** @var array<string, mixed> $data */
91+
$data = (array) $decoded;
92+
9093
try {
9194
$result = $this->registrar->register($data);
9295
} catch (ClientRegistrationException $e) {
@@ -125,7 +128,8 @@ private function enrichAuthServerMetadata(ResponseInterface $response): Response
125128
->withBody($this->streamFactory->createStream(
126129
json_encode($metadata, \JSON_THROW_ON_ERROR | \JSON_UNESCAPED_SLASHES),
127130
))
128-
->withHeader('Content-Type', 'application/json');
131+
->withHeader('Content-Type', 'application/json')
132+
->withoutHeader('Content-Length');
129133
}
130134

131135
/**

0 commit comments

Comments
 (0)