Important: #106240 - Enforce File Extension and MIME-Type Consistency in File Abstraction Layer
See forge#106240
Description
The following methods of
Resource
have been improved to enhance
consistency and security for both existing and uploaded files:
add
File rename
File replace
File add
Uploaded File
Key enhancements
- Only explicitly allowed file extensions are accepted. These must be configured
under the following sub-properties in
$GLOBALS
:['TYPO3_ CONF_ VARS'] ['SYS'] textfile_
,ext mediafile_
, orext miscfile_
.ext - Files are only accepted if their MIME type matches the expected file extension.
The MIME type is determined based on the actual file content. For example,
uploading a real PNG image with the filename
image.
will be rejected, becauseexe image/
is not a valid MIME type for thepng exe
extension.
New Configuration Property in $GLOBALS['TYPO3_CONF_VARS']['SYS']
A new configuration property,
miscfile_
, has been introduced. It
allows specifying file extensions that don't belong to either textfile_
or mediafile_
, such as zip
or xz
.
New Feature Flags
security.
: Controls whether only the configured file extensions are permitted. - Disabled by default in existing installations. - Enabled by default in new installations.system. enforce Allowed File Extensions security.
: Controls whether the MIME type and file extension consistency check is enforced.system. enforce File Extension Mime Type Consistency
Exemptions
Some use cases—such as importing files through internal low-level system components—may require temporary exemptions from the above restrictions.
The following example shows how to define a one-time exemption for a known and controlled operation:
<?php
class ImportCommand
{
use \TYPO3\CMS\Core\Resource\ResourceInstructionTrait;
protected function execute(): void
{
// ...
// Skip the consistency check once for the specified storage, source, and target
$this->skipResourceConsistencyCheckForCommands($storage, $temporaryFileName, $targetFileName);
/** @var \TYPO3\CMS\Core\Resource\File $file */
$file = $storage->addFile($temporaryFileName, $targetFolder, $targetFileName);
}
}
Copied!