Repository navigation
Disable the debug toolbar and the /_profiler/phpinfo page in dev #298
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
robertSt7
wants to merge
4
commits into
2026.3
Choose a base branch
from
fix/disable-profiler-toolbar-phpinfo
base: 2026.3
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
a8a2c30
Disable the debug toolbar and the /_profiler/phpinfo page in the dev …
robertSt7 f2bad2e
Run the dev profiler test against the test database
robertSt7 ad41599
Restore each DATABASE_URL environment store separately in the profile…
robertSt7 c0eec15
Document how to activate the profiler toolbar and the phpinfo page in…
robertSt7 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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 |
|---|---|---|
| @@ -1,2 +1,7 @@ | ||
| imports: | ||
| - { resource: ../../config.yaml } | ||
|
|
||
| # The Symfony debug toolbar is off by default, so a dev instance that is reachable from the network does not | ||
| # advertise the profiler on every page. Set it to `true` locally when you want it. | ||
| web_profiler: | ||
| toolbar: false |
This file contains hidden or 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 |
|---|---|---|
| @@ -1,2 +1,11 @@ | ||
| _pimcore_dev: | ||
| resource: "@PimcoreCoreBundle/config/routing_dev.yaml" | ||
|
|
||
| # Symfony's profiler route `/_profiler/phpinfo` prints phpinfo() - including environment variables and secrets - to | ||
| # anyone who can reach the application, and it is not affected by `web_profiler.toolbar`. Redefining the route | ||
| # under the same name replaces it with one that never matches, so the URL falls through to the profiler's token | ||
| # route, which only reports an unknown token, while the rest of the profiler keeps working. Delete this route to | ||
| # get the page back. | ||
| _profiler_phpinfo: | ||
| path: /_profiler/phpinfo | ||
| condition: "false" |
This file contains hidden or 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,130 @@ | ||
| <?php | ||
| declare(strict_types=1); | ||
|
|
||
| namespace App\Tests\Functional\Dev; | ||
|
|
||
| use App\Kernel; | ||
| use Pimcore\Test\KernelTestCase; | ||
| use Symfony\Bundle\WebProfilerBundle\EventListener\WebDebugToolbarListener; | ||
| use Symfony\Component\HttpFoundation\Request; | ||
|
|
||
| /** | ||
| * Covers the shipped dev-environment profiler defaults (config/packages/dev, config/routes/dev). | ||
| */ | ||
| class ProfilerTest extends KernelTestCase | ||
| { | ||
| /** | ||
| * Original DATABASE_URL of each environment store while it is overridden; null means the store had no entry. | ||
| * | ||
| * @var array{server: array{value: mixed}|null, env: array{value: mixed}|null, process: array{value: string}|null}|null | ||
| */ | ||
| private ?array $originalDatabaseUrl = null; | ||
|
|
||
| protected static function getKernelClass(): string | ||
| { | ||
| return Kernel::class; | ||
| } | ||
|
|
||
| protected function setUp(): void | ||
| { | ||
| parent::setUp(); | ||
|
|
||
| $this->useTestDatabase(); | ||
|
|
||
| // The profiler is only available in the dev environment, so boot that one instead of the test environment. | ||
| self::bootKernel(['environment' => 'dev', 'debug' => true]); | ||
| } | ||
|
|
||
| protected function tearDown(): void | ||
| { | ||
| parent::tearDown(); | ||
|
|
||
| $this->restoreDatabaseUrl(); | ||
| } | ||
|
|
||
| public function testPhpinfoRouteIsNotMatched(): void | ||
| { | ||
| $match = self::$kernel->getContainer()->get('router')->match('/_profiler/phpinfo'); | ||
|
|
||
| // The URL must fall through to the profiler's token route instead of reaching the phpinfo action. | ||
| self::assertNotSame('_profiler_phpinfo', $match['_route']); | ||
| self::assertSame('_profiler', $match['_route']); | ||
| self::assertSame('phpinfo', $match['token']); | ||
| } | ||
|
|
||
| public function testPhpinfoIsNotServed(): void | ||
| { | ||
| $response = self::$kernel->handle(Request::create('/_profiler/phpinfo')); | ||
| $content = (string) $response->getContent(); | ||
|
|
||
| // The profiler's token route answers instead, reporting an unknown token. | ||
| self::assertStringNotContainsString('PHP Version', $content); | ||
| self::assertStringNotContainsString('PHP Credits', $content); | ||
| self::assertStringContainsString('phpinfo', $content); | ||
| } | ||
|
|
||
| public function testProfilerRoutesStillWork(): void | ||
| { | ||
| $router = self::$kernel->getContainer()->get('router'); | ||
|
|
||
| // Only phpinfo is blocked: the profiler itself and its links to the phpinfo route keep working. | ||
| self::assertSame('_profiler_search_results', $router->match('/_profiler/abc123/search/results')['_route']); | ||
| self::assertSame('/_profiler/phpinfo', $router->generate('_profiler_phpinfo')); | ||
| } | ||
|
|
||
| public function testToolbarIsDisabledByDefault(): void | ||
| { | ||
| $container = self::$kernel->getContainer(); | ||
|
|
||
| // The parameter is only registered while the toolbar (or redirect interception) is enabled. | ||
| $enabled = $container->hasParameter('web_profiler.debug_toolbar.mode') | ||
| && WebDebugToolbarListener::ENABLED === $container->getParameter('web_profiler.debug_toolbar.mode'); | ||
|
|
||
| self::assertFalse($enabled); | ||
| } | ||
|
|
||
| /** | ||
| * The dev environment does not apply the test database override of config/packages/test, so point the | ||
| * default connection at the test database explicitly instead of the development one. | ||
| */ | ||
| private function useTestDatabase(): void | ||
| { | ||
| $dsn = $_SERVER['PIMCORE_TEST_DB_DSN'] ?? $_ENV['PIMCORE_TEST_DB_DSN'] ?? getenv('PIMCORE_TEST_DB_DSN'); | ||
| if (!is_string($dsn) || '' === $dsn) { | ||
| return; | ||
| } | ||
|
|
||
| $processValue = getenv('DATABASE_URL'); | ||
| $this->originalDatabaseUrl = [ | ||
| 'server' => array_key_exists('DATABASE_URL', $_SERVER) ? ['value' => $_SERVER['DATABASE_URL']] : null, | ||
| 'env' => array_key_exists('DATABASE_URL', $_ENV) ? ['value' => $_ENV['DATABASE_URL']] : null, | ||
| 'process' => false === $processValue ? null : ['value' => $processValue], | ||
| ]; | ||
|
|
||
| $_SERVER['DATABASE_URL'] = $_ENV['DATABASE_URL'] = $dsn; | ||
| putenv('DATABASE_URL=' . $dsn); | ||
| } | ||
|
|
||
| private function restoreDatabaseUrl(): void | ||
| { | ||
| if (null === $this->originalDatabaseUrl) { | ||
| return; | ||
| } | ||
|
|
||
| if (null === $this->originalDatabaseUrl['server']) { | ||
| unset($_SERVER['DATABASE_URL']); | ||
| } else { | ||
| $_SERVER['DATABASE_URL'] = $this->originalDatabaseUrl['server']['value']; | ||
| } | ||
|
|
||
| if (null === $this->originalDatabaseUrl['env']) { | ||
| unset($_ENV['DATABASE_URL']); | ||
| } else { | ||
| $_ENV['DATABASE_URL'] = $this->originalDatabaseUrl['env']['value']; | ||
| } | ||
|
|
||
| putenv('DATABASE_URL' . (null === $this->originalDatabaseUrl['process'] ? '' : '=' . $this->originalDatabaseUrl['process']['value'])); | ||
|
|
||
| $this->originalDatabaseUrl = null; | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.