|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace Frosh\Tools\Components\Health\Checker\HealthChecker; |
| 6 | + |
| 7 | +use Frosh\Tools\Components\Health\Checker\CheckerInterface; |
| 8 | +use Frosh\Tools\Components\Health\HealthCollection; |
| 9 | +use Frosh\Tools\Components\Health\SettingsResult; |
| 10 | +use Symfony\Bundle\WebProfilerBundle\WebProfilerBundle; |
| 11 | +use Symfony\Component\DependencyInjection\Attribute\Autowire; |
| 12 | + |
| 13 | +class DebugChecker implements HealthCheckerInterface, CheckerInterface |
| 14 | +{ |
| 15 | + public function __construct( |
| 16 | + /** @var array<string, string> $kernelBundles */ |
| 17 | + #[Autowire(param: 'kernel.bundles')] |
| 18 | + private readonly array $kernelBundles, |
| 19 | + #[Autowire(param: 'kernel.debug')] |
| 20 | + private readonly bool $kernelDebug, |
| 21 | + ) {} |
| 22 | + |
| 23 | + public function collect(HealthCollection $collection): void |
| 24 | + { |
| 25 | + $this->checkWebProfiler($collection); |
| 26 | + $this->checkKernelDebug($collection); |
| 27 | + } |
| 28 | + |
| 29 | + private function checkWebProfiler(HealthCollection $collection): void |
| 30 | + { |
| 31 | + if (\in_array(WebProfilerBundle::class, $this->kernelBundles, true)) { |
| 32 | + $collection->add(SettingsResult::error( |
| 33 | + 'webprofiler', |
| 34 | + 'WebProfilerBundle is active which leaks sensitive information', |
| 35 | + 'active', |
| 36 | + 'not active' |
| 37 | + )); |
| 38 | + |
| 39 | + return; |
| 40 | + } |
| 41 | + |
| 42 | + $collection->add(SettingsResult::ok( |
| 43 | + 'webprofiler', |
| 44 | + 'WebProfilerBundle is not active', |
| 45 | + 'not active', |
| 46 | + 'not active' |
| 47 | + )); |
| 48 | + } |
| 49 | + |
| 50 | + private function checkKernelDebug(HealthCollection $collection): void |
| 51 | + { |
| 52 | + if ($this->kernelDebug) { |
| 53 | + $collection->add(SettingsResult::error( |
| 54 | + 'kerneldebug', |
| 55 | + 'Kernel debug is active', |
| 56 | + 'active', |
| 57 | + 'not active' |
| 58 | + )); |
| 59 | + |
| 60 | + return; |
| 61 | + } |
| 62 | + |
| 63 | + $collection->add(SettingsResult::ok( |
| 64 | + 'kerneldebug', |
| 65 | + 'Kernel debug is not active', |
| 66 | + 'not active', |
| 67 | + 'not active' |
| 68 | + )); |
| 69 | + } |
| 70 | +} |
0 commit comments