Review main Merged

95878[TASK] Use PSR-14 event for page URI cache hash calculation

Benni Mack CR +2 V +2 Normal +181 −32 updated 09/23/26, 12:35

Commit message

Core\Routing\PageRouter, which lives in EXT:core, calculated the "cHash"
query argument for generated page links itself, using
Frontend\Page\CacheHashCalculator and CacheHashConfiguration. This
forces a hard dependency of EXT:core on EXT:frontend, even though cHash
is exclusively a frontend caching concern: it prevents cache poisoning
of a page in the frontend page cache.

The calculation is moved to the existing PSR-14 event
Core\Routing\Event\AfterPageUriGeneratedEvent, which now also carries
the page ID and PageArguments of the generated link via getPageId() and
getPageArguments(). EXT:core no longer calculates a cHash; it only keeps
an incoming "cHash" argument out of URL generation. EXT:frontend
registers the listener
Frontend\EventListener\CalculatePageUriCacheHashEventListener, which
calculates the cHash from the event's PageArguments and appends it to
the query, reproducing the exact calculation PageRouter did before.
Without that listener, generated URIs carry no cHash.

CacheHashCalculator is now resolved as a shared container service via
constructor injection, instead of a fresh instance PageRouter built with
makeInstance() on every call. This matches PageArgumentValidator, which
already injects it, so URL generation and incoming request validation
now use the same instance, and
$GLOBALS['TYPO3_CONF_VARS']['FE']['cacheHash'] is read once when that
instance is created.

Review

  • Code review CR +2 Done
    • Benni Mack +2
    • Oli Bartsch +1
    • Wouter Wolters +1
  • Verified V +2 Done
    • Benni Mack +2
    • Oli Bartsch +1
    • Wouter Wolters +1
    • core-ci +1 CI

Issues 1

Files 4

Review log 2029

Show 24 earlier messages
  1. Benni Mack uploaded patch set 1 09/16/26, 14:02

  2. Benni Mack uploaded patch set 2 09/16/26, 14:07

  3. core-ci voted on patch set 1 V +1 09/16/26, 14:15 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/108692

  4. core-ci voted on patch set 2 V -1 09/16/26, 14:17 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/108694

  1. Benni Mack uploaded patch set 3 V -1 09/16/26, 14:25

  2. Benni Mack uploaded patch set 4 09/16/26, 14:30

  3. Benni Mack marked it ready for review 09/16/26, 14:30

  4. Benni Mack updated the commit message in patch set 5 09/16/26, 14:33

  5. core-ci voted on patch set 3 V -1 09/16/26, 14:33 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/108697

  6. core-ci voted on patch set 4 V -1 09/16/26, 14:38 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/108698

  7. core-ci voted on patch set 5 V -1 09/16/26, 14:41 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/108699

  8. Benni Mack uploaded patch set 6 V -1 09/16/26, 16:03

  9. core-ci voted on patch set 6 V +1 09/16/26, 16:11 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/108702

  10. Benni Mack marked it ready for review 09/16/26, 16:35

  11. Wouter Wolters voted on patch set 6 CR +1 09/16/26, 16:45

  12. Wouter Wolters voted on patch set 6 V +1 09/16/26, 16:54

  13. Jochen Roth voted on patch set 6 CR +1 V +1 09/17/26, 21:24

  14. Oli Bartsch voted on patch set 6 V -1 09/17/26, 21:50

  15. Oli Bartsch commented on patch set 6 09/17/26, 22:10

    Worth adding CacheHashCalculator is now a shared container service instead of a per-PageRouter makeInstance(), so GLOBALS['TYPO3_CONF_VARS']['FE']['cacheHash'] is frozen at container build time. That matches PageArgumentValidator, which already injects it, so generation and validation now share one instance. An improvement, but a behaviour change that could be mentioned.

    PageRouter.php:320

    This is an unrelated behaviour change, and it regresses generated URLs. generateUri(1000, ['key' => 'value', 'cHash' => 'staleincoming']) before: https://oli.it/?key=value&cHash=00f30ec5… after: https://oli.it/?cHash=00f30ec5…&key=value The hash value is correct in both cases, but the URL string differs. Stripping it here, before the enhancers and route generation run, is also strictly safer than letting it pollute $originalParameters, which is handed to enhanceForGeneration()/decorateForGeneration(), to RouteSorter, and to $event->getParameters(). I suggest to keep the unset and the listener only ever has to,append.

    PageRouter.php:386

    With the null check above, $matchedRoute is now always true. Either drop it or keep the previous `$matchedRoute && $pageRouteResult &&` form.

    CalculatePageUriCacheHashEventListener.php:25

    This advice produces links with an invalid cHash, so please remove or rewrite it. The hash is computed from $event->getPageArguments()->getDynamicArguments(), not from the URI query. A listener that runs before this one and adds a query argument is therefore never covered by the hash. Running after this listener fails in exactly the same way, for the same reason. So today there is no way at all for a listener to add a cacheable query argument to a generated page URI. Either drop the paragraph, or hash the URI's query instead of the PageArguments. The second option changes the hash for enhanced routes though, so it needs its own careful look.

    CalculatePageUriCacheHashEventListener.php:52

    The parse_str() / http_build_query() round-trip is lossy. parse_str() rewrites "." and " " in top-level keys to "_" and collapses duplicate keys. Inside PageRouter's own flow this is same as today. There is already a parse_str(), so no regression from this patch, but you now put a second round-trip on whatever URI a preceding listener produced, and silently mangle it. So I think this is avoidable. Build the query from $event->getPageArguments()->getQueryArguments() plus the cHash, exactly as PageRouter did before, instead of re-parsing the URI. Combined with keeping the unset() in PageRouter, the listener then only appends and never rewrites.

    CalculatePageUriCacheHashEventListener.php:60

    setUri() is called unconditionally, so every URI with dynamic arguments goes through the round-trip above even when nothing changes. Worth an early return when the computed query equals the existing one.
  16. Benni Mack uploaded patch set 7 CR +1 V +1 09/22/26, 15:16

  17. Benni Mack commented on patch set 7 09/22/26, 15:17

    Reply

    Done

    PageRouter.php:320 Reply

    Done

    PageRouter.php:386 Reply

    Done

    CalculatePageUriCacheHashEventListener.php:25 Reply

    Done

    CalculatePageUriCacheHashEventListener.php:52 Reply

    Done

    CalculatePageUriCacheHashEventListener.php:60 Reply

    Done
  18. core-ci voted on patch set 7 V -1 09/22/26, 15:29 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/108998

  19. core-ci voted on patch set 7 V +1 09/22/26, 17:06 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/108998

  20. Oli Bartsch updated the commit message in patch set 8 V +1 09/23/26, 08:39

  21. Oli Bartsch voted on patch set 8 CR +1 V +1 09/23/26, 08:39

  22. core-ci voted on patch set 8 V +1 09/23/26, 08:47 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/109036

  23. Wouter Wolters voted on patch set 8 CR +1 V +1 09/23/26, 12:33

  24. Benni Mack voted on patch set 8 CR +2 V +2 09/23/26, 12:35

  25. Benni Mack merged patch set 9 09/23/26, 12:35