Display only exception messages during booting

By not letting PHP render the stack trace, we prevent displaying
sensitive information (such as the database credentials). Instead,
we display a simple line with the exception message.

In the console, the full exception can still be shown, as that is
a tool only for forum admins anyway.

Fixes #1421.
This commit is contained in:
Franz Liedke 2018-09-21 23:33:28 +02:00
parent d35532b744
commit 712d1cdd1e

View File

@ -31,7 +31,7 @@ class Server
public function listen() public function listen()
{ {
$app = $this->site->bootApp(); $app = $this->safelyBootApp();
$runner = new RequestHandlerRunner( $runner = new RequestHandlerRunner(
$app->getRequestHandler(), $app->getRequestHandler(),
@ -45,4 +45,18 @@ class Server
); );
$runner->run(); $runner->run();
} }
/**
* Try to boot Flarum, and prevent exceptions from exposing sensitive info.
*
* @return \Flarum\Foundation\AppInterface
*/
private function safelyBootApp()
{
try {
return $this->site->bootApp();
} catch (Throwable $e) {
exit('Error booting Flarum: '.$e->getMessage());
}
}
} }