Skip to content

Commit 5889e26

Browse files
committed
Add validation for missing client_id in ServerController::authorize().
1 parent 1877fb2 commit 5889e26

File tree

2 files changed

+25
-4
lines changed

2 files changed

+25
-4
lines changed

solid/lib/Controller/ServerController.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -154,11 +154,13 @@ public function cors($path) {
154154
public function authorize() {
155155
// Create a request
156156
if (!$this->userManager->userExists($this->userId)) {
157-
$result = new JSONResponse('Authorization required');
158-
$result->setStatus(401);
159-
return $result;
160-
// return $result->addHeader('Access-Control-Allow-Origin', '*');
157+
return new JSONResponse('Authorization required', 401);
158+
}
159+
160+
if (! isset($_GET['client_id'])) {
161+
return new JSONResponse('Bad request, missing client_id', 400);
161162
}
163+
$clientId = $_GET['client_id'];
162164

163165
if (isset($_GET['request'])) {
164166
$jwtConfig = Configuration::forSymmetricSigner(new Sha256(), InMemory::plainText($this->config->getPrivateKey()));

solid/tests/Unit/Controller/ServerControllerTest.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,25 @@ public function testAuthorizeWithoutUser()
115115
$this->assertEquals($expected, $actual);
116116
}
117117

118+
/**
119+
* @testdox ServerController should return a 400 when asked to authorize with a user but without client_id
120+
*
121+
* @covers ::authorize
122+
*/
123+
public function testAuthorizeWithoutClientId()
124+
{
125+
$parameters = $this->createMockConstructorParameters();
126+
127+
$parameters['MockUserManager']->method('userExists')->willReturn(true);
128+
129+
$controller = new ServerController(...array_values($parameters));
130+
131+
$actual = $controller->authorize();
132+
$expected = new JSONResponse('Bad request, missing client_id', Http::STATUS_BAD_REQUEST);
133+
134+
$this->assertEquals($expected, $actual);
135+
}
136+
118137
/**
119138
* @testdox ServerController should return a 400 when asked to authorize with a user but without valid token
120139
*

0 commit comments

Comments
 (0)