Added the Porter Stemmer module to improve searches. This doesn't deal with some...
[yaffs-website] / web / modules / contrib / security_review / src / Checks / ErrorReporting.php
1 <?php
2
3 namespace Drupal\security_review\Checks;
4
5 use Drupal\Core\Link;
6 use Drupal\security_review\Check;
7 use Drupal\security_review\CheckResult;
8
9 /**
10  * Defines a security check that checks the error reporting setting.
11  */
12 class ErrorReporting extends Check {
13
14   /**
15    * {@inheritdoc}
16    */
17   public function getNamespace() {
18     return 'Security Review';
19   }
20
21   /**
22    * {@inheritdoc}
23    */
24   public function getTitle() {
25     return 'Error reporting';
26   }
27
28   /**
29    * {@inheritdoc}
30    */
31   public function run() {
32     // Get the error level.
33     $error_level = $this->configFactory()->get('system.logging')
34       ->get('error_level');
35
36     // Determine the result.
37     if (is_null($error_level) || $error_level != 'hide') {
38       $result = CheckResult::FAIL;
39     }
40     else {
41       $result = CheckResult::SUCCESS;
42     }
43
44     return $this->createResult($result, ['level' => $error_level]);
45   }
46
47   /**
48    * {@inheritdoc}
49    */
50   public function help() {
51     $paragraphs = [];
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.');
53
54     return [
55       '#theme' => 'check_help',
56       '#title' => $this->t('Error reporting'),
57       '#paragraphs' => $paragraphs,
58     ];
59   }
60
61   /**
62    * {@inheritdoc}
63    */
64   public function evaluate(CheckResult $result) {
65     if ($result->result() == CheckResult::SUCCESS) {
66       return [];
67     }
68
69     $paragraphs = [];
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'
74     );
75
76     return [
77       '#theme' => 'check_evaluation',
78       '#paragraphs' => $paragraphs,
79       '#items' => [],
80     ];
81   }
82
83   /**
84    * {@inheritdoc}
85    */
86   public function evaluatePlain(CheckResult $result) {
87     if ($result->result() == CheckResult::SUCCESS) {
88       return '';
89     }
90
91     if (isset($result->findings()['level'])) {
92       return $this->t('Error level: @level', [
93         '@level' => $result->findings()['level'],
94       ]);
95     }
96     return '';
97   }
98
99   /**
100    * {@inheritdoc}
101    */
102   public function getMessage($result_const) {
103     switch ($result_const) {
104       case CheckResult::SUCCESS:
105         return $this->t('Error reporting set to log only.');
106
107       case CheckResult::FAIL:
108         return $this->t('Errors are written to the screen.');
109
110       default:
111         return $this->t('Unexpected result.');
112     }
113   }
114
115 }