Skip to content

Commit 6742dab

Browse files
committed
[!!!][TASK] Avoid global content link rewriting in FE
The frontend rendering contains a method that receives the fully generated Response body content to apply a global search and replace string operation in order to fix links to included assets. This was always a bad idea and is now finally obsolete with the new system resource API: The system can expect that links to resources are final when they are created by some sub system. The patch removes the logic along with a TYPO3_CONF_VARS setting that allowed exending this brittle magic. Resolves: #108114 Related: #107537 Releases: main Change-Id: Ib67aad945475a93e774338c621df6a5641e5f36d Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/91656 Tested-by: core-ci <typo3@b13.com> Reviewed-by: Lina Wolf <112@linawolf.de> Reviewed-by: Helmut Hummel <typo3@helhum.io> Tested-by: Christian Kuhn <lolli@schwarzbu.ch> Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch> Tested-by: Lina Wolf <112@linawolf.de> Tested-by: Helmut Hummel <typo3@helhum.io>
1 parent d231c74 commit 6742dab

File tree

5 files changed

+59
-41
lines changed

5 files changed

+59
-41
lines changed

typo3/sysext/core/Configuration/DefaultConfiguration.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1553,7 +1553,6 @@
15531553
'defaultTypoScript_constants.' => [], // Lines of TS to include after a static template with the uid = the index in the array (Constants)
15541554
'defaultTypoScript_setup' => '',
15551555
'defaultTypoScript_setup.' => [], // Lines of TS to include after a static template with the uid = the index in the array (Setup)
1556-
'additionalAbsRefPrefixDirectories' => '',
15571556
'enable_mount_pids' => true,
15581557
'hidePagesIfNotTranslatedByDefault' => false,
15591558
'eID_include' => [], // Array of key/value pairs where key is "tx_[ext]_[optional suffix]" and value is relative filename of class to include. Key is used as "?eID=" for \TYPO3\CMS\Frontend\Http\RequestHandlerRequestHandler to include the code file which renders the page from that point. (Useful for functionality that requires a low initialization footprint, eg. frontend ajax applications)

typo3/sysext/core/Configuration/DefaultConfigurationDescription.yaml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -520,9 +520,6 @@ FE:
520520
type: multiline
521521
description: 'Enter lines of default TypoScript, setup-field.'
522522
compareValuesWithCurrentConfiguration: false
523-
additionalAbsRefPrefixDirectories:
524-
type: text
525-
description: 'Enter additional directories to be prepended with absRefPrefix. Directories must be comma-separated. TYPO3 already prepends the following directories: typo3/, typo3temp/, typo3conf/ext/ and all local storages'
526523
enable_mount_pids:
527524
type: bool
528525
description: 'If enabled, the mount_pid feature allowing ''symlinks'' in the page tree (for frontend operation) is allowed.'
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
.. include:: /Includes.rst.txt
2+
3+
.. _breaking-108114-1763085569:
4+
5+
==================================================================
6+
Breaking: #108114 - Global frontend content link prefixing removed
7+
==================================================================
8+
9+
See :issue:`108114`
10+
11+
Description
12+
===========
13+
14+
The frontend rendering contained logic that searched for links to resources within
15+
the generated Response content to globally replace them with the configured URL
16+
prefix (TypoScript :typoscript:`config.absRefPrefix`).
17+
18+
This solution has always been brittle and has finally been obsoleted with the
19+
introduction of the :ref:`system resource API <feature-107537-1759136314>`.
20+
21+
The global search and replace code has been removed which obsoletes setting
22+
:php:`$GLOBALS['TYPO3_CONF_VARS']['FE']['additionalAbsRefPrefixDirectories']`
23+
as well.
24+
25+
26+
Impact
27+
======
28+
29+
Generated content can no longer expect their links to resources being globally
30+
"fixed". They need to create the final URL themself.
31+
32+
The obsolete :php:`$GLOBALS['TYPO3_CONF_VARS']['FE']['additionalAbsRefPrefixDirectories']`
33+
will be automatically removed from :file:`settings.php` after upgrading to
34+
TYPO3 v14 and accessing the install tool.
35+
36+
37+
Affected installations
38+
======================
39+
40+
The system resource API is wired into the system in a way that extensions usually
41+
create proper links automatically as long as the provided core API is used.
42+
43+
Instances with extensions that hard code link generation may be affected, though.
44+
45+
46+
Migration
47+
=========
48+
49+
Instances should check the rendered frontend for broken links after upgrading
50+
to TYPO3 v14 and substitute hard coded link generation with proper API calls,
51+
for instance based on the various URL, URI and asset related Fluid view helpers.
52+
53+
This change heavily depends on the specific extension code. There is no
54+
good advise for extension developers to catch all possible cases.
55+
56+
57+
.. index:: Frontend, PHP-API, NotScanned, ext:frontend

