Skip to content

Commit

Permalink
[BUGFIX] Avoid NullSite in Request object setup in RedirectService
Browse files Browse the repository at this point in the history
Redirects can match even if no SiteConfiguration could
be determined for the current request and a `NullSite`
has been added as request attribute. In this case, the
`RedirectService` already resolves a SiteConfiguration
for the matched redirect.

Bootstrapping a  `TypoScriptFrontendController` is done
using the resolved SiteConfiguration, still using the
NullSite in the request for id determination and loading
TypoScript.

In cases where no real `sys_template` records exists,
for example when `b13/bolt` is used to provide fake
rows, it is important to avoid NullSite.

This change uses the redirect target based resolved
site in case the request does not contain a valid
site object. Prepared test from #103555 is enabled
now to guard this case for the future.

Note: TYPO3 v13 recieved quite some refactoring in
the Middleware, TSFE and TypoScript loading order
a long with a factory and fixed this already. This
is a simple solution for TYPO3 v12.

Resolves: #103395
Related: #103555
Releases: 12.4
Change-Id: If3d3003c8af1799e19937328c00fedb7b32562c7
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/83701
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: core-ci <typo3@b13.com>
Tested-by: Andreas Kienast <a.fernandez@scripting-base.de>
Reviewed-by: Andreas Kienast <a.fernandez@scripting-base.de>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Stefan Bürk <stefan@buerk.tech>
Reviewed-by: Stefan Bürk <stefan@buerk.tech>
  • Loading branch information
sbuerk committed Apr 8, 2024
1 parent 20a8584 commit 1a1ff71
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
14 changes: 14 additions & 0 deletions typo3/sysext/redirects/Classes/Service/RedirectService.php
Expand Up @@ -387,6 +387,20 @@ protected function getUriFromCustomLinkDetails(array $redirectRecord, ?SiteInter
*/
protected function bootFrontendController(SiteInterface $site, array $queryParams, ServerRequestInterface $originalRequest): TypoScriptFrontendController
{
// Request without a matching site configuration can still have matching redirects and the $site already
// contains a resolved site based on the target or a default one. If the request site is a NullSite, we
// replace it here to ensure proper TypoScript loading, which is essential if no sys_template record exist
// and extension like `b13/bolt` providing fake template rows. Without this, they could work properly.
//
// There is currently not a better way to pass this down, and is fixed in TYPO3 v13 due to a more extensive
// rework and implementation of a TypoScript factory already.
//
// See https://forge.typo3.org/issues/103395
if ($originalRequest->getAttribute('site') instanceof NullSite) {
$originalRequest = $originalRequest
->withAttribute('site', $site)
->withAttribute('siteLanguage', $site->getDefaultLanguage());
}
$controller = GeneralUtility::makeInstance(
TypoScriptFrontendController::class,
GeneralUtility::makeInstance(Context::class),
Expand Down
Expand Up @@ -996,15 +996,14 @@ public static function sourceHostNotNotContainedInAnySiteConfigRedirectIsRedirec
'expectedRedirectLocationUri' => 'https://acme.com/page2',
];
// Regression test for https://forge.typo3.org/issues/103395
// @todo Enable again in bugfix change.
// yield 'non-configured source_host with site root target without typoscript using T3 LinkHandler syntax' => [
// 'request' => new InternalRequest('https://non-configured.domain.tld/redirect-to-pid1'),
// 'rootPageTypoScriptFiles' => ['setup' => ['EXT:redirects/Tests/Functional/Service/Fixtures/Redirects.typoscript']],
// 'useTestBolt' => true,
// 'expectedRedirectStatusCode' => 301,
// 'expectedRedirectUid' => 1,
// 'expectedRedirectLocationUri' => 'https://acme.com/',
// ];
yield 'non-configured source_host with site root target without typoscript using T3 LinkHandler syntax' => [
'request' => new InternalRequest('https://non-configured.domain.tld/redirect-to-pid1'),
'rootPageTypoScriptFiles' => ['setup' => ['EXT:redirects/Tests/Functional/Service/Fixtures/Redirects.typoscript']],
'useTestBolt' => true,
'expectedRedirectStatusCode' => 301,
'expectedRedirectUid' => 1,
'expectedRedirectLocationUri' => 'https://acme.com/',
];
}

/**
Expand Down

0 comments on commit 1a1ff71

Please sign in to comment.