From 6e0785f8c52af4c0fe9c6b5264a9f66b483d0d6a Mon Sep 17 00:00:00 2001 From: error56 <46536532+error56@users.noreply.github.com> Date: Sat, 6 Apr 2019 18:09:06 +0200 Subject: [PATCH] [Profiler] Update ProfilerController.php --- .../Controller/ProfilerController.php | 45 +++++++------------ 1 file changed, 15 insertions(+), 30 deletions(-) diff --git a/src/Symfony/Bundle/WebProfilerBundle/Controller/ProfilerController.php b/src/Symfony/Bundle/WebProfilerBundle/Controller/ProfilerController.php index 35cf31fbf9..2dc1c62436 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/Controller/ProfilerController.php +++ b/src/Symfony/Bundle/WebProfilerBundle/Controller/ProfilerController.php @@ -54,11 +54,7 @@ class ProfilerController */ public function homeAction() { - if (null === $this->profiler) { - throw new NotFoundHttpException('The profiler must be enabled.'); - } - - $this->profiler->disable(); + $this->denyAccessIfProfilerDisabled(); return new RedirectResponse($this->generator->generate('_profiler_search_results', ['token' => 'empty', 'limit' => 10]), 302, ['Content-Type' => 'text/html']); } @@ -75,11 +71,7 @@ class ProfilerController */ public function panelAction(Request $request, $token) { - if (null === $this->profiler) { - throw new NotFoundHttpException('The profiler must be enabled.'); - } - - $this->profiler->disable(); + $this->denyAccessIfProfilerDisabled(); if (null !== $this->cspHandler) { $this->cspHandler->disableCsp(); @@ -170,11 +162,7 @@ class ProfilerController */ public function searchBarAction(Request $request) { - if (null === $this->profiler) { - throw new NotFoundHttpException('The profiler must be enabled.'); - } - - $this->profiler->disable(); + $this->denyAccessIfProfilerDisabled(); if (null !== $this->cspHandler) { $this->cspHandler->disableCsp(); @@ -231,11 +219,7 @@ class ProfilerController */ public function searchResultsAction(Request $request, $token) { - if (null === $this->profiler) { - throw new NotFoundHttpException('The profiler must be enabled.'); - } - - $this->profiler->disable(); + $this->denyAccessIfProfilerDisabled(); if (null !== $this->cspHandler) { $this->cspHandler->disableCsp(); @@ -276,11 +260,7 @@ class ProfilerController */ public function searchAction(Request $request) { - if (null === $this->profiler) { - throw new NotFoundHttpException('The profiler must be enabled.'); - } - - $this->profiler->disable(); + $this->denyAccessIfProfilerDisabled(); $ip = preg_replace('/[^:\d\.]/', '', $request->query->get('ip')); $method = $request->query->get('method'); @@ -331,11 +311,7 @@ class ProfilerController */ public function phpinfoAction() { - if (null === $this->profiler) { - throw new NotFoundHttpException('The profiler must be enabled.'); - } - - $this->profiler->disable(); + $this->denyAccessIfProfilerDisabled(); if (null !== $this->cspHandler) { $this->cspHandler->disableCsp(); @@ -394,6 +370,15 @@ class ProfilerController return $this->templateManager; } + + private function denyAccessIfProfilerDisabled() + { + if (null === $this->profiler) { + throw new NotFoundHttpException('The profiler must be enabled.'); + } + + $this->profiler->disable(); + } private function renderWithCspNonces(Request $request, $template, $variables, $code = 200, $headers = ['Content-Type' => 'text/html']) {