Study guide · Uploads, files and extensions
Safe uploads, protected files and trustworthy extensions
Where users may upload files and foreign code enters the installation, especially dangerous holes appear. On this page you learn how an upload turns into a back door and which layers prevent that. After that it is about protected files, about tokens against forged requests and about choosing and maintaining extensions. The running example is the careers page of a company with an application form from a custom extension.
How an upload becomes a back door
The biggest risk of an insecure upload is an executable file in the web root. If an attacker can upload a PHP file and then call it in the browser, the server runs it. The attacker now has code running on the server. This is called remote code execution, RCE for short.
Usually the attacker places a web shell. That is a small script file through which they remote-control the server via the browser. They can read files, take credentials from the configuration and create further back doors.
Even without uploads, nothing sensitive belongs in the web root. Backup files such as an SQL dump or a ZIP archive are retrievable there via the browser. They reveal credentials, password hashes and customer data. Backups always belong outside the document root.
The fileDenyPattern and its limits
TYPO3 blocks dangerous file types on upload with the fileDenyPattern. That is a regular expression in the system configuration. The default blocks executable scripts with extensions such as php, phar, phtml, cgi and pl, as well as the file .htaccess. Images, PDFs and Office files stay allowed.
Do not weaken this pattern, even if you trust your editors. An attacker who takes over just one simple editor account could otherwise place a web shell.
That is why editors upload files via the backend and not via FTP. The backend checks every upload against the fileDenyPattern. Via FTP, even executable files land on the server unchecked.
This is exactly the weak spot of many projects. Custom, unchecked upload code is often more dangerous than the Core. It bypasses the reviewed mechanisms of the Core and the backend, and its quality varies greatly. The Core ships the fileDenyPattern, the file abstraction layer FAL and validators. Custom code only uses them if the developer applies them on purpose. No mechanism checks custom code automatically, and no Security Team has reviewed it by default.
Allowlist, content check and neutral names
A deny list names what is forbidden. An allowlist names what is allowed. The allowlist is superior, because new dangerous extensions are not allowed automatically. A deny list, on the other hand, easily misses a new variant. The allowlist goes together with a content check. It stops disguised files, for example a script with the extension jpg. The content check complements both lists, and no list makes it unnecessary.
TYPO3 has three such allowlists: textfile_ext, mediafile_ext and miscfile_ext. Two feature toggles build on them:
- security.system.enforceFileExtensionMimeTypeConsistency is active by default. TYPO3 checks whether extension and MIME type match. It rejects an HTML file disguised as jpg.
- security.system.enforceAllowedFileExtensions is off by default. When switched on, TYPO3 only allows extensions from the three configured allowlists.
Ideally you do not keep the name of an uploaded file. Replace it with a self-generated, neutral name. That takes control over the file name away from the attacker. Tricks with special characters or double extensions come to nothing.
The most important layer is the target. Store uploads in a folder where the server runs no scripts. Then an uploaded PHP file does not turn into a web shell, even if it slips through. Limiting the file size, renaming the file or writing it in capital letters, on the other hand, prevents nothing.