Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,27 @@ public function toolbarAction(Request $request, ?string $token = null): Response
]);
}

/**
* Renders the Web Debug Toolbar stylesheet.
*
* @throws NotFoundHttpException
*/
public function toolbarStylesheetAction(): Response
{
$this->denyAccessIfProfilerDisabled();

$this->cspHandler?->disableCsp();

return new Response(
$this->twig->render('@WebProfiler/Profiler/toolbar.css.twig'),
200,
[
'Content-Type' => 'text/css',
'Cache-Control' => 'max-age=600, private',
],
);
}

/**
* Renders the profiler search bar.
*
Expand Down Expand Up @@ -383,6 +404,9 @@ protected function getTemplateManager(): TemplateManager
return $this->templateManager ??= new TemplateManager($this->profiler, $this->twig, $this->templates);
}

/**
* @throws NotFoundHttpException
*/
private function denyAccessIfProfilerDisabled(): void
{
if (null === $this->profiler) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/routing https://symfony.com/schema/routing/routing-1.0.xsd">

<route id="_wdt_stylesheet" path="/styles.css">
<default key="_controller">web_profiler.controller.profiler::toolbarStylesheetAction</default>
</route>

<route id="_wdt" path="/{token}">
<default key="_controller">web_profiler.controller.profiler::toolbarAction</default>
</route>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@
}) }}
</div>

<style{% if csp_style_nonce %} nonce="{{ csp_style_nonce }}"{% endif %}>
{{ include('@WebProfiler/Profiler/toolbar.css.twig') }}
</style>
<link rel="stylesheet"{% if csp_style_nonce %} nonce="{{ csp_style_nonce }}"{% endif %} href="{{ url('_wdt_stylesheet') }}" />

{# CAUTION: the contents of this file are processed by Twig before loading
them as JavaScript source code. Always use '/*' comments instead
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,33 @@ public function testToolbarActionWithEmptyToken($token)
$this->assertEquals(200, $response->getStatusCode());
}

public function testToolbarStylesheetActionWithProfilerDisabled()
{
$urlGenerator = $this->createMock(UrlGeneratorInterface::class);
$twig = $this->createMock(Environment::class);

$controller = new ProfilerController($urlGenerator, null, $twig, []);

$this->expectException(NotFoundHttpException::class);
$this->expectExceptionMessage('The profiler must be enabled.');

$controller->toolbarStylesheetAction();
}

public function testToolbarStylesheetAction()
{
$urlGenerator = $this->createMock(UrlGeneratorInterface::class);
$twig = $this->createMock(Environment::class);
$profiler = $this->createMock(Profiler::class);

$controller = new ProfilerController($urlGenerator, $profiler, $twig, []);

$response = $controller->toolbarStylesheetAction();
$this->assertSame(200, $response->getStatusCode());
$this->assertSame('text/css', $response->headers->get('Content-Type'));
$this->assertSame('max-age=600, private', $response->headers->get('Cache-Control'));
}

public static function getEmptyTokenCases()
{
return [
Expand Down