File uploads and SVG
This page is for administrators and developers. Uploads are a classic way into a web server: a script disguised as an image, an SVG or HTML file that runs script in the browser, or a huge file that exhausts the server. Exponential has defenses at each step (Security hardening: File upload abuse).
Warning
.htaccess slows down every request. When .htaccess files are enabled (AllowOverride anything but None), let alone
used, Apache looks for them and reads and evaluates them on every request, in every directory of the path, and
page loading times go up drastically (measured). The only real fix is to switch the feature off for
the virtual host: AllowOverride None in the HTTPS virtual host, and the rules in the virtual host's own
configuration as mod_rewrite rules. That is far faster in production speed tests and well worth the time it takes
to optimize a production configuration. Switch over right away: copy the rules of the
example HTTPS virtual host into your virtual host (with the static cache, also
staticcache_offload.conf), set AllowOverride None, run apachectl configtest, reload Apache and
test the site. The same rules for other servers: nginx, LiteSpeed,
Caddy, IIS, Velocity (built in); where virtual host rules go in a control
panel: Plesk, cPanel, DirectAdmin, ISPConfig.
On LiteSpeed or OpenLiteSpeed, the server's own page cache can also answer anonymous visitors and crawlers without PHP: Page caching with LiteSpeed and OpenLiteSpeed.
Contents
The defenses
| Step | Defense | Where |
|---|---|---|
| Accepting an image | type read from the file content with PHP's fileinfo, compared with an allow-list | expImageUploadValidator, image.ini [ImageUploadSettings] AllowedMIMETypes[] |
| Storing an SVG | sanitized; only what is known to be safe is kept | expSvgSanitizer, image.ini [ImageUploadSettings] SanitizeSVG=enabled |
| Serving | nothing below the document root executed (.php, .phtml, .phar answer 404); only image files served directly from the storage | .htaccess_root |
| Serving other uploads | only through content/download, which checks read permission | kernel |
| Serving SVG from the storage | a sandboxing policy header (sandbox; default-src 'none') | .htaccess_root, needs mod_headers |
| Packages | uploads need package policies; ManagedByDeployment blocks them | Packages |
The allowed image types as shipped are JPEG, PNG, GIF, WebP, AVIF, TIFF, BMP and SVG (Security and audit, 1).
SVG images
Since 15 October 2026 the image datatype accepts SVG (.svg, .svgz) on every site. An SVG is a document a browser
can run script from, so it is never stored as uploaded: the stored file is the sanitizer's output. Every path that
stores an image sanitizes (edit form, upload module, multi-upload, editor upload dialog, AJAX uploader, WebDAV, package
import). A file that claims to be SVG but is not recognized as one is not stored
(SVG images).
Keep them in place
- Keep the rewrite rules current after every upgrade (
.htaccess_root, or the derived nginx block); never serve the installation with a "serve the file if it exists" configuration. - Keep
SanitizeSVG=enabled. - Check that fileinfo is loaded in the web server's PHP:
php -m | grep fileinfoon the command line, and the same for PHP-FPM. Without it an older check applies and the log says so. - Give upload rights only to roles that need them.
- Keep
TemporaryDirprivate to the site, for example belowvar/(the shipped/tmp/is shared with every user of the machine). - Documents and other files are not scanned for malware by Exponential. If your policy requires scanning, do it at the server or storage level.
Checking
./console exp:ini get 'image.ini/ImageUploadSettings/AllowedMIMETypes' --allow-root-user
for p in .env .git/config extension/expservices/ezinfo.php; do
curl -s -o /dev/null -w "$p %{http_code}\n" https://www.example.gov/$p
doneExpected: the allow-list as you intend it, and 404 three times.
Related pages
- SVG images
- 13.2 What the web server must never hand out
- SVG and image formats
- Free documentation: this page is free to copy, translate and improve under the GNU FDL 1.3.
Become an Exponential Partner
Partners share their information, provide funding, contribute back and develop the products with us, and that is how Exponential grows. A partner website and dashboard are planned for mid-2027: please become a partner today to speed up our growth rate and land new features faster.