-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add check for active webProfiler and kernelDebug state
(cherry picked from commit 3f623de)
- Loading branch information
Showing
1 changed file
with
70 additions
and
0 deletions.
There are no files selected for viewing
70 changes: 70 additions & 0 deletions
70
src/Components/Health/Checker/HealthChecker/DebugChecker.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Frosh\Tools\Components\Health\Checker\HealthChecker; | ||
|
||
use Frosh\Tools\Components\Health\Checker\CheckerInterface; | ||
use Frosh\Tools\Components\Health\HealthCollection; | ||
use Frosh\Tools\Components\Health\SettingsResult; | ||
use Symfony\Bundle\WebProfilerBundle\WebProfilerBundle; | ||
use Symfony\Component\DependencyInjection\Attribute\Autowire; | ||
|
||
class DebugChecker implements HealthCheckerInterface, CheckerInterface | ||
{ | ||
public function __construct( | ||
/** @var array<string, string> $kernelBundles */ | ||
#[Autowire(param: 'kernel.bundles')] | ||
private readonly array $kernelBundles, | ||
#[Autowire(param: 'kernel.debug')] | ||
private readonly bool $kernelDebug, | ||
) {} | ||
|
||
public function collect(HealthCollection $collection): void | ||
{ | ||
$this->checkWebProfiler($collection); | ||
$this->checkKernelDebug($collection); | ||
} | ||
|
||
private function checkWebProfiler(HealthCollection $collection): void | ||
{ | ||
if (\in_array(WebProfilerBundle::class, $this->kernelBundles, true)) { | ||
$collection->add(SettingsResult::error( | ||
'webprofiler', | ||
'WebProfilerBundle is active which leaks sensitive information', | ||
'active', | ||
'not active' | ||
)); | ||
|
||
return; | ||
} | ||
|
||
$collection->add(SettingsResult::ok( | ||
'webprofiler', | ||
'WebProfilerBundle is not active', | ||
'not active', | ||
'not active' | ||
)); | ||
} | ||
|
||
private function checkKernelDebug(HealthCollection $collection): void | ||
{ | ||
if ($this->kernelDebug) { | ||
$collection->add(SettingsResult::error( | ||
'kerneldebug', | ||
'Kernel debug is active', | ||
'active', | ||
'not active' | ||
)); | ||
|
||
return; | ||
} | ||
|
||
$collection->add(SettingsResult::ok( | ||
'kerneldebug', | ||
'Kernel debug is not active', | ||
'not active', | ||
'not active' | ||
)); | ||
} | ||
} |