How to Set a CSP Header for Upload Folders
Security Intermediate 5 min read

How to Set a CSP Header for Upload Folders

A CSP header for upload folders stops uploaded HTML and SVG files from running scripts. Apache and nginx configuration from TYPO3's documentation.

Published: December 1, 2026 • Updated: December 1, 2026
content security policyfile uploadapachenginxtypo3

A CSP header for upload folders is a Content-Security-Policy sent with every file served from a directory that holds user-supplied content. It tells the browser that files from that path may not run scripts, load stylesheets or embed plugins, so an uploaded HTML or SVG document renders as inert markup instead of executing in your site's origin. TYPO3 documents the exact header for Apache and nginx, and the actively exploited CVE-2026-125160 upload path leak is only dangerous on servers that skipped it.

Why does an upload folder need its own CSP?

Any folder that accepts files from users can end up holding browser-executable content, because file-type filters fail, get misconfigured or are bypassed. A CSP header on that folder means the browser refuses to execute whatever slipped through, regardless of how it got there.

TYPO3's administrator guidelines spell out the threat: authenticated users without administrator rights can upload to their file mounts, and that includes HTML or SVG files carrying JavaScript. The 2026 Form Framework bugs extended the same risk to anonymous visitors on forms with an empty MIME allow list. Both cases are stopped by the same header.

The policy your main pages use does not help here. TYPO3's own CSP feature, and most application-level CSP implementations, only apply to responses the application generates. Static files under fileadmin/ are served directly by the web server, so the header has to come from the web server configuration.

What should the policy say?

TYPO3's documented policy for the default storage is a four-directive header. The header below is the one shown in TYPO3 Explained for fileadmin/.htaccess:

Content-Security-Policy: default-src 'self'; script-src 'none'; style-src 'none'; object-src 'none';

Each directive does one job. The default-src 'self' baseline lets the file load same-origin sub-resources such as images referenced from an SVG. The script-src 'none' directive blocks all script execution, inline or external. The style-src 'none' directive blocks stylesheets, which closes CSS-based data exfiltration tricks. The object-src 'none' directive blocks plugins and embedded objects.

TYPO3 later tightened the shipped file to add the sandbox directive. The core changelog entry for issue #106715 explains that sandbox additionally disallows downloads, form submissions, popups and top-level navigation from files that may contain markup. The same entry carves out two exceptions: PDF files get a looser policy because strict rules stopped Safari from rendering them, and SVG files are allowed inline styles so that styled SVGs still display.

How do you set the header on Apache?

Put a .htaccess file in the upload directory with a Header set directive inside an IfModule block for mod_headers. TYPO3 ships this file as fileadmin/.htaccess for the default storage, so on most Apache installations the work is to verify it exists and is current rather than to create it.

The simple form from TYPO3's documentation is:

# placed in fileadmin/.htaccess on Apache 2.x webserver
<IfModule mod_headers.c>
  Header set Content-Security-Policy "default-src 'self'; script-src 'none'; style-src 'none'; object-src 'none';"
</IfModule>

The newer form in the TYPO3 changelog uses three FilesMatch blocks: one for .pdf with the Safari-compatible policy, one for .svg that permits inline styles and adds sandbox, and a negative-lookbehind catch-all for everything else that applies the strict policy plus sandbox. Copy that version if you are updating an existing installation.

Two Apache caveats. First, .htaccess only works if the virtual host allows overrides for that directory; if AllowOverride is None, move the directives into the server configuration. Second, TYPO3 states that the fileadmin/.htaccess file is not updated automatically once it has been created, so an installation set up years ago will still have the old header until someone edits it.

How do you set the header on nginx?

nginx has no per-directory configuration file, so the header goes in the server block. TYPO3's documentation uses a map so the policy applies only to the upload path without being overridden by other add_header lines:

map $request_uri $csp_header {
    ~^/fileadmin/ "default-src 'self'; script-src 'none'; style-src 'none'; object-src 'none';";
}

server {
    # Add strict CSP header depending on mapping (fileadmin only)
    add_header Content-Security-Policy $csp_header;
    # ... other add_header declarations can follow here
}

The map matters because of an nginx rule that catches people out: add_header directives set at the server level are discarded inside any location block that declares its own add_header. A location-scoped header for the upload folder would silently drop your other security headers for that path, and a server-scoped header without the map would apply the strict policy to the whole site and break it. The map gives you a per-path value with one add_header line.

Adapt the regular expression to your actual upload paths. If your Form Framework uploads land outside fileadmin/, or you have additional file storages, add each public storage base path to the map.

How do you verify the header is actually served?

Fetch a file from the upload folder with a command-line HTTP client and read the response headers. If the Content-Security-Policy line is missing, nothing else in this article is in effect. Check a .pdf, a .svg and a plain file separately if you used the per-type policy.

Beyond the header check, upload a harmless HTML test file through the same path a user would use, open it in a browser and confirm the console reports blocked script execution. Then delete the test file. TYPO3's documentation also points to Google's CSP Evaluator for reviewing the policy text itself.

Finally, confirm the behaviour survives deployments. A build process that regenerates the web root, a container image that does not include the .htaccess file, or an nginx configuration managed by a template that someone else edits can all remove the header without anyone noticing. Put the header check in your post-deploy smoke test.

Where this fits

The header is a containment control. It assumes an executable file will reach the folder and makes that outcome harmless. It pairs with two other layers: fixing the leak that reveals the file's location, covered in what CWE-209 is, and the structural option of serving user uploads from a separate domain so that even a fully executable file has no access to your users' sessions. If you only have time for one of the three this week, the header is the fastest to deploy and verify.