Skip to content

Commit

Permalink
feat: add check for active webProfiler and kernelDebug state
Browse files Browse the repository at this point in the history
(cherry picked from commit 3f623de)
  • Loading branch information
tinect committed Jan 9, 2025
1 parent 260bccd commit 7ff5d5d
Showing 1 changed file with 70 additions and 0 deletions.
70 changes: 70 additions & 0 deletions src/Components/Health/Checker/HealthChecker/DebugChecker.php
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'
));
}
}

0 comments on commit 7ff5d5d

Please sign in to comment.