94161[BUGFIX] Ensure Site's CacheTag identifier is valid
Commit message
Review
-
Code review CR -2
- Garvin Hicking -2
-
Verified V 0
- core-ci +1 CI
Issues 2
Files 1
Review log 2728
Show 23 earlier messages
-
Garvin Hicking uploaded patch set 1 05/26/26, 17:22
-
Garvin Hicking commented on patch set 1 05/26/26, 17:25
I'm not too happy about these things: - due to the middleware and no involved service class subject, this isn't (pretty|easy) to test? - I don't like to introduce a new regexp to replace what's contained in PATTERN_TAG. However I don't want to obfuscate the interface by adding a new regular expression rule in there. - Not throwing the exception and internally scrubbing a cache tag would have serious side effects, as a lot of the current interface and chain really depends on the sanity checks. If they suddenly all pass due to "automatic conversion", that would be a substantial change I'm not willing to do just for this fix. -
core-ci voted on patch set 1 V +1 05/26/26, 17:30 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/102444
-
Helmut Hummel commented on patch set 1 05/26/26, 17:58
Reply
Adding on top: Scrubbing the cache identifier defeats the initial purpose of "easily flushing cache by site identifier" because the tag will NOT be the site identifier when the site identifier contains "invalid" characters. In such case, it will be counter intuitive to flush the cache for a site. -
Garvin Hicking commented on patch set 1 05/26/26, 18:11
Reply
Good comment, indeed. Well - we could catch the exception, and then just not add a cache tag? Maybe even log something like "your site identifier is suboptional, please rename your site - no cache tag was added"? The more I think about it, the less clear a proper fix is to me. -
Oliver Hader commented on patch set 1 05/26/26, 18:56
Reply
We also might introduce `CacheTag::sanitize('my.🫶site.com!?"""')` which uses the `INVALID_PATTERN_TAG = '/[^a-zA-Z0-9_%\\-&]/' and enforces the length range 1-250 chars. Or as last resort: Revert the change that introduced this behavior. -
Oliver Hader commented on patch set 1 05/26/26, 18:58
Reply
In case the cache tag shall exactly related to the site identifier, only encoding (hex or base64) would help. -
Garvin Hicking commented on patch set 1 05/26/26, 19:26
Reply
My claude suggested the same ::sanitize method. However the regexp is on the interface and not the class so IMO that barely makes it better. Helmuts concern coukd be addressed with a ReST file to mention the scrubbing, and that extra chars must be removed. Or we can introduce a "Site->getSanitizedIdentifier()" method to make it more programmatic. Honestly I'm thinking a revert might be better so we can sort it out properly. Maybe denying these chars in the identifier already could be better (breakinf; v15 only) for the future. Or allowing dots in the cacheTag? -
Helmut Hummel commented on patch set 1 05/27/26, 10:25
Reply Unresolved
Use pageCache instance to check for valid tag by using the pageCache->isValidTag() API and log a warning if it isn't valid. Then: Option 1: do not add a cache tag Option 2: scrub cache tag an log the scrubbed cache tag and use the scrubbed cache tag For scrubbing I suggest to not remove invalid chars but replace it with a defined one. site_awm-stadt-muenster-de is imho better to read than site_awmstadt-muensterde I personally would prefer Option 1, as it is basically reverting the change for site identifiers, that violate the tag rules. > My claude suggested the same ::sanitize method. However the regexp is on the interface and not the class so IMO that barely makes it better. If the isValidTag() method is on the cache frontend (interface), then a sanitizeTag() would belong there as well. > Site->getSanitizedIdentifier() This is a nogo for me. It mixes the site API with cache API -
Oliver Hader commented on patch set 1 05/27/26, 11:22
That's my alternative suggestion, using a factory method to reliably assign the cache tag. If the tag name contains invalid chars, those are hashed. → https://review.typo3.org/c/Packages/TYPO3.CMS/+/94166 -
Garvin Hicking commented on patch set 1 05/27/26, 15:54
Reply
@oliver.hader@typo3.org I think the hashing will make the flusbytag not usable. To me Helmuts idea sounds promising - I can rework the patch if you agree -
Oliver Hader commented on patch set 1 05/27/26, 20:50
Reply Unresolved
I added a test for `flushByTag` using `CacheTag` at https://review.typo3.org/c/Packages/TYPO3.CMS/+/94166/2/typo3/sysext/core/Tests/Functional/Cache/Backend/Typo3DatabaseBackendTest.php However, I see the point with delegating the validation to `FrontendInterface::isValidTag()`. I'd be fine with using Helmut's suggestion from above as well (drop invalid cache tag, and log a warning instead of throwing the exception). -
Christian Kuhn commented on patch set 1 05/27/26, 21:51
Unresolved
Thanks for quick action on this issue! Related: When editing sites in BE, formEngine TCA for 'identifier' is configured eval=>'lower, alphanum_x, trim' (a-z,0-9,_,-) -> no dot allowed. JS removes the dot when adding a site and changing 'identifier', and it is done php-side in SiteConfigurationController->validateAndProcessValue() (triggered on saveAction), too. This means the issue can not be triggered when editing sites in BE. However, when manually creating a site configuration directory that contains a dot, it is "accepted". I agree we need to fix the issue with one of the proposed solutions. As a second step (new issue?) we may also want to look if we could reflect invalid 'identifier' situations in a better way in the BE or logging, or maybe even actively throwing early, to catch cases when "invalid" site identifiers have been crafted/deployed by direct directory/file manipulation, not using the interface. Good idea? Alternatively, we could review the sanitation to see if we could allow "more" in BE validation, even though we may not want to end up with emoticons in directory names ... -
Benjamin Franzke commented on patch set 1 05/28/26, 06:44
Hey, I'd like to point to another option: I'd vote for reverting the original patch: > https://review.typo3.org/c/Packages/TYPO3.CMS/+/94024 The change has several flaws: It actually backported a new FEATURE into a priority bugfix release. The feature added a cache tag, but never cleared it. That means it is unused in core and "only" used for extensions that might want to flush based on sites. Also the issue https://forge.typo3.org/issues/109792 basically explained this feature request as a desirement for third party code: > To ease the clearing of cache of a single site, including the resolved site as a cachetag to `frontend.cache.collector` allows a integrator to use > `$this->cache->flushByTag($siteIdentifier)` This usecase – an extension wants to add a new cache tag – can be implemented thanks to the delayed architecture that `CacheDataCollector` implements. Cache entries are enqueued, but persistence is delayed into the core-middleware-postprocessing. That means any frontend middleware can process and extend entries in `CacheDataCollector` and could add a site identifier on it's own. For this reason I'd suggest to revert since: * There are existing mechanisms to solve the "task" * Invalid feature backport to v13 * We avoid to introduce new infrastructure (like a cache-tag-sanitizer) to cope with a patch that is – strictly seen – not really needed. -
Garvin Hicking commented on patch set 1 05/28/26, 07:01
Reply
I'm also coming to terms with needing to revert this. Would you be able to share a possible middleware implementation in the issue or commit message of a revert, I think that would help a lot to foster understanding. I do think though it would be helpful to introduce this cache tag in v15, and then take the chance to also have a breaking change to deny special characters in site config identifiers that Lolli pointed out. -
Oliver Hader commented on patch set 1 05/28/26, 07:07
Reply
Revert is fine for me as well (I mentioned that earlier already as "last resort"). -
Benjamin Franzke commented on patch set 1 05/28/26, 07:10
Reply
ack, sorry, I overread that -
Helmut Hummel commented on patch set 1 05/28/26, 07:25
Reply
revert is of course also fine for me. As Christian pointed out, we should consider logging warnings (depreciations?) at some point when invalid site identifiers are used. -
Benjamin Franzke commented on patch set 1 05/28/26, 07:31
Reply
> Would you be able to share a possible middleware implementation *Classes/Middleware/SiteCacheTag.php* ``` <?php declare(strict_types=1); namespace Bnf\MySite\Middleware; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Server\MiddlewareInterface; use Psr\Http\Server\RequestHandlerInterface; use TYPO3\CMS\Core\Cache\CacheDataCollector; use TYPO3\CMS\Core\Cache\CacheTag; use TYPO3\CMS\Core\Site\Entity\SiteInterface; final readonly class SiteCacheTag implements MiddlewareInterface { public function process( ServerRequestInterface $request, RequestHandlerInterface $handler ): ResponseInterface { $response = $handler->handle($request); $cacheDataCollector = $this->getCacheDataCollector($request); $site = $this->getSite($request); if ($site !== null && count($cacheDataCollector?->getCacheEntries()) > 0) { $cacheDataCollector->addCacheTags( new CacheTag('site_' . $site->getIdentifier()) ); } return $response; } private function getCacheDataCollector( ServerRequestInterface $request ): ?CacheDataCollector { return $request->getAttribute('frontend.cache.collector'); } private function getSite( ServerRequestInterface $request ): ?SiteInterface { return $request->getAttribute('site'); } } ``` *Configuration/RequestMiddlewares.php* ``` <?php return [ 'frontend' => [ 'bnf/my-site/site-cache-tag' => [ 'target' => \Bnf\MySite\Middleware\SiteCacheTag::class, 'after' => [ 'typo3/cms-frontend/site', ], ], ], ]; ``` -
Benjamin Franzke commented on patch set 1 05/28/26, 07:44
Reply Unresolved
Even easier via TypoScript (could be added as global if *really* needed or per site): ``` page = PAGE page { 1779954161 = COA 1779954161.stdWrap.addPageCacheTags = site_{site:identifier} 1779954161.stdWrap.addPageCacheTags.insertData = 1 } ``` -
Soren Malling commented on patch set 1 06/04/26, 08:16
Unresolved
The regexp doing stuff to the site identifier defeats the purpose of using the site identifier directly other places. I see the need for a valid cache identifier, but I think this is not the right place to solve it -
Oliver Hader commented on patch set 1 06/04/26, 10:56
→ the original change has been reverted with https://review.typo3.org/c/Packages/TYPO3.CMS/+/94177 -
Oliver Hader wrote 06/04/26, 10:57
Removed cc Oliver Hader. -
Garvin Hicking commented on patch set 1 CR -2 06/04/26, 11:28
Reply
I'll leave this open and see what I can mangle this into for a better v15 approach, limiting the siteIdentifier to a dotless string, so that then the original patch can be restored there and be breaking. -
Garvin Hicking marked it work in progress 06/04/26, 17:18
-
Christian Kuhn commented on patch set 1 06/09/26, 23:06
Reply Unresolved
tbh, i'm not sure if that is really worth the trouble: when you deploy sites, it can very well happen there is a dot in it, since its kinda natural having full domain names as folder names, too. it's probably hard to avoid that when site configs are deployed/shipped. i guess best we could do would be a red error in the sites module, plus maybe an exception in FE (which may be considered breaking). we could also see if relaxing the dot restriction on cache identifiers is an option (and adapt the UI to allow them), but that probably needs thoughts and tests on the cache layer to not introduce path traversal for file based caches, and if then a third party cache does funny stuff, we risk introducing sec issues in there through a core change in this area. anyway, issue #109876 has been resolved by reverting the change. we can keep this patch pending to potentially pick it up again, but it should be assigned a fresh issue, i suppose. -
Soren Malling commented on patch set 1 06/10/26, 08:38
No hard feelings from my side to abandon this change totally. Clearly there is a case of naming site configs that I didn't think about, so this is not something we just implement. And, it's a nice to have and can be done by integrators themself if really needed - or be a separate extension with a middleware 👌 -
Garvin Hicking abandoned the change 08/10/26, 08:13