typo3/sysext/frontend/Classes/Controller/TypoScriptFrontendController.php

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -25,21 +25,18 @@
2525
use TYPO3\CMS\Core\Cache\CacheTag;
2626
use TYPO3\CMS\Core\Cache\Frontend\FrontendInterface;
2727
use TYPO3\CMS\Core\Context\Context;
28-
use TYPO3\CMS\Core\Core\Environment;
2928
use TYPO3\CMS\Core\Database\ConnectionPool;
3029
use TYPO3\CMS\Core\Page\AssetCollector;
3130
use TYPO3\CMS\Core\Page\PageRenderer;
3231
use TYPO3\CMS\Core\PageTitle\PageTitleProviderManager;
3332
use TYPO3\CMS\Core\TimeTracker\TimeTracker;
3433
use TYPO3\CMS\Core\Utility\GeneralUtility;
35-
use TYPO3\CMS\Core\Utility\PathUtility;
3634
use TYPO3\CMS\Frontend\Authentication\FrontendBackendUserAuthentication;
3735
use TYPO3\CMS\Frontend\Cache\CacheLifetimeCalculator;
3836
use TYPO3\CMS\Frontend\Cache\MetaDataState;
3937
use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
4038
use TYPO3\CMS\Frontend\Event\AfterCacheableContentIsGeneratedEvent;
4139
use TYPO3\CMS\Frontend\Event\AfterCachedPageIsPersistedEvent;
42-
use TYPO3\CMS\Frontend\Page\FrontendUrlPrefix;
4340

4441
/**
4542
* Main controller class of the TypoScript based frontend.
@@ -175,8 +172,6 @@ protected function setSysLastChanged(ServerRequestInterface $request): void
175172
*/
176173
public function generatePage_postProcessing(ServerRequestInterface $request, string $content): string
177174
{
178-
$absRefPrefix = GeneralUtility::makeInstance(FrontendUrlPrefix::class)->getUrlPrefix($request);
179-
$content = $this->setAbsRefPrefixInContent($content, $absRefPrefix);
180175
$eventDispatcher = GeneralUtility::makeInstance(EventDispatcherInterface::class);
181176
$usePageCache = $request->getAttribute('frontend.cache.instruction')->isCachingAllowed();
182177
$cacheDataCollector = $request->getAttribute('frontend.cache.collector');
@@ -318,8 +313,6 @@ public function INTincScript(ServerRequestInterface $request, string $content):
318313
$content = $pageRenderer->renderJavaScriptAndCssForProcessingOfUncachedContentObjects($content, $pageParts->getPageRendererSubstitutionHash());
319314
// Replace again, because header and footer data and page renderer replacements may introduce additional placeholders (see #44825)
320315
$content = $this->recursivelyReplaceIntPlaceholdersInContent($request, $content);
321-
$absRefPrefix = GeneralUtility::makeInstance(FrontendUrlPrefix::class)->getUrlPrefix($request);
322-
$content = $this->setAbsRefPrefixInContent($content, $absRefPrefix);
323316
$this->getTimeTracker()->pull();
324317
return $content;
325318
}
@@ -546,36 +539,6 @@ public function isStaticCacheble(ServerRequestInterface $request): bool
546539
return $isCachingAllowed && !$pageParts->hasNotCachedContentElements() && !$this->context->getAspect('frontend.user')->isUserOrGroupSet();
547540
}
548541

549-
/**
550-
* Converts relative paths in the HTML source to absolute paths for fileadmin/, typo3conf/ext/ and media/ folders.
551-
*/
552-
protected function setAbsRefPrefixInContent(string $content, string $absRefPrefix): string
553-
{
554-
if ($absRefPrefix === '') {
555-
return $content;
556-
}
557-
$encodedAbsRefPrefix = htmlspecialchars($absRefPrefix, ENT_QUOTES | ENT_HTML5);
558-
$search = [
559-
'"_assets/',
560-
'"typo3temp/',
561-
'"' . PathUtility::stripPathSitePrefix(Environment::getExtensionsPath()) . '/',
562-
'"' . PathUtility::stripPathSitePrefix(Environment::getFrameworkBasePath()) . '/',
563-
];
564-
$replace = [
565-
'"' . $encodedAbsRefPrefix . '_assets/',
566-
'"' . $encodedAbsRefPrefix . 'typo3temp/',
567-
'"' . $encodedAbsRefPrefix . PathUtility::stripPathSitePrefix(Environment::getExtensionsPath()) . '/',
568-
'"' . $encodedAbsRefPrefix . PathUtility::stripPathSitePrefix(Environment::getFrameworkBasePath()) . '/',
569-
];
570-
// Process additional directories
571-
$directories = GeneralUtility::trimExplode(',', $GLOBALS['TYPO3_CONF_VARS']['FE']['additionalAbsRefPrefixDirectories'], true);
572-
foreach ($directories as $directory) {
573-
$search[] = '"' . $directory;
574-
$replace[] = '"' . $encodedAbsRefPrefix . $directory;
575-
}
576-
return str_replace($search, $replace, $content);
577-
}
578-
579542
/**
580543
* Get the cache timeout for the current page.
581544
*/

typo3/sysext/install/Classes/Service/SilentConfigurationUpgradeService.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,8 @@ class SilentConfigurationUpgradeService
213213
'BE/compressionLevel',
214214
// #108055
215215
'FE/compressionLevel',
216+
// #108114
217+
'FE/additionalAbsRefPrefixDirectories',
216218
];
217219

218220
public function __construct(private readonly ConfigurationManager $configurationManager) {}

0 commit comments

Comments
 (0)