Skip to content

Commit 065bbf3

Browse files
committed
Fixed exception being always instantiated
Exception was always created regardless if an error was actually there. What's more, it was created in one place, so it was impossible to determine which of the two code paths was taken.
1 parent 4d46dd3 commit 065bbf3

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

src/lib/Server/Controller/SessionController.php

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -217,13 +217,8 @@ private function checkCsrfToken(Request $request)
217217
return;
218218
}
219219

220-
$exception = new UnauthorizedException(
221-
'Missing or invalid CSRF token',
222-
$request->getMethod() . ' ' . $request->getPathInfo()
223-
);
224-
225220
if (!$request->headers->has('X-CSRF-Token')) {
226-
throw $exception;
221+
throw $this->createInvalidCsrfTokenException($request);
227222
}
228223

229224
$csrfToken = new CsrfToken(
@@ -232,7 +227,7 @@ private function checkCsrfToken(Request $request)
232227
);
233228

234229
if (!$this->csrfTokenManager->isTokenValid($csrfToken)) {
235-
throw $exception;
230+
throw $this->createInvalidCsrfTokenException($request);
236231
}
237232
}
238233

@@ -263,6 +258,14 @@ private function getAuthenticator(): ?AuthenticatorInterface
263258

264259
return $this->authenticator;
265260
}
261+
262+
private function createInvalidCsrfTokenException(Request $request): UnauthorizedException
263+
{
264+
return new UnauthorizedException(
265+
'Missing or invalid CSRF token',
266+
$request->getMethod() . ' ' . $request->getPathInfo()
267+
);
268+
}
266269
}
267270

268271
class_alias(SessionController::class, 'EzSystems\EzPlatformRest\Server\Controller\SessionController');

0 commit comments

Comments
 (0)