Skip to content
Snippets Groups Projects
Verified Commit 5959b69d authored by Alex Pott's avatar Alex Pott
Browse files

Issue #3419693 by mondrake, alexpott, smustgrave, catch: Log error instead of...

Issue #3419693 by mondrake, alexpott, smustgrave, catch: Log error instead of trigger_error in Drupal\Core\EventSubscriber\RedirectResponseSubscriber::checkRedirectUrl

(cherry picked from commit 25697a17)
parent ec1aa07a
No related branches found
No related tags found
26 merge requests!11185Issue #3477324 by andypost, alexpott: Fix usage of str_getcsv() and fgetcsv() for PHP 8.4,!10602Issue #3438769 by vinmayiswamy, antonnavi, michelle, amateescu: Sub workspace does not clear,!10301Issue #3469309 by mstrelan, smustgrave, moshe weitzman: Use one-time login...,!10187Issue #3487488 by dakwamine: ExtensionMimeTypeGuesser::guessMimeType must support file names with "0" (zero) like foo.0.zip,!9944Issue #3483353: Consider making the createCopy config action optionally fail...,!9929Issue #3445469 by pooja_sharma, smustgrave: Add additional test coverage for...,!9787Resolve issue 3479427 - bootstrap barrio issue under Windows,!9742Issue #3463908 by catch, quietone: Split OptionsFieldUiTest into two,!9526Issue #3458177 by mondrake, catch, quietone, godotislate, longwave, larowlan,...,!8738Issue #3424162 by camilledavis, dineshkumarbollu, smustgrave: Claro...,!8704Make greek characters available in ckeditor5,!8597Draft: Issue #3442259 by catch, quietone, dww: Reduce time of Migrate Upgrade tests...,!8533Issue #3446962 by kim.pepper: Remove incorrectly added...,!8517Issue #3443748 by NexusNovaz, smustgrave: Testcase creates false positive,!8325Update file Sort.php,!8095Expose document root on install,!7930Resolve #3427374 "Taxonomytid viewsargumentdefault plugin",!7627Issue #3439440 by nicxvan, Binoli Lalani, longwave: Remove country support from DateFormatter,!7445Issue #3440169: When using drupalGet(), provide an associative array for $headers,!7401#3271894 Fix documented StreamWrapperInterface return types for realpath() and dirname(),!7384Add constraints to system.advisories,!7078Issue #3320569 by Spokje, mondrake, smustgrave, longwave, quietone, Lendude,...,!6622Issue #2559833 by piggito, mohit_aghera, larowlan, guptahemant, vakulrai,...,!6502Draft: Resolve #2938524 "Plach testing issue",!38582585169-10.1.x,!3226Issue #2987537: Custom menu link entity type should not declare "bundle" entity key
Pipeline #114011 passed with warnings
Pipeline: drupal

