Review main Merged

89519[BUGFIX] Fix file uploads where concrete MIME types can't be determined

Benjamin Franzke CR +2 V +2 Hard +384 −31 updated 05/27/25, 06:10

Commit message

Recognize files that are detected with a generic MIME type
(e.g. text/plain instead of text/csv despite their csv file extension
and contents) to be allowed for uploading with the MIME type hardening
added in #106240.

The file extension-based MIME type mapping
(`SYS/FileInfo/fileExtensionToMimeType`) is now superseded (but still
supported) by a more fine-grained MIME type compatibility list that
allows to associate generic (as detected by PHP MIME detectors) MIME
types with a set of allowed extension keys and their associated specific
MIME types.

This means generic matches (like `text/xml`) can be transformed to
specific MIME types (e.g. `application/rss+xml`), based on a combined
file extension and file content detection.

This mapping is based on the mime-db MIME type to extension mapping that
is combined with heuristics to map structured syntax suffixes
(+xml, +yaml, +json) from their generic (detected) MIME type to concrete
ones and to map a text/plain to text/* mime-types.

mime-db based heuristics are:

     * Map text/plain to matching text/* MIME types
     * Map text/plain to matching *+yaml MIME types
     * Map text/plain to matching *+json MIME types
     * Map text/xml to matching *+xml MIME types

The mapping is extendable via:

```
SYS/FileInfo/mimeTypeCompatibility/{mimeType}/{extension}={newMimeType}
```

Review

  • Code review CR +2 Done
    • Benjamin Franzke +2
    • Georg Ringer +1
    • Oliver Hader +1
  • Verified V +2 Done
    • Benjamin Franzke +2
    • Georg Ringer +1
    • Oliver Hader +1
    • core-ci +1 CI

Issues 2

Files 7

Review log 1520

  1. Benjamin Franzke uploaded patch set 1 05/26/25, 08:53

  2. Benjamin Franzke uploaded patch set 2 05/26/25, 08:54

  3. Benjamin Franzke uploaded patch set 3 05/26/25, 08:55

  4. core-ci voted on patch set 3 V +1 05/26/25, 09:02 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/79474

  5. Benjamin Franzke uploaded patch set 4 V +1 05/26/25, 11:58

  6. core-ci voted on patch set 4 V +1 05/26/25, 12:04 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/79488

  7. Oliver Hader commented on patch set 4 05/26/25, 13:53

    FileInfo.php:34

    If guess there should be a comment, that `$targetFileName` only affects the guessers) - basically to avoid the question why `$this->getExtension()` is used below instead of using the extension from `$targetFileName`
  8. Oliver Hader commented on patch set 4 05/26/25, 14:23

    MimeTypeCompatibilityTypeGuesser.php:67

    I guess `+json` should be assigned to `application/json`? I have been testing with a `file.jsonld` which was determined as `application/json`, but the mime-type collection holds `application/ld+json` for that extension. Thus, code-wise having ``` } elseif (str_ends_with($mimeType, '+json')) { foreach ($extensions as $extension) { $mimeTypeCompatibility['application/json'][$extension] = $mimeType; } } elseif ( str_ends_with($mimeType, '+yaml') || (str_starts_with($mimeType, 'text/') && $mimeType !== 'text/plain') ) { ```
  9. Oliver Hader commented on patch set 4 05/26/25, 14:25

    The upgrade wizard worked well 👍
  10. Benjamin Franzke uploaded patch set 5 V +1 05/26/25, 15:32

  11. Benjamin Franzke commented on patch set 5 05/26/25, 15:32

    MimeTypeCompatibilityTypeGuesser.php:67 Reply

    good catch, thanks, I tested this to return text/plain (but with an older PHP version), so both options exist… I've accounted for both cases.

    FileInfo.php:34 Reply

    Ack, done.
  12. core-ci voted on patch set 5 V -1 05/26/25, 15:38 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/79503

  13. Benjamin Franzke uploaded patch set 6 V -1 05/26/25, 15:39

  14. Benjamin Franzke uploaded patch set 7 05/26/25, 15:40

  15. core-ci voted on patch set 6 V -1 05/26/25, 15:48 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/79505

  16. core-ci voted on patch set 7 V +1 05/26/25, 15:50 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/79506

  17. Oliver Hader voted on patch set 7 CR +1 V +1 05/26/25, 18:22

  18. Georg Ringer voted on patch set 7 CR +1 V +1 05/26/25, 19:02

  19. Benjamin Franzke voted on patch set 7 CR +2 V +2 05/27/25, 06:10

  20. Benjamin Franzke merged patch set 8 05/27/25, 06:10