Review main Merged

91925[BUGFIX] Properly persist ENV variables in site config (rootPageId)

Rozbeh Chiryai Sharahi CR +2 V +2 Hard +332 −69 updated 03/10/26, 14:13

Commit message

With this patch, ENV placeholder variables can be used for
site configuration dropdowns like rootPageId, without
failing to display the current config in the GUI or
failing to persist any site configuration where such a config
is utilized.

Details:

The site config (sites/xxx/config.yaml) allows to process YAML
placeholders. This can be properly utilized already for plaintext
input fields like `base` and `websiteTitle`, so that in the
config GUI these will contain the values like

```
  base: 'https://%env(DDEV_HOSTNAME)%/styleguide-demo'
```

Saving this in the GUI will keep the value, as intended.
Saving `%env(...)` placeholders via GUI in any variable that
did not yet contain an ENV variable will fail due to security
reasons.

However, applying the same ENV replacement logic for a select-field
like `rootPageId` fails due to:

1) The backend config GUI will show a root page id select dropdown
   with the entry "MISSING LABEL ("%env...%)", revealing that
   no page id resolving takes place in the GUI (good, in theory).

2) When saving this, the value will be invalidated, the rootPage
   not be resolved, ending in an exception for "Existing config
   for site xxx-[randomhash] not found". This happens because
   TYPO3 treats the config as a "new site", create an empty directory
   and fails to populate the config (rightly so).

3) Re-entering the site config will reveal the stored flash messages:

   ```
      Renamed identifier
      Given site identifier "main" already exists. It has been renamed
      to "main-6985fec488155032110726". Maybe you want to edit the site
      again and give it a better name.

      Introducing placeholder %env(BASE_URI)% for base is not allowed
   ```

The reason for why the rootPageId resolve fails is, the
`AbstractItemProvider` would remove the given value from
passed-through `databaseRow`, as the value is (by foreign_table clause)
not a  valid root-page-id.

On save of site-configuration the ENV-variable based root-page-id
would get lost on int conversion.

To fix this, this patch:

- Makes use of a specific EnvPlaceholderProcessor which does isolated
  replacements. The code is based on what the YamlFileLoader() already
  did, and makes it usable outside the whole YAML loading process.
  That processor is able to parse a single value with possibly multiple
  ENV placeholders.

- This new placeholder processing is then used to check whether the
  current root-page-id actually is an ENV placeholder.
  If yes => temporarily accept the value as an allowed value.

- On save, the same placeholder processing is used to process the
  page-id, so TYPO3 duplication checks and root-page-id checks can take
  place. Finally, the unprocessed value (placeholder) is used again for
  persistence into config.yaml.

This whole logic also applies to any other TcaSelect-type field
of the site-config which contains an ENV placeholder.

Review

  • Code review CR +2 Done
    • Garvin Hicking +2
    • Sven Liebert +1
    • Rozbeh Chiryai Sharahi +1
  • Verified V +2 Done
    • Garvin Hicking +2
    • Timo Webler +1
    • Sven Liebert +1
    • core-ci +1 CI

Issues 1

Files 10

Review log 2842

