3 namespace Drupal\security_review\Checks;
6 use Drupal\security_review\Check;
7 use Drupal\security_review\CheckResult;
10 * Defines a security check that checks the error reporting setting.
12 class ErrorReporting extends Check {
17 public function getNamespace() {
18 return 'Security Review';
24 public function getTitle() {
25 return 'Error reporting';
31 public function run() {
32 // Get the error level.
33 $error_level = $this->configFactory()->get('system.logging')
36 // Determine the result.
37 if (is_null($error_level) || $error_level != 'hide') {
38 $result = CheckResult::FAIL;
41 $result = CheckResult::SUCCESS;
44 return $this->createResult($result, ['level' => $error_level]);
50 public function help() {
52 $paragraphs[] = $this->t('As a form of hardening your site you should avoid information disclosure. Drupal by default prints errors to the screen and writes them to the log. Error messages disclose the full path to the file where the error occurred.');
55 '#theme' => 'check_help',
56 '#title' => $this->t('Error reporting'),
57 '#paragraphs' => $paragraphs,
64 public function evaluate(CheckResult $result) {
65 if ($result->result() == CheckResult::SUCCESS) {
70 $paragraphs[] = $this->t('You have error reporting set to both the screen and the log.');
71 $paragraphs[] = Link::createFromRoute(
72 $this->t('Alter error reporting settings.'),
73 'system.logging_settings'
77 '#theme' => 'check_evaluation',
78 '#paragraphs' => $paragraphs,
86 public function evaluatePlain(CheckResult $result) {
87 if ($result->result() == CheckResult::SUCCESS) {
91 if (isset($result->findings()['level'])) {
92 return $this->t('Error level: @level', [
93 '@level' => $result->findings()['level'],
102 public function getMessage($result_const) {
103 switch ($result_const) {
104 case CheckResult::SUCCESS:
105 return $this->t('Error reporting set to log only.');
107 case CheckResult::FAIL:
108 return $this->t('Errors are written to the screen.');
111 return $this->t('Unexpected result.');