[FEATURE] Add feature switch to reorder redirect middlewares 26/61426/20
authorGeorg Gro├čberger <contact@grossberger-ge.org>
Sat, 3 Aug 2019 08:28:41 +0000 (10:28 +0200)
committerSusanne Moog <look@susi.dev>
Fri, 25 Oct 2019 17:18:11 +0000 (19:18 +0200)
A new feature switch has been introduced to change the ordering
of the redirect middleware and the base redirect middleware.

If enabled, the redirect is executed before the
base-redirect-resolver to ensure configured redirects are hit first.

To not break the current behaviour the new order is not
applied by default.

Resolves: #88902
Releases: master
Change-Id: I3ba732f4611c03f589c10bf74ddcb61deefe8816
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/61426
Tested-by: Andreas Fernandez <a.fernandez@scripting-base.de>
Tested-by: TYPO3com <noreply@typo3.com>
Tested-by: Susanne Moog <look@susi.dev>
Reviewed-by: Andreas Fernandez <a.fernandez@scripting-base.de>
Reviewed-by: Susanne Moog <look@susi.dev>
typo3/sysext/core/Configuration/DefaultConfiguration.php
typo3/sysext/core/Configuration/DefaultConfigurationDescription.yaml
typo3/sysext/core/Configuration/FactoryConfiguration.php
typo3/sysext/core/Documentation/Changelog/master/Important-88902-FeatureSwitchRedirectAndStaticRoutesMiddlewaresCanBeReordered.rst [new file with mode: 0644]
typo3/sysext/redirects/Configuration/RequestMiddlewares.php

index 903550a..ae008f1 100644 (file)
@@ -75,6 +75,7 @@ return [
             'redirects.hitCount' => false,
             'unifiedPageTranslationHandling' => false,
             'security.frontend.keepSessionDataOnLogout' => false,
+            'rearrangedRedirectMiddlewares' => false,
         ],
         'createGroup' => '',
         'sitename' => 'TYPO3',
index e842c43..f6c93d3 100644 (file)
@@ -223,6 +223,9 @@ SYS:
               security.frontend.keepSessionDataOnLogout:
                 type: bool
                 description: 'If on, session data is kept in an anonymous session after frontend user logged out. As this is a potential security risk, it is recommended to disable this option if not specifically needed.'
+              rearrangedRedirectMiddlewares:
+                type: bool
+                description: 'If on, the middlewares "base redirect" and "redirects" are switched, so that "redirects" (if ext:redirects is installed) is executed before "base redirect". The new ordering aims to be a better default shipped by the TYPO3 core.'
         availablePasswordHashAlgorithms:
             type: array
             description: 'A list of available password hash mechanisms. Extensions may register additional mechanisms here. This is usually not extended in LocalConfiguration.php.'
index 51e973d..e0e6177 100644 (file)
@@ -20,7 +20,8 @@ return [
     'SYS' => [
         'sitename' => 'New TYPO3 site',
         'features' => [
-            'unifiedPageTranslationHandling' => true
+            'unifiedPageTranslationHandling' => true,
+            'rearrangedRedirectMiddlewares' => true,
         ],
     ],
 ];
diff --git a/typo3/sysext/core/Documentation/Changelog/master/Important-88902-FeatureSwitchRedirectAndStaticRoutesMiddlewaresCanBeReordered.rst b/typo3/sysext/core/Documentation/Changelog/master/Important-88902-FeatureSwitchRedirectAndStaticRoutesMiddlewaresCanBeReordered.rst
new file mode 100644 (file)
index 0000000..48f0a42
--- /dev/null
@@ -0,0 +1,33 @@
+.. include:: ../../Includes.txt
+
+=========================================================================================
+Feature: #88902 - Feature Switch: Redirect and Base Redirect Middlewares can be reordered
+=========================================================================================
+
+See :issue:`88902`
+
+Description
+===========
+
+A new feature switch :php:`rearrangedRedirectMiddlewares` has been introduced to rearrange the middlewares
+:php:`typo3/cms-redirects/redirecthandler` and :php:`typo3/cms-frontend/base-redirect-resolver`. If enabled, the
+middlewares are executed in reversed order, so the :php:`typo3/cms-redirects/redirecthandler` comes first.
+
+The new ordering aims to be a better default shipped by the TYPO3 core but might still need adjustment due to specific
+configuration setups.
+
+The feature switch is turned off by default to assure a non-breaking behaviour.
+
+Impact
+======
+
+If turned on, the new ordering has the following implications:
+
+By putting the :php:`typo3/cms-frontend/base-redirect-resolver` last, redirects are always resolved even if no
+configured base URL was requested. In most cases this is considered to be a bugfix. However, redirect behavior might
+change.
+
+Custom middlewares that have been put in between the two above mentioned middlewares most likely will lead to a circular
+dependency exception now. Such custom middlewares have to be revisited and registered differently.
+
+.. index:: Frontend, NotScanned, ext:redirects
index 288afab..ec8ae6c 100644 (file)
@@ -3,16 +3,19 @@
 /**
  * Definitions for middlewares provided by EXT:redirects
  */
+$rearrangedMiddlewares = TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(
+    TYPO3\CMS\Core\Configuration\Features::class
+)->isFeatureEnabled('rearrangedRedirectMiddlewares');
+
 return [
     'frontend' => [
         'typo3/cms-redirects/redirecthandler' => [
             'target' => \TYPO3\CMS\Redirects\Http\Middleware\RedirectHandler::class,
             'before' => [
-                'typo3/cms-frontend/page-resolver',
+                $rearrangedMiddlewares ? 'typo3/cms-frontend/base-redirect-resolver' : 'typo3/cms-frontend/page-resolver',
             ],
             'after' => [
-                'typo3/cms-frontend/authentication',
-                'typo3/cms-frontend/static-route-resolver',
+                $rearrangedMiddlewares ? 'typo3/cms-frontend/authentication' : 'typo3/cms-frontend/static-route-resolver',
             ],
         ],
     ],