Show 1017 earlier messages
  1. Rozbeh Chiryai Sharahi uploaded patch set 1 11/28/25, 05:51

  2. Rozbeh Chiryai Sharahi uploaded patch set 2 11/28/25, 05:58

  3. core-ci voted on patch set 1 V -1 11/28/25, 06:06 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/91171

  4. core-ci voted on patch set 2 V -1 11/28/25, 06:11 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/91172

  5. Rozbeh Chiryai Sharahi uploaded patch set 3 V -1 11/28/25, 07:06

  6. Rozbeh Chiryai Sharahi uploaded patch set 4 11/28/25, 07:12

  7. core-ci voted on patch set 3 V -1 11/28/25, 07:14 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/91178

  8. core-ci voted on patch set 4 V -1 11/28/25, 07:20 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/91179

  9. Rozbeh Chiryai Sharahi uploaded patch set 5 V -1 11/28/25, 07:24

  10. core-ci voted on patch set 5 V +1 11/28/25, 07:33 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/91180

  11. Rozbeh Chiryai Sharahi uploaded patch set 6 V +1 11/28/25, 08:24

  12. core-ci voted on patch set 6 V -1 11/28/25, 08:34 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/91186

  13. Garvin Hicking marked it work in progress 11/28/25, 08:41

  14. Garvin Hicking commented on patch set 6 02/06/26, 11:09

    You might want to check out / look at typo3/sysext/core/Classes/Configuration/Loader/YamlPlaceholderGuard.php
  15. Garvin Hicking uploaded patch set 7 V -1 02/06/26, 15:01

  16. core-ci voted on patch set 7 V -1 02/06/26, 15:11 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/95301

  17. Garvin Hicking uploaded patch set 8 V -1 02/06/26, 15:15

  1. core-ci voted on patch set 8 V +1 02/06/26, 15:26 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/95304

  2. Garvin Hicking marked it ready for review 02/06/26, 20:19

  3. Garvin Hicking uploaded patch set 9 V +1 02/13/26, 07:41

    Refactor into specific processor
  4. core-ci voted on patch set 9 V -1 02/13/26, 07:51 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/95805

  5. Garvin Hicking uploaded patch set 10 V -1 02/13/26, 08:15

    address CGL
  6. Garvin Hicking uploaded patch set 11 02/13/26, 08:18

  7. core-ci voted on patch set 10 V -1 02/13/26, 08:28 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/95807

  8. core-ci voted on patch set 11 V -1 02/13/26, 08:28 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/95808

  9. Garvin Hicking commented on patch set 12 V -1 02/13/26, 08:30

    Published edit on patch set 11.
  10. core-ci voted on patch set 12 V +1 02/13/26, 09:05 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/95809

  11. Rozbeh Chiryai Sharahi commented on patch set 12 02/13/26, 10:16

    EnvPlaceholderProcessor.php:46

    no code anywhere uses this method neither with null nor with int. Introducing type-bluriness here is not necessary. Also $referenceArray is currently not used and should not be added -- I guess this unused arguments are there because you implement the `PlaceholderProcessorInterface` on this class, though you dont need to. This class is basically using the processor-list which runs a stack of implementations of `PlaceholderProcessorInterface`, but does not need itself to implement the `PlaceholderProcessorInterface` like the children do.

    EnvPlaceholderProcessor.php:54

    no code anywhere uses this method neither with null nor with int. Introducing type-bluriness here is not necessary. Also $referenceArray is currently not used and should not be added. probably unwanted sideeffect of implementing processor-interface

    EnvVariableProcessor.php:26

    I understand it can be convenient to not type-caste a yaml value to string, before using canProcess. However, I'd suggest to make this more declarative and do `if(!is_string($placeholder)) return false` as this is currently passing a possible int to str_contains

    EnvVariableProcessor.php:38

    This signature change is not needed. when calling `process` you should beforehand call `canProcess` (which is currently the case everywhere). On `canProcess` however it makes sense to me.
  12. Rozbeh Chiryai Sharahi commented on patch set 12 02/13/26, 10:24

    EnvVariableProcessor.php:26 Reply

    This code is actually not used in the branch at all, so i'd even revert the change, as it is out-of-scope to create this extra type `int` and the `Interface` also has `string` only
  13. Rozbeh Chiryai Sharahi uploaded patch set 13 V +1 02/13/26, 10:25

  14. Rozbeh Chiryai Sharahi uploaded patch set 14 02/13/26, 10:32

  15. core-ci voted on patch set 13 V -1 02/13/26, 10:38 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/95822

  16. core-ci voted on patch set 14 V +1 02/13/26, 10:42 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/95824

  17. Garvin Hicking commented on patch set 14 02/13/26, 10:54

    Thanks, this seems to evolve into the right direction :)

    EnvPlaceholderProcessor.php:46 Reply

    Exactly. And yes, the interface is it helpful here. Thanks.

    EnvPlaceholderProcessor.php:54 Reply

    Done

    EnvVariableProcessor.php:26 Reply

    Done

    EnvVariableProcessor.php:38 Reply

    Done
  18. Rozbeh Chiryai Sharahi commented on patch set 14 CR +1 02/13/26, 11:55

    Short summary of the steps taken: - we introduced an `EnvPlaceholderProcessor` which uses the same logic as `YamlFileLoader` for `%env(...)%` resolving. - The `EnvPlaceholderProcessor` uses the already existing `EnvProcessorInterface` stack - `EnvPlaceholderProcessor` is used on various places in order to resolve env-var-based inputs of site configs in order to do specific checks. For instance root-page id must be an existing page, and we need to resolve the env-placeholder in order to check if the page actually exists. - ... however wo do not touch the input when writing back to site config otherwise `%env(ROOT_PAGE_ID)` would turn into the resolved value, similar to introducing `getenv(...)` on `settings.php`. - Tests where introduced - Code is none-breaking - I checked manually on TYPO3 GUI if it works. I tested in combination with othersites with hard-coded root-page-id and also in isolation. - Tests are passing For me this patch is ready and I am looking forward to thumbsup or more inputs.
  19. Garvin Hicking voted on patch set 14 CR +1 V +1 02/13/26, 12:26

  20. Timo Webler commented on patch set 14 V +1 02/18/26, 07:20

    I tested it. Everything works as expected. We have this problem with our setups, too. So I'm glad someone has solved it. 😊
  21. Sven Liebert voted on patch set 14 CR +1 V +1 02/23/26, 18:23

  22. Benni Mack commented on patch set 14 CR -2 02/24/26, 08:05

    I need to review this properly. give me some time (= days)
  23. Benni Mack voted on patch set 14 CR 0 03/10/26, 13:01

  24. Garvin Hicking voted on patch set 14 CR +2 V +2 03/10/26, 14:06

  25. Garvin Hicking merged patch set 15 03/10/26, 14:13