Skip to main content

Protecting uploaded files

Where the files attached through a file field are stored, and how they are protected. If your site runs on nginx, adding one server rule is recommended (below).

Where files are stored and what Form Plant does​

Uploaded files go to a per-form folder inside the uploads directory:

wp-content/uploads/fplant_uploads/fplant_(form ID)_(32 random characters)_uploads/
  • The folder name and the file name contain random strings, so the URL cannot realistically be guessed (the 32-character folder name is used since v1.5.3; folders made earlier have 6 characters, and files uploaded after updating to v1.5.3 go to a new folder)
  • The folder contains an .htaccess file that blocks requests from outside (effective on Apache and LiteSpeed)
  • The file URL is never shown in notification emails, webhooks or the admin screens. Downloads from the Submissions screen are handed over by Form Plant after checking the login and the permission
  • Deleting a submission deletes its uploaded files as well (since v1.5.3)

If your site runs on nginx​

nginx does not read .htaccess. The block above has no effect there, and the only protection left is the random folder and file name. A file cannot be opened unless its URL leaks, but adding the following rule to the server configuration closes the gap.

location ~* /fplant_uploads/fplant_[^/]+_uploads/ {
deny all;
}
  • Put it inside the site's server { ... } block, before any other location ~ (regular expression) block. If a rule for static files such as images comes first, nginx uses that one instead
  • After adding it, check the configuration with nginx -t and reload nginx
  • Downloads from the admin screen and attachments in notification emails keep working with this rule (both read the file on the server directly, not through its URL)
  • fplant_uploads/assets/ (per-form custom CSS) in the same place must stay public, so the rule does not cover it

If you cannot change the nginx configuration (shared hosting, for example), ask your hosting provider to add the rule.

Checking the protection (Site Health)​

Since v1.5.3, Tools → Site Health includes a test called Form Plant upload protection. Form Plant places a temporary test file and requests it from your own site once, to see whether it can be opened from outside.

ResultMeaning
Files uploaded through Form Plant cannot be opened directlyProtected. Nothing to do
Files uploaded through Form Plant can be opened directly by URLNot protected. Add the nginx rule
Form Plant could not check whether uploaded files are protectedThe check could not be completed: the site cannot connect to itself, is password-protected, and so on. On Apache and LiteSpeed the files are protected and nothing needs to be done. On nginx, make sure the rule above is in place

The test file and its folder are removed after every check.

Keeping the files​

To keep the uploaded files when a submission is deleted, turn the deletion off with a filter.

// Keep uploaded files when a submission is deleted
add_filter( 'fplant_delete_submission_files', '__return_false' );

See the PHP hooks reference for details.