Skip to content

Commit 06d8aaa

Browse files
Deal with bad actors who throw http exceptions with invalid codes
1 parent 42c5b78 commit 06d8aaa

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

src/Exception/Handler.php

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,11 +203,23 @@ protected function genericResponse(Throwable $exception)
203203
*/
204204
protected function getStatusCode(Throwable $exception)
205205
{
206+
$statusCode = null;
207+
206208
if ($exception instanceof ValidationException) {
207-
return $exception->status;
209+
$statusCode = $exception->status;
210+
} else if ($exception instanceof HttpExceptionInterface) {
211+
$statusCode = $exception->getStatusCode();
212+
} else {
213+
// By default throw 500
214+
$statusCode = 500;
215+
}
216+
217+
// Be extra defensive
218+
if ($statusCode < 100 || $statusCode > 500) {
219+
$statusCode = 500;
208220
}
209221

210-
return $exception instanceof HttpExceptionInterface ? $exception->getStatusCode() : 500;
222+
return $statusCode;
211223
}
212224

213225
/**

0 commit comments

Comments
 (0)