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