Skip to content

Commit 01d4027

Browse files
linawolffroemken
andauthored
[SECURITY] Enforce file extension and MIME-type consistency (#5644)
* [SECURITY] Enforce file extension and MIME-type consistency Resolves: TYPO3-Documentation/Changelog-To-Doc#1252 Releases: main, 13.4. 12.4 * Update Documentation/Configuration/Typo3ConfVars/SYS.rst Co-authored-by: Stefan Frömken <froemken@gmail.com> --------- Co-authored-by: Stefan Frömken <froemken@gmail.com>
1 parent 1d1b3a2 commit 01d4027

File tree

2 files changed

+71
-1
lines changed

2 files changed

+71
-1
lines changed

Documentation/ApiOverview/Fal/UsingFal/ExamplesFileFolder.rst

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@ Deleting a file
9595
:language: php
9696
:caption: EXT:my_extension/Classes/MyClass.php
9797

98-
9998
.. _fal-using-fal-examples-file-folder-add-file:
10099

101100
Adding a file
@@ -123,6 +122,61 @@ To store the file in a sub-folder use :php:`$storage->getFolder()`:
123122
In this example, the file path would likely be
124123
:file:`<document-root>/fileadmin/some/nested/folder/final_file_name.ext`
125124

125+
.. _fal-using-fal-examples-file-folder-add-file-security:
126+
127+
Security and consistency checks
128+
--------------------------------
129+
130+
.. versionadded:: 13.4.12 / 12.4.31
131+
Stricter validation is enforced when working with files through the FAL API,
132+
specifically regarding file extensions and MIME types.
133+
134+
The new behaviour was introduced with the security fix `Important: #106240 -
135+
Enforce File Extension and MIME-Type Consistency in File Abstraction
136+
Layer <https://docs.typo3.org/permalink/changelog:important-106240-1747316969>`_.
137+
138+
The following methods of :php:`\TYPO3\CMS\Core\Resource\ResourceStorage` perform
139+
validation checks:
140+
141+
* :php:`addFile()`
142+
* :php:`renameFile()`
143+
* :php:`replaceFile()`
144+
* :php:`addUploadedFile()`
145+
146+
Validation behavior:
147+
148+
* Only explicitly allowed file extensions are accepted. Valid extensions must be configured in:
149+
`$GLOBALS['TYPO3_CONF_VARS']['SYS']['textfile_ext'] <https://docs.typo3.org/permalink/t3coreapi:confval-globals-typo3-conf-vars-sys-textfile-ext>`_,
150+
`$GLOBALS['TYPO3_CONF_VARS']['SYS']['mediafile_ext'] <https://docs.typo3.org/permalink/t3coreapi:confval-globals-typo3-conf-vars-sys-mediafile-ext>`_,
151+
`$GLOBALS['TYPO3_CONF_VARS']['SYS']['miscfile_ext'] <https://docs.typo3.org/permalink/t3coreapi:confval-globals-typo3-conf-vars-sys-miscfile-ext>`_.
152+
* The file’s MIME type must match the expected file extension. For example,
153+
a real PNG image with a `.exe` file extension is rejected.
154+
155+
Feature flags controlling this behavior:
156+
157+
* :php:`security.system.enforceAllowedFileExtensions`
158+
* :php:`security.system.enforceFileExtensionMimeTypeConsistency`
159+
160+
For controlled or low-level operations, consistency checks can be bypassed temporarily:
161+
162+
.. code-block:: php
163+
164+
<?php
165+
class ImportCommand
166+
{
167+
use \TYPO3\CMS\Core\Resource\ResourceInstructionTrait;
168+
169+
protected function execute(): void
170+
{
171+
// ...
172+
173+
// Skip the consistency check once for the specified storage, source, and target
174+
$this->skipResourceConsistencyCheckForCommands($storage, $temporaryFileName, $targetFileName);
175+
176+
/** @var \TYPO3\CMS\Core\Resource\File $file */
177+
$file = $storage->addFile($temporaryFileName, $targetFolder, $targetFileName);
178+
}
179+
}
126180
127181
.. _fal-using-fal-examples-file-folder-create-reference:
128182

Documentation/Configuration/Typo3ConfVars/SYS.rst

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,22 @@ configurations.
246246
Commalist of file extensions perceived as media files by TYPO3.
247247
Must be written in lower case with no spaces between.
248248

249+
.. _typo3ConfVars_sys_miscfile_ext:
250+
251+
.. confval:: miscfile_ext
252+
:name: globals-typo3-conf-vars-sys-miscfile-ext
253+
:Path: $GLOBALS['TYPO3_CONF_VARS']['SYS']['miscfile_ext']
254+
:type: text
255+
:Default: 'zip'
256+
257+
.. versionadded:: 13.4.12 / 12.4.31
258+
This property has been added with the security fix `Important: #106240 -
259+
Enforce File Extension and MIME-Type Consistency in File Abstraction
260+
Layer <https://docs.typo3.org/permalink/changelog:important-106240-1747316969>`_.
261+
262+
Allows specifying file extensions that don't belong to either `textfile_ext`
263+
or `mediafile_ext`, such as `zip` or `xz`.
264+
249265
.. _typo3ConfVars_sys_binPath:
250266

251267
.. confval:: binPath

0 commit comments

Comments
 (0)