Review main Abandoned

86092[FEATURE] Restrict backend file uploads by file extensions

Sybille Peters CR 0 V 0 Hard +327 −4 updated 11/10/26, 20:26

Commit message

This change makes it possible to further restrict uploaded
files in the backend by file extension without having
to change the regular expression for fileDenyPattern
($GLOBALS['TYPO3_CONF_VARS']['BE']['fileDenyPattern']).
Changing the regular expression for fileDenyPattern
may be error-prone and is currently discouraged by not
showing this option in the global configuration.

Two new global configuration settings are introduced:

-  $GLOBALS['TYPO3_CONF_VARS']['BE']['fileExtensionAllow']
-  $GLOBALS['TYPO3_CONF_VARS']['BE']['fileExtensionDeny']

Additionally, a method `PathUtility::getFileExtension()`
is added to make it possible to have a streamlined way to
retrieve the file extension without instantiating a file object.

The new functionality is added to the existing
method `FileNameValidator::isValid` (instead of adding a
separate method) to ensure that any validation
always considers these settings as well.

Review

  • Code review CR 0
  • Verified V 0
    • core-ci +1 CI

Issues 1

Files 8

Review log 2944

Show 1119 earlier messages
  1. Sybille Peters uploaded patch set 1 09/14/24, 10:43

  2. Sybille Peters updated the commit message in patch set 2 09/14/24, 10:44

  3. Sybille Peters updated the commit message in patch set 3 09/14/24, 10:45

  4. core-ci voted on patch set 2 V -1 09/14/24, 10:52 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/65752

  5. core-ci voted on patch set 3 V -1 09/14/24, 10:54 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/65753

  6. core-ci voted on patch set 1 V -1 09/14/24, 10:54 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/65751

  7. Sybille Peters uploaded patch set 4 V -1 09/14/24, 11:01

  8. core-ci voted on patch set 4 V -1 09/14/24, 11:07 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/65754

  9. Sybille Peters uploaded patch set 5 V -1 09/14/24, 11:23

  10. core-ci voted on patch set 5 V +1 09/14/24, 11:30 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/65755

  11. Sybille Peters uploaded patch set 6 V +1 09/14/24, 11:58

  12. core-ci voted on patch set 6 V +1 09/14/24, 12:05 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/65756

  13. Garvin Hicking commented on patch set 7 V +1 09/14/24, 18:58

    Published edit on patch set 6.
  14. Garvin Hicking commented on patch set 7 09/14/24, 19:01

    Unresolved

    I think this is a feature helpful to have! I could not test the functionality yet and not perform a proper code review. I adjusted the ReST file for some commentary, hope that was fine by you. Things that need testing: - How does this play with TCA configurations for uploads (allow/deny patterns) - How does it play with Extbase file uploads, with also use the FilenameValidator by default. Especially because for extbase file uploads different allowed/denied filename patterns will be applied - Neesd involvement of the Security team for approval

    AbstractFile.php:258

    IMO this does not belong into the Abstract File class, but a method in `TYPO3\CMS\Core\UtilityPathUtility` instead, especially because what's checked is not part of an AbstractFile object, but a another file...? We could then utilize that method also in AbstractFile::getExtension() then. A dependency to PathUtility already exists.
  15. core-ci voted on patch set 7 V +1 09/14/24, 19:03 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/65767

  16. Garvin Hicking updated the commit message in patch set 8 V +1 09/14/24, 19:06

  17. core-ci voted on patch set 8 V +1 09/14/24, 19:15 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/65768

  18. Benni Mack commented on patch set 8 09/14/24, 19:26

    I think that's quite interesting, even though I think if we want to do this on editor-level (at least this is my understanding when reading the commit message), a userTSconfig option would be better suited? I also would like to know what is the definition of which option trumps which? we have this often in other places, such as "allowTags" vs. "denyTags". Setting values to "" or "*" etc, where this needs to be well thought-out. What was your idea here? Also if people would need both options at the same time?
  19. Garvin Hicking commented on patch set 8 09/14/24, 19:47

    Reply

    Maybe I wrongly changed terminology when I referred to "editorial" and mislead you, Benni. I think this is still meant to apply installation-wide. But it's an interesting thought to maybe apply this to backend user groups, too (IMO not on per-user level though). So that certain editors can only upload images, and others can upload zips. Most pressing would be system-wide though, maybe the other enhancement per-groups would be a different patch. I think it's mainly to generally prevent files that are not supported in an implemented site. The ReST file explains the stacking idea: denyPatter filters out dangerous files. AllowTypes positively filter (if used) and in the end deny takes place, and IMO deny needs to be able to deny patterns that were allowed in allowpattern. But I leave the concept to this up to Sybille :)
  1. Sybille Peters commented on patch set 8 09/14/24, 20:58

    Reply Unresolved

    Fron my end, I did not intend to do this on editor-level. In fact I (primarily) want to restrict editors from uploading files which are not suitable for the web. Which option trumps which - yes, that is the question. Right now it is very restrictive, so if you have something in the "deny", it is denied in any case, regardless if it is in "allow". If "allow" is set, only these will be allowed, even if not set in deny. I think this is a safe way to do this. (It does not make sense to set both). Also, the already existing fileDenyPattern is always applied additionally. Also, there is no pattern matching or "*". You only use a list of extensions. (If pattern is required, you can override the fileDenyPattern). I hope my intention is more or less clear. I explained a little in the changelog.
  2. Sybille Peters uploaded patch set 9 V +1 12/01/24, 14:06

  3. core-ci voted on patch set 9 V +1 12/01/24, 14:13 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/70422

  4. Sybille Peters commented on patch set 9 12/07/24, 07:07

    Feature-102644-AddConfigurationForRestrictingAllowedFileExtensions.rst:21

    I think this should be "Comma-separated" or "comma separated"
  5. Sybille Peters uploaded patch set 10 V +1 12/07/24, 07:07

  6. Sybille Peters uploaded patch set 11 12/07/24, 07:11

  7. Sybille Peters commented on patch set 9 12/07/24, 07:11

    AbstractFile.php:258 Reply

    I moved the method
  8. Sybille Peters updated the commit message in patch set 12 12/07/24, 07:12

  9. Sybille Peters commented on patch set 12 12/07/24, 07:13

    Feature-102644-AddConfigurationForRestrictingAllowedFileExtensions.rst:21 Reply

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

  11. core-ci voted on patch set 12 V -1 12/07/24, 07:21 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/70740

  12. core-ci voted on patch set 11 V -1 12/07/24, 07:22 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/70739

  13. Sybille Peters uploaded patch set 13 V -1 12/08/24, 17:26

  14. core-ci voted on patch set 13 V +1 12/08/24, 17:31 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/70777

  15. Benni Mack wrote 01/24/25, 10:05

    Removed cc Benni Mack.
  16. Garvin Hicking uploaded patch set 14 V +1 04/03/25, 19:44

    rebase and fix merge conflict
  17. core-ci voted on patch set 14 V +1 04/03/25, 19:50 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/76969

  18. Sybille Peters updated the commit message in patch set 15 V +1 05/09/25, 06:29

  19. core-ci voted on patch set 15 V +1 05/09/25, 06:36 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/78718

  20. Oliver Hader commented on patch set 15 05/17/25, 08:46

    In general we should aim for an allow-list-only approach. I'll come back to this topic the next few days...
  21. Sybille Peters commented on patch set 15 05/20/25, 10:30

    Reply

    Oliver Hader, it looks like this issue is obsolete with https://typo3.org/security/advisory/typo3-core-sa-2025-014. Can you confirm?
  22. Oliver Hader commented on patch set 15 05/20/25, 12:20

    Reply

    I think, it is. The deny-list approach has been dropped, but it has an opt-in functionality via feature flags (which might be enforced in v14).
  23. Oliver Hader commented on patch set 15 05/20/25, 12:21

    Reply

    However, there are some good changed in this very patch that would help to streamline the existing code (e.g. using appropriate `PathUtility` functions).
  24. Sybille Peters commented on patch set 15 05/20/25, 14:11

    Reply Unresolved

    Ok, waiting for instructions how to proceed. There is no rush from my end.
  25. Oli Bartsch abandoned the change 11/10/26, 20:26

    Abandoning, as the use case of #102644 is covered without touching fileDenyPattern: * System-wide allowlist: feature toggle security.system.enforceAllowedFileExtensions together with SYS.textfile_ext / mediafile_ext / miscfile_ext (see Important-106240, 12.4.x). Remove e.g. "zip" from miscfile_ext to reject it. * Per storage and per file mount: allowedFileExtensions in file-storages.yaml and the new file mount field, merged with #103594 (https://review.typo3.org/c/Packages/TYPO3.CMS/+/96681). A separate deny list on top would add a third place to configure the same thing; an allowlist is the safer model anyway.