‪TYPO3CMS  10.4
ProductionExceptionHandler.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
16 namespace ‪TYPO3\CMS\Core\Error;
17 
23 
30 {
36  protected ‪$defaultTitle = 'Oops, an error occurred!';
37 
43  protected ‪$defaultMessage = '';
44 
48  public function ‪__construct()
49  {
50  set_exception_handler([$this, 'handleException']);
51  }
52 
58  public function ‪echoExceptionWeb(\Throwable $exception)
59  {
60  $this->‪sendStatusHeaders($exception);
61  $this->‪writeLogEntries($exception, self::CONTEXT_WEB);
62  echo GeneralUtility::makeInstance(ErrorPageController::class)->errorAction(
63  $this->‪getTitle($exception),
64  $this->‪getMessage($exception),
66  $this->‪discloseExceptionInformation($exception) ? $exception->getCode() : 0
67  );
68  }
69 
75  public function ‪echoExceptionCLI(\Throwable $exception)
76  {
77  $filePathAndName = $exception->getFile();
78  $exceptionCodeNumber = $exception->getCode() > 0 ? '#' . $exception->getCode() . ': ' : '';
79  $this->‪writeLogEntries($exception, self::CONTEXT_CLI);
80  echo LF . 'Uncaught TYPO3 Exception ' . $exceptionCodeNumber . $exception->getMessage() . LF;
81  echo 'thrown in file ' . $filePathAndName . LF;
82  echo 'in line ' . $exception->getLine() . LF . LF;
83  die(1);
84  }
85 
92  protected function ‪discloseExceptionInformation(\Throwable $exception)
93  {
94  // Allow message to be shown in production mode if the exception is about
95  // trusted host configuration. By doing so we do not disclose
96  // any valuable information to an attacker but avoid confusions among TYPO3 admins
97  // in production context.
98  if ($exception->getCode() === 1396795884) {
99  return true;
100  }
101  // Show client error messages 40x in every case
102  if ($exception instanceof ‪AbstractClientErrorException) {
103  return true;
104  }
105  // Only show errors if a BE user is authenticated
106  if (‪$GLOBALS['BE_USER'] instanceof ‪BackendUserAuthentication) {
107  return ‪$GLOBALS['BE_USER']->user['uid'] > 0;
108  }
109  return false;
110  }
111 
118  protected function ‪getTitle(\Throwable $exception)
119  {
120  if ($this->‪discloseExceptionInformation($exception) && method_exists($exception, 'getTitle') && $exception->getTitle() !== '') {
121  return $exception->getTitle();
122  }
123  return ‪$this->defaultTitle;
124  }
125 
132  protected function ‪getMessage(\Throwable $exception)
133  {
134  if ($this->‪discloseExceptionInformation($exception)) {
135  return $exception->getMessage();
136  }
138  }
139 }
‪TYPO3\CMS\Core\Error\ProductionExceptionHandler\$defaultMessage
‪string $defaultMessage
Definition: ProductionExceptionHandler.php:41
‪TYPO3\CMS\Core\Error\ProductionExceptionHandler\__construct
‪__construct()
Definition: ProductionExceptionHandler.php:46
‪TYPO3\CMS\Core\Messaging\AbstractMessage
Definition: AbstractMessage.php:26
‪TYPO3\CMS\Core\Controller\ErrorPageController
Definition: ErrorPageController.php:32
‪TYPO3\CMS\Core\Error\ProductionExceptionHandler
Definition: ProductionExceptionHandler.php:30
‪TYPO3\CMS\Core\Error\ProductionExceptionHandler\echoExceptionWeb
‪echoExceptionWeb(\Throwable $exception)
Definition: ProductionExceptionHandler.php:56
‪TYPO3\CMS\Core\Error\Http\AbstractClientErrorException
Definition: AbstractClientErrorException.php:22
‪TYPO3\CMS\Core\Error\AbstractExceptionHandler
Definition: AbstractExceptionHandler.php:34
‪TYPO3\CMS\Core\Error\ProductionExceptionHandler\discloseExceptionInformation
‪bool discloseExceptionInformation(\Throwable $exception)
Definition: ProductionExceptionHandler.php:90
‪TYPO3\CMS\Core\Error\ProductionExceptionHandler\getMessage
‪string getMessage(\Throwable $exception)
Definition: ProductionExceptionHandler.php:130
‪TYPO3\CMS\Core\Error\ProductionExceptionHandler\$defaultTitle
‪string $defaultTitle
Definition: ProductionExceptionHandler.php:35
‪TYPO3\CMS\Core\Error\AbstractExceptionHandler\sendStatusHeaders
‪sendStatusHeaders(\Throwable $exception)
Definition: AbstractExceptionHandler.php:154
‪TYPO3\CMS\Core\Error\ProductionExceptionHandler\getTitle
‪string getTitle(\Throwable $exception)
Definition: ProductionExceptionHandler.php:116
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication
Definition: BackendUserAuthentication.php:62
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Core\Error
Definition: AbstractExceptionHandler.php:16
‪TYPO3\CMS\Core\Error\ProductionExceptionHandler\echoExceptionCLI
‪echoExceptionCLI(\Throwable $exception)
Definition: ProductionExceptionHandler.php:73
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Core\Messaging\AbstractMessage\ERROR
‪const ERROR
Definition: AbstractMessage.php:31
‪TYPO3\CMS\Core\Error\AbstractExceptionHandler\writeLogEntries
‪writeLogEntries(\Throwable $exception, $context)
Definition: AbstractExceptionHandler.php:72