Issue Feature Under Review Quiet

#110832Introduce upload constraints for file uploads

Sebastian Michaelsen 09/29/26, 12:58 updated 09/30/26, 08:51

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 in ResourceStorage::assureFileUploadPermissions() and passed to the client by FilesControlContainer, FileListController and CreateFileBrowser (data-max-file-size)
  • File deny pattern: $GLOBALS['TYPO3_CONF_VARS']['BE']['fileDenyPattern'], checked through FileNameValidator and passed to the client by FileListController and CreateFileBrowser (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;
}
  • UploadContext holds 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 in ResourceStorage for 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 ResourceStorage through 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