Skip to content

Commit

Permalink
Prevent exceptions from being interpreted as HTML (#1394)
Browse files Browse the repository at this point in the history
  • Loading branch information
BelleNottelling committed Jul 1, 2023
1 parent c718051 commit 5eb516d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/library/FOSSBilling/ErrorPage.php
Expand Up @@ -137,7 +137,7 @@ private function getCodeInfo(int $code): array
public function generatePage(int $code, string $message)
{
$error = $this->getCodeInfo($code);
$error['message'] ??= __trans('Uh-oh! You\'ve received a generic error message: :errorMessage', [':errorMessage' => '<code>' . $message . '</code>']);
$error['message'] ??= __trans('You\'ve received a generic error message: :errorMessage', [':errorMessage' => '<code>' . $message . '</code>']);

$page = '
<!DOCTYPE html>
Expand Down
9 changes: 5 additions & 4 deletions src/load.php
Expand Up @@ -152,16 +152,17 @@ function errorHandler(int $number, string $message, string $file, int $line)
*/
function exceptionHandler($e)
{
$message = htmlspecialchars($e->getMessage());
if (APPLICATION_ENV === 'testing') {
echo $e->getMessage() . PHP_EOL;
echo $message . PHP_EOL;

return;
}
error_log($e->getMessage());
error_log($message);

if (defined('BB_MODE_API')) {
$code = $e->getCode() ?: 9998;
$result = ['result' => null, 'error' => ['message' => $e->getMessage(), 'code' => $code]];
$result = ['result' => null, 'error' => ['message' => $message, 'code' => $code]];
echo json_encode($result);

return false;
Expand All @@ -187,7 +188,7 @@ function exceptionHandler($e)
} else {
include PATH_LIBRARY . DIRECTORY_SEPARATOR . 'FOSSBilling' . DIRECTORY_SEPARATOR . 'ErrorPage.php';
$errorPage = new \FOSSBilling\ErrorPage();
$errorPage->generatePage($e->getCode(), $e->getMessage());
$errorPage->generatePage($e->getCode(), $message);
}
}

Expand Down

0 comments on commit 5eb516d

Please sign in to comment.