#110832Introduce upload constraints for file uploads
Description
Problem
The rules that decide whether a file may be uploaded are hard-coded and spread across several places. Each one is implemented twice: once as a client-side hint for the drag uploader, once as the actual server-side check.
- Maximum file size:
GeneralUtility::getMaxUploadFileSize(), checked inResourceStorage::assureFileUploadPermissions()and passed to the client byFilesControlContainer,FileListControllerandCreateFileBrowser(data-max-file-size) - File deny pattern:
$GLOBALS['TYPO3_CONF_VARS']['BE']['fileDenyPattern'], checked throughFileNameValidatorand passed to the client byFileListControllerandCreateFileBrowser(data-file-deny-pattern)
Extensions cannot add their own rules. Examples:
- a lower size limit for certain user groups (#108660)
- rejecting files after a virus or content scan
- restricting uploads per storage or folder
- informing editors that uploads are post-processed (e.g. spell-checked, resized)
The two halves also drift apart easily: the limit shown in the UI and the limit the server enforces can differ.
Proposal
Introduce upload constraints: services tagged file.upload_constraint that implement an interface with two methods:
interface UploadConstraintInterface
{
public function describe(UploadContext $context): ?UploadConstraintDescription;
public function validate(UploadedFileInterface $file, UploadContext $context): ?UploadRejection;
}
UploadContextholds the storage, the target folder and the user.describe()runs before the upload, when there is no file yet. It returns a human-readable label and optional machine-readable client hints (maximum file size, deny pattern). The core merges the hints of all constraints: the lowest size wins, and the patterns are combined.validate()runs inResourceStoragefor every uploaded file. A rejection carries a reason, which is shown to the user as a flash message.
Because one class describes and enforces a rule, the hint in the UI and the server-side check stay consistent.
Scope of this issue
- Add the interface, the value objects and a registry collecting all tagged constraints
- Port the existing core rules (PHP upload limit, file deny pattern) to constraints
- Validate uploads in
ResourceStoragethrough the registry, keeping today’s exceptions and flash messages for the ported rules - Feed the existing data attributes of the drag uploader from the registry
- No change in behaviour for existing installations
- Deprecating
GeneralUtility::getMaxUploadFileSize()
Out of scope / follow-ups
- Rendering constraint labels in the upload UI (separate issue)
Supersedes #108660 and https://review.typo3.org/c/Packages/TYPO3.CMS/+/92360, following the review feedback there.
Reviews 2
History 02
-
Gerrit Code Review pushed patch set 1 for main to change 96201 status
NewUnder Review <span data-processor="relativetime" data-value="2026-09-30T06:18:16+00:00" > 09/30/26, 06:18 </span> -
Gerrit Code Review pushed patch set 2 for main to change 96201 <span data-processor="relativetime" data-value="2026-09-30T08:51:06+00:00" > 09/30/26, 08:51 </span>