ErrorReporting.php in Security Review 8
File
src/Checks/ErrorReporting.php
View source
<?php
namespace Drupal\security_review\Checks;
use Drupal\Core\Link;
use Drupal\security_review\Check;
use Drupal\security_review\CheckResult;
class ErrorReporting extends Check {
public function getNamespace() {
return 'Security Review';
}
public function getTitle() {
return 'Error reporting';
}
public function run() {
$error_level = $this
->configFactory()
->get('system.logging')
->get('error_level');
if (is_null($error_level) || $error_level != 'hide') {
$result = CheckResult::FAIL;
}
else {
$result = CheckResult::SUCCESS;
}
return $this
->createResult($result, [
'level' => $error_level,
]);
}
public function help() {
$paragraphs = [];
$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.');
return [
'#theme' => 'check_help',
'#title' => $this
->t('Error reporting'),
'#paragraphs' => $paragraphs,
];
}
public function evaluate(CheckResult $result) {
if ($result
->result() == CheckResult::SUCCESS) {
return [];
}
$paragraphs = [];
$paragraphs[] = $this
->t('You have error reporting set to both the screen and the log.');
$paragraphs[] = Link::createFromRoute($this
->t('Alter error reporting settings.'), 'system.logging_settings');
return [
'#theme' => 'check_evaluation',
'#paragraphs' => $paragraphs,
'#items' => [],
];
}
public function evaluatePlain(CheckResult $result) {
if ($result
->result() == CheckResult::SUCCESS) {
return '';
}
if (isset($result
->findings()['level'])) {
return $this
->t('Error level: @level', [
'@level' => $result
->findings()['level'],
]);
}
return '';
}
public function getMessage($result_const) {
switch ($result_const) {
case CheckResult::SUCCESS:
return $this
->t('Error reporting set to log only.');
case CheckResult::FAIL:
return $this
->t('Errors are written to the screen.');
default:
return $this
->t('Unexpected result.');
}
}
}
Classes
Name |
Description |
ErrorReporting |
Defines a security check that checks the error reporting setting. |