#114027

    Pipeline: drupal

    #114024

      Pipeline: drupal

      #114021

        +1
        ......@@ -1384,7 +1384,7 @@ services:
        class: Drupal\Core\EventSubscriber\ResponseGeneratorSubscriber
        redirect_response_subscriber:
        class: Drupal\Core\EventSubscriber\RedirectResponseSubscriber
        arguments: ['@unrouted_url_assembler', '@router.request_context']
        autowire: true
        redirect_leading_slashes_subscriber:
        class: Drupal\Core\EventSubscriber\RedirectLeadingSlashesSubscriber
        request_close_subscriber:
        ......
        ......@@ -7,24 +7,18 @@
        use Drupal\Core\Routing\LocalRedirectResponse;
        use Drupal\Core\Routing\RequestContext;
        use Drupal\Core\Utility\UnroutedUrlAssemblerInterface;
        use Symfony\Component\DependencyInjection\Attribute\AutowireServiceClosure;
        use Symfony\Component\EventDispatcher\EventSubscriberInterface;
        use Symfony\Component\HttpFoundation\RedirectResponse;
        use Symfony\Component\HttpFoundation\Response;
        use Symfony\Component\HttpKernel\KernelEvents;
        use Symfony\Component\HttpKernel\Event\ResponseEvent;
        use Symfony\Component\HttpFoundation\RedirectResponse;
        use Symfony\Component\EventDispatcher\EventSubscriberInterface;
        use Symfony\Component\HttpKernel\KernelEvents;
        /**
        * Allows manipulation of the response object when performing a redirect.
        */
        class RedirectResponseSubscriber implements EventSubscriberInterface {
        /**
        * The unrouted URL assembler service.
        *
        * @var \Drupal\Core\Utility\UnroutedUrlAssemblerInterface
        */
        protected $unroutedUrlAssembler;
        /**
        * Whether to ignore the destination query parameter when redirecting.
        *
        ......@@ -32,22 +26,22 @@ class RedirectResponseSubscriber implements EventSubscriberInterface {
        */
        protected bool $ignoreDestination = FALSE;
        /**
        * The request context.
        */
        protected RequestContext $requestContext;
        /**
        * Constructs a RedirectResponseSubscriber object.
        *
        * @param \Drupal\Core\Utility\UnroutedUrlAssemblerInterface $url_assembler
        * @param \Drupal\Core\Utility\UnroutedUrlAssemblerInterface $unroutedUrlAssembler
        * The unrouted URL assembler service.
        * @param \Drupal\Core\Routing\RequestContext $request_context
        * @param \Drupal\Core\Routing\RequestContext $requestContext
        * The request context.
        * @param \Closure $loggerClosure
        * A closure that wraps the 'logger.channel.php' service.
        */
        public function __construct(UnroutedUrlAssemblerInterface $url_assembler, RequestContext $request_context) {
        $this->unroutedUrlAssembler = $url_assembler;
        $this->requestContext = $request_context;
        public function __construct(
        protected UnroutedUrlAssemblerInterface $unroutedUrlAssembler,
        protected RequestContext $requestContext,
        #[AutowireServiceClosure('logger.channel.php')]
        protected \Closure $loggerClosure,
        ) {
        }
        /**
        ......@@ -87,13 +81,14 @@ public function checkRedirectUrl(ResponseEvent $event) {
        }
        catch (\InvalidArgumentException $e) {
        // If the above failed, it's because the redirect target wasn't
        // local. Do not follow that redirect. Display an error message
        // instead. We're already catching one exception, so trigger_error()
        // rather than throw another one.
        // We don't throw an exception, because this is a client error rather than a
        // server error.
        // local. Do not follow that redirect. Log an error message instead,
        // then return a 400 response to the client with the error message.
        // We don't throw an exception, because this is a client error rather
        // than a server error.
        $message = 'Redirects to external URLs are not allowed by default, use \Drupal\Core\Routing\TrustedRedirectResponse for it.';
        trigger_error($message, E_USER_ERROR);
        /** @var \Psr\Log\LoggerInterface $logger */
        $logger = ($this->loggerClosure)();
        $logger->error($message);
        $safe_response = new Response($message, 400);
        }
        $event->setResponse($safe_response);
        ......
        ......@@ -2724,14 +2724,6 @@ parameters:
        count: 1
        path: tests/Drupal/Tests/Core/Entity/EntityUrlTest.php
        -
        message: """
        #^Call to deprecated method expectError\\(\\) of class PHPUnit\\\\Framework\\\\TestCase\\:
        https\\://github\\.com/sebastianbergmann/phpunit/issues/5062$#
        """
        count: 2
        path: tests/Drupal/Tests/Core/EventSubscriber/RedirectResponseSubscriberTest.php
        -
        message: """
        #^Call to deprecated method expectWarning\\(\\) of class PHPUnit\\\\Framework\\\\TestCase\\:
        ......
        ......@@ -4,12 +4,13 @@
        namespace Drupal\Tests\Core\EventSubscriber;
        use Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher as EventDispatcher;
        use Drupal\Core\EventSubscriber\RedirectResponseSubscriber;
        use Drupal\Core\Routing\TrustedRedirectResponse;
        use Drupal\Core\Utility\UnroutedUrlAssemblerInterface;
        use Drupal\Tests\UnitTestCase;
        use Psr\Log\LoggerInterface;
        use Symfony\Component\DependencyInjection\Container;
        use Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher as EventDispatcher;
        use Symfony\Component\HttpFoundation\RedirectResponse;
        use Symfony\Component\HttpFoundation\Request;
        use Symfony\Component\HttpKernel\Event\ResponseEvent;
        ......@@ -36,12 +37,21 @@ class RedirectResponseSubscriberTest extends UnitTestCase {
        */
        protected $urlAssembler;
        /**
        * The mocked logger closure.
        */
        protected \Closure $loggerClosure;
        /**
        * {@inheritdoc}
        */
        protected function setUp(): void {
        parent::setUp();
        $this->loggerClosure = function (): LoggerInterface {
        return $this->prophesize(LoggerInterface::class)->reveal();
        };
        $this->requestContext = $this->getMockBuilder('Drupal\Core\Routing\RequestContext')
        ->disableOriginalConstructor()
        ->getMock();
        ......@@ -82,7 +92,7 @@ public function testDestinationRedirect(Request $request, $expected) {
        $response = new RedirectResponse('http://example.com/drupal');
        $request->headers->set('HOST', 'example.com');
        $listener = new RedirectResponseSubscriber($this->urlAssembler, $this->requestContext);
        $listener = new RedirectResponseSubscriber($this->urlAssembler, $this->requestContext, $this->loggerClosure);
        $dispatcher->addListener(KernelEvents::RESPONSE, [$listener, 'checkRedirectUrl']);
        $event = new ResponseEvent($kernel, $request, HttpKernelInterface::SUB_REQUEST, $response);
        $dispatcher->dispatch($event, KernelEvents::RESPONSE);
        ......@@ -122,11 +132,11 @@ public function testDestinationRedirectToExternalUrl($request, $expected) {
        $kernel = $this->createMock('Symfony\Component\HttpKernel\HttpKernelInterface');
        $response = new RedirectResponse('http://other-example.com');
        $listener = new RedirectResponseSubscriber($this->urlAssembler, $this->requestContext);
        $listener = new RedirectResponseSubscriber($this->urlAssembler, $this->requestContext, $this->loggerClosure);
        $dispatcher->addListener(KernelEvents::RESPONSE, [$listener, 'checkRedirectUrl']);
        $event = new ResponseEvent($kernel, $request, HttpKernelInterface::SUB_REQUEST, $response);
        $this->expectError();
        $dispatcher->dispatch($event, KernelEvents::RESPONSE);
        $this->assertSame(400, $event->getResponse()->getStatusCode());
        }
        /**
        ......@@ -139,7 +149,7 @@ public function testRedirectWithOptInExternalUrl() {
        $request = Request::create('');
        $request->headers->set('HOST', 'example.com');
        $listener = new RedirectResponseSubscriber($this->urlAssembler, $this->requestContext);
        $listener = new RedirectResponseSubscriber($this->urlAssembler, $this->requestContext, $this->loggerClosure);
        $dispatcher->addListener(KernelEvents::RESPONSE, [$listener, 'checkRedirectUrl']);
        $event = new ResponseEvent($kernel, $request, HttpKernelInterface::SUB_REQUEST, $response);
        $dispatcher->dispatch($event, KernelEvents::RESPONSE);
        ......@@ -170,11 +180,11 @@ public function testDestinationRedirectWithInvalidUrl(Request $request) {
        $kernel = $this->createMock('Symfony\Component\HttpKernel\HttpKernelInterface');
        $response = new RedirectResponse('http://example.com/drupal');
        $listener = new RedirectResponseSubscriber($this->urlAssembler, $this->requestContext);
        $listener = new RedirectResponseSubscriber($this->urlAssembler, $this->requestContext, $this->loggerClosure);
        $dispatcher->addListener(KernelEvents::RESPONSE, [$listener, 'checkRedirectUrl']);
        $event = new ResponseEvent($kernel, $request, HttpKernelInterface::SUB_REQUEST, $response);
        $this->expectError();
        $dispatcher->dispatch($event, KernelEvents::RESPONSE);
        $this->assertSame(400, $event->getResponse()->getStatusCode());
        }
        /**
        ......
        0% Loading or .
        You are about to add 0 people to the discussion. Proceed with caution.
        Finish editing this message first!
        Please register or to comment