@@ -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
101100Adding a file
@@ -123,6 +122,61 @@ To store the file in a sub-folder use :php:`$storage->getFolder()`:
123122In 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: `\T YPO3\C MS\C ore\R esource\R esourceStorage ` 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
0 commit comments