Review main Abandoned

85215[BUGFIX] Ignore TypoScript linkVars configuration for Core arguments

Garvin Hicking CR 0 V 0 Normal +52 −11 updated 03/28/25, 12:28

Commit message

TYPO3 internally handles several specific URI arguments:

* L
* id
* no_cache
* cHash
* MP

With the TypoScript `config.linkVars` configuration, these
parameters could be set to a more specific (or broader) range
than the core internally handles.

This could lead to invalid page cache generation with unresolvable
languages or pages.

The popular EXT:bootstrap_package makes use of this configuration
option, setting "L(int)" which accepts also invalid languages
to create pages. Because other sitepackages may borrow from
that, it can be assumed that many pages are affected by
this misconfiguration.

A symptom would be, that if crawlers request "L" parameters allowed
via TypoScript configuration (for example "999"), but not set
in site configurations, the page cache could be poisoned with invalid
(empty) link targets or descriptors.

This patch creates an "ignore list" of the listed arguments,
and skips any interpretation of them through the linkVars handling,
so that only further core calculations are applied to these
parameters.

Please note that with #86057 using `config.linkVars` with a "L" setting
was already officially discouraged. The use of URI parameter "type" is
intentionally still allowed to be restricted via TypoScript.

Review

  • Code review CR 0
  • Verified V 0

Issues 2

Files 3

Review log 3342

Show 1317 earlier messages
  1. Garvin Hicking uploaded patch set 1 07/10/24, 13:00

  2. core-ci voted on patch set 1 V -1 07/10/24, 13:07 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/61315

  3. Garvin Hicking uploaded patch set 2 V -1 07/10/24, 13:14

  4. core-ci voted on patch set 2 V +1 07/10/24, 13:22 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/61317

  5. Lina Wolf commented on patch set 2 CR +1 07/10/24, 13:23

    Code looks good to me, didnt try it out yet
  6. Stefan Froemken commented on patch set 2 07/10/24, 13:41

    He he...Happy coding in good old tsref.xml

    LinkVarsCalculator.php:80

    I would prefer move it to top in this foreach as far as possible. Why calling preg_match on something which may be invalid?

    LinkVarsCalculatorTest.php:47

    For empty array I prefer `[]` without linebreak. Same in line 53
  7. Garvin Hicking uploaded patch set 3 CR +1 V +1 07/10/24, 14:13

    Apply code review suggestions
  8. core-ci voted on patch set 3 V -1 07/10/24, 14:18 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/61322

  9. Stefan Froemken commented on patch set 3 CR +1 07/10/24, 14:18

    LinkVarsCalculator.php:80 Reply

    Done

    LinkVarsCalculatorTest.php:47 Reply

    Done
  10. Stefan Froemken voted on patch set 3 CR 0 07/10/24, 14:19

  11. Stefan Froemken commented on patch set 3 07/10/24, 14:25

    LinkVarsCalculator.php:68

    Sorry. I haven't seen that `$linkVar=L(12)` will be changed to `$linkVar=L`. Please move it behind preg_match again. Sorry...
  12. Garvin Hicking uploaded patch set 4 V -1 07/10/24, 14:44

  13. core-ci voted on patch set 4 V +1 07/10/24, 14:49 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/61326

  14. Garvin Hicking commented on patch set 4 07/10/24, 14:52

    LinkVarsCalculator.php:68 Reply

    Funny thing, and this helped to find out more. It's allowed to indicate nested arrays: config.linkVars = L|subkey(int) to allow a URL variable like "L[subkey]=4711". So I think we actually need to test on $rootKey here, otherwise parameters would still allow to be added as arrays. Added one more test case for this. Thank you!
  15. Stefan Froemken voted on patch set 4 CR +1 07/11/24, 19:31

  16. Benni Mack commented on patch set 4 07/11/24, 21:02

    LinkVarsCalculator.php:66

    feel free to make this a instance property ($this->coreArguments)
  17. Christian Kuhn commented on patch set 4 07/11/24, 22:13

    LinkVarsCalculator.php:66 Reply

    no property, but a constant, please. this class should stay a stateless service!
  1. Garvin Hicking uploaded patch set 5 CR +1 V +1 07/12/24, 08:13

    Use constant
  2. Garvin Hicking commented on patch set 5 07/12/24, 08:15

    LinkVarsCalculator.php:66 Reply

    Implemented it like this: public const coreArgumentsToSkip = ['L', 'id', 'no_cache', 'cHash', 'MP']; (cannot use "array" type hint due to PHP 8.3 requirement) I made it public by intent so maybe other code could use this list somehow? But I can happily make it protected too, if you want.
  3. core-ci voted on patch set 5 V +1 07/12/24, 08:18 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/61463

  4. Benni Mack commented on patch set 5 07/15/24, 09:12

    LinkVarsCalculator.php:66 Reply

    protected.
  5. Tymoteusz Motylewski commented on patch set 5 07/15/24, 10:25

    LinkVarsCalculator.php:66

    is allowed because restricting might have a benefit? I dont get it.
  6. Garvin Hicking uploaded patch set 6 V +1 07/15/24, 12:19

  7. Garvin Hicking commented on patch set 6 07/15/24, 12:22

    LinkVarsCalculator.php:66 Reply

    done

    LinkVarsCalculator.php:66 Reply

    Appending "?type=xxx" to a URL to request a specific type is something that you may want to restrict through a LinkVars configuration. So doing something like: config.linkVars = type(garvin|tymo) should be allowed. This is not the case with other URL vars like id, L, no_cache, cHash because those are nowadays so tightly coupled to core internals that you shouldn't tamper with that through TypoScript config, or it will lead to the side-effects that SiteMatchers, LanguageMatchers, Cache-Matchers etc. will fail. Since the "type"-matching is pretty open to extensions, this "core" variable IMO does not need to be tightly controlled like the others. If I misunderstood something here, please let me know. I'm also open to other thoughts about this, I only tried to address the bug report with a possible fix that looks valid to me.
  8. core-ci voted on patch set 6 V +1 07/15/24, 12:27 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/61581

  9. Garvin Hicking commented on patch set 6 07/17/24, 19:07

    LinkVarsCalculator.php:66 Reply

    Done
  10. Lina Wolf commented on patch set 6 08/02/24, 08:19

    LinkVarsCalculator.php:66 Reply

    I agree with Garvins position here
  11. Garvin Hicking commented on patch set 6 08/14/24, 23:28

    LinkVarsCalculator.php:66 Reply

    Adding Tymoteusz' Feedback here which didn't get through and he sent me via slack: Your explanation Garvin totally makes sense. It's just that this todo comment is hard to grasp without all this context. What would help eg: „type” -> „type” url parameter Also the phrases „allowed to be set” and „restrict” could be improved as we are not setting the „type” parameter value in typoscript, but rather configuring the restriction or keep it possible to configure allowe values in TS. tldr my comment was only about making the todo comment more understandable
  12. Garvin Hicking uploaded patch set 7 V +1 08/14/24, 23:53

    Rewordings
  13. Garvin Hicking commented on patch set 7 08/14/24, 23:54

    LinkVarsCalculator.php:66 Reply

    Done
  14. core-ci voted on patch set 7 V -1 08/15/24, 00:00 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/63429

  15. Garvin Hicking uploaded patch set 8 V -1 08/15/24, 07:05

    Fix whitespace
  16. core-ci voted on patch set 8 V +1 08/15/24, 07:12 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/63443

  17. Stefan Froemken commented on patch set 8 CR -1 08/15/24, 20:40

    LinkVarsCalculator.php:32

    Please always upper case constants: CORE_ARGUMENTS_TO_SKIP
  18. Stefan Bürk commented on patch set 8 CR -2 08/16/24, 07:55

    Garvin, let's have a call/talk about that next week after your vacation.
  19. Stefan Bürk commented on patch set 8 08/16/24, 07:56

    Reply

    + document the outcome here as comment then.
  20. Garvin Hicking uploaded patch set 9 CR -1 V +1 08/22/24, 08:43

    Copied Votes: * Code-Review-2 (copy condition: "changekind:NO_CHANGE OR **is:MIN**")
  21. core-ci voted on patch set 9 V +1 08/22/24, 08:50 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/63965

  22. Garvin Hicking commented on patch set 9 CR -2 V -1 08/22/24, 09:06

    Reply

    Done
    Stefan Bürk and I discussed this patch. The possible impact/side effects could be considerate, and would need a larger set of tests and verifications to not break anything, especially due to the backport goal of 11.5 and 12.4. We will postpone testing this to the v13 stabilization sprint later this year, and ideally talk about this on-location to gather more feedback. To recap, the general problem is this: * Caches are cleared * A URL like https://example.com/index.php?id=1&L=4711 is requested * The "L" parameter should be invalid, and falls back to default language * Links are created on the page, but since "L=4711" is evaluated and accepted, and no pages with that language exist, all links built with TypoScript pointing to any page will have an empty href * This result is now CACHED as the default language page result! Any normal user requesting the resulting page will receive the wrong cache result with wrongly cached links The idea of this patch is to not accept a parameter like "L" to prevent that outside URL arguments are used for linkbuilding. The assumption of this patch is, that if parameters like L, chash etc. are not specifically set (via linkVars) the link generation will already utilize the context of the current page request to build links. This assumption needs thorough verification, what could happen if these linkvars are now missing, and people might NOT use "speaking URLs" still, or they might rely on the behaviour that "core arguments" are passed. We will need to think about all these scenarios. Maybe another solution could be to mark requests with possibly "invalid" URL arguments to not be persisted in the cache. Thus, marking as -2 for now.

    LinkVarsCalculator.php:32 Reply

    Done
  23. Lina Wolf wrote 08/26/24, 04:26

    Removed reviewer Lina Wolf.
  24. Benni Mack updated the commit message in patch set 10 V +1 10/18/24, 13:47

    Copied Votes: * Code-Review-2 (copy condition: "changekind:NO_CHANGE OR **is:MIN**")
  25. Garvin Hicking abandoned the change 03/28/25, 12:28

    Abandoned. will try to write a "FAQ".