Catch more exceptions during boot process

This extends our boot exception handling block to also catch and format
all exceptions that could be thrown while building our request handler,
i.e. the middleware stack handling requests.

The only exceptions that would now not be handled in this way could be
raised by Zend's `RequestHandlerRunner` and its delegates, which we
should be able to rely on.

Exceptions on request execution will be handled by the error handler in
the middleware stack.

Fixes #1607.
This commit is contained in:
Franz Liedke 2019-12-07 01:16:48 +01:00
parent 840e740309
commit 43c551929b
No known key found for this signature in database
GPG Key ID: 9A0231A879B055F4

View File

@ -29,10 +29,8 @@ class Server
public function listen()
{
$app = $this->safelyBootApp();
$runner = new RequestHandlerRunner(
$app->getRequestHandler(),
$this->safelyBootAndGetHandler(),
new SapiEmitter,
[ServerRequestFactory::class, 'fromGlobals'],
function (Throwable $e) {
@ -45,14 +43,17 @@ class Server
}
/**
* Try to boot Flarum, and prevent exceptions from exposing sensitive info.
* Try to boot Flarum, and retrieve the app's HTTP request handler.
*
* @return \Flarum\Foundation\AppInterface
* We catch all exceptions happening during this process and format them to
* prevent exposure of sensitive information.
*
* @return \Psr\Http\Server\RequestHandlerInterface
*/
private function safelyBootApp()
private function safelyBootAndGetHandler()
{
try {
return $this->site->bootApp();
return $this->site->bootApp()->getRequestHandler();
} catch (Throwable $e) {
exit($this->formatBootException($e));
}