Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[WebProfilerBundle] add nonces to profiler #44570

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

Merged
merged 1 commit into from
Feb 25, 2022
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 @@ -88,7 +88,7 @@ public function panelAction(Request $request, $token)
}

if (!$profile = $this->profiler->loadProfile($token)) {
return new Response($this->twig->render('@WebProfiler/Profiler/info.html.twig', ['about' => 'no_token', 'token' => $token, 'request' => $request]), 200, ['Content-Type' => 'text/html']);
return $this->renderWithCspNonces($request, '@WebProfiler/Profiler/info.html.twig', ['about' => 'no_token', 'token' => $token, 'request' => $request]);
}

if (null === $panel) {
Expand All @@ -111,7 +111,7 @@ public function panelAction(Request $request, $token)
throw new NotFoundHttpException(sprintf('Panel "%s" is not available for token "%s".', $panel, $token));
}

return new Response($this->twig->render($this->getTemplateManager()->getName($profile, $panel), [
return $this->renderWithCspNonces($request, $this->getTemplateManager()->getName($profile, $panel), [
'token' => $token,
'profile' => $profile,
'collector' => $profile->getCollector($panel),
Expand All @@ -121,7 +121,7 @@ public function panelAction(Request $request, $token)
'templates' => $this->getTemplateManager()->getNames($profile),
'is_ajax' => $request->isXmlHttpRequest(),
'profiler_markup_version' => 2, // 1 = original profiler, 2 = Symfony 2.8+ profiler
]), 200, ['Content-Type' => 'text/html']);
]);
}

/**
Expand Down Expand Up @@ -252,7 +252,7 @@ public function searchResultsAction(Request $request, $token)
$end = $request->query->get('end', null);
$limit = $request->query->get('limit');

return new Response($this->twig->render('@WebProfiler/Profiler/results.html.twig', [
return $this->renderWithCspNonces($request, '@WebProfiler/Profiler/results.html.twig', [
'request' => $request,
'token' => $token,
'profile' => $profile,
Expand All @@ -265,7 +265,7 @@ public function searchResultsAction(Request $request, $token)
'end' => $end,
'limit' => $limit,
'panel' => null,
]), 200, ['Content-Type' => 'text/html']);
]);
}

/**
Expand Down Expand Up @@ -367,11 +367,11 @@ public function openAction(Request $request)
throw new NotFoundHttpException(sprintf('The file "%s" cannot be opened.', $file));
}

return new Response($this->twig->render('@WebProfiler/Profiler/open.html.twig', [
return $this->renderWithCspNonces($request, '@WebProfiler/Profiler/open.html.twig', [
'filename' => $filename,
'file' => $file,
'line' => $line,
]), 200, ['Content-Type' => 'text/html']);
]);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
<link rel="icon" type="image/x-icon" sizes="16x16" href="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAFEUlEQVR4AZVXA4wm2RMf27bXDM/+3/+sYBGfrbVtezc6BWtzfPbYXtvDL9906t6v0vWl05me7q1JzXuvvu4yXnvZgJ9hH6bwZYXLFR739vauUGuDwhq1L1N4Uv/tRYUhFjwcg49hn6aYr1V4TiGp86CoP9Oh1tV414KnM6t9fHymKUZ3DAI0hW4b1AyK3lE8phh5OxWeoJgUGhi5mLm95YzBwcHuhIQEV1JSEoWGhoKWHxYWFmenhJ/B5W0GwZpDt5Ovry9lZWWRyWOu5ORk7JsUpogsq5gnmISTU+HKQoLFQv/qq6/os88+I+EVFRUlSsRZ5oRiVmwlXMWShQkahUdERJCfnx/vd+3aRTU1NXTixAmqrq6mK1eu0PTp05mnrmD+QK6XhLO0XP2O2FJAQICRjjMU4P1PP/1EfX19NGfOHM8Z0N7ezueQkBBXYGAgSWIaQ5Em2T5QzFNSUig9PV3OHOe4uDjZ87p//34C7Nm7x/NcRUUFAX799Vec8Y7m7+8Pz92SfBDXr7VwPYRbxn/MmDG8Tps2jQBd3V30/PPPe35/6qmnaPXq1TR69Gg+h4eHiwwosdLT4dBkQDSXWmJiIq/vv/8+/fvv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dwm95eg5xa/R8G6d8U5EcFhwAAAABJRU5ErkJggg==">

{% block head %}
<style>
<style{% if csp_style_nonce is defined and csp_style_nonce %} nonce="{{ csp_style_nonce }}"{% endif %}">
{{ include('@WebProfiler/Profiler/profiler.css.twig') }}
</style>
{% endblock %}
</head>
<body>
<script>
<script{% if csp_script_nonce is defined and csp_script_nonce %} nonce="{{ csp_script_nonce }}"{% endif %}">
document.body.classList.add(
localStorage.getItem('symfony/profiler/theme') || (matchMedia('(prefers-color-scheme: dark)').matches ? 'theme-dark' : 'theme-light'),
localStorage.getItem('symfony/profiler/width') || 'width-normal'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,8 @@ public function testSearchResultsAction($withCsp)
'limit' => 2,
'panel' => null,
'request' => $request,
'csp_script_nonce' => $withCsp ? 'dummy_nonce' : null,
'csp_style_nonce' => $withCsp ? 'dummy_nonce' : null,
]));

$response = $controller->searchResultsAction($request, 'empty');
Expand Down