On this page
What this issue is
Many sites let people upload files: images in a media library, CVs in a job form, documents in a quote request. Those files are saved in a folder such as wp-content/uploads. That folder should only store and serve files. It should never run them.
If the web server is set to execute PHP anywhere, a file called shell.php in the uploads folder will run as code when someone opens its URL. Attackers call this a webshell: a small script that gives them a remote control panel for your server. The weakness is the folder setting. The way the file gets in is usually a flawed plugin, a form that accepts any file type, or a stolen login.
Why it costs you leads or sales
A webshell lets an attacker edit pages, change form recipients, inject scripts into checkouts, send spam from your domain and read your database, including leads. Typical results are:
- Redirect visitors or ad traffic to another site
- Change the email address your lead form sends to, so leads go to the attacker
- Inject card-skimming or tracking scripts into checkout pages
- Get your domain flagged by Google Safe Browsing, which shows a red warning page to visitors
- Get ad accounts disapproved for malware or deceptive behaviour
- Land your emails in spam after your server is used to send junk
- Upload form or pluginAccepts a file with a .php extension or a disguised one
- File saved in uploadsServer allows PHP to run in that folder
- Attacker opens the file URLCode runs with your site's permissions
- Site taken overRedirects, hijacked forms, blacklisting
- Leads and salesStolen, diverted or blocked
The folder setting turns a single bad upload into a full takeover.
How to check if your site has it
Only test a site you own or have written permission to test. The safest check is a harmless file that prints text instead of doing anything dangerous.
Create a harmless test file
On your computer, make a file named
fg-exec-test.phpcontaining exactly: <?php echo 'EXECUTED'; ?>Place it in the upload folder
Use SFTP, your host's file manager or SSH to copy it into the uploads folder (for WordPress,
wp-content/uploads). Do not use a public upload form for this test.Open its URL in a browser
Visit https://yoursite.com/wp-content/uploads/fg-exec-test.php. If you see the word EXECUTED, PHP runs there and the problem exists. If you get a download prompt, a 403 or a 404, or you see the raw code, the folder is not executing PHP.
Delete the test file
Remove it straight away, whatever the result.
Look for files that should not be there
List the uploads folder for any
.php,.phtml,.pharor.php5files, and for double extensions such asphoto.jpg.php. Images folders should contain none of these.
How to fix it
The goal has two layers: stop the server running scripts in upload folders, and stop dangerous files being accepted at all. Which snippet you need depends on your web server.
Find out your web server
Ask your host or check Tools > Site Health > Info > Server. Apache or LiteSpeed uses .htaccess. Nginx needs a server config change.
Add an .htaccess file (Apache/LiteSpeed)
Create
wp-content/uploads/.htaccesswith the Apache snippet shown below this block.Or edit the Nginx config (Nginx)
Add the Nginx location block shown below this block before your general PHP location, then reload Nginx. Managed hosts often do this for you on request.
Restrict who can upload
Make sure only trusted roles have the
upload_filescapability, and remove form or file-manager plugins you do not use.
Store uploads outside the web root
Best option: save files in a folder the web server cannot serve directly, and deliver them through a script that checks permissions.
If they must be public, disable execution there
Use the Apache or Nginx snippet below for your upload directory, and serve it from a separate domain or storage bucket if you can.
Validate on the server
Allow-list extensions and check the real MIME type. Rename files to a random name with a fixed safe extension. Never trust the file name or the browser-sent type.
Set safe file permissions
Files should be 644 and folders 755, owned by a user that cannot edit core code.
Nothing to configure for core uploads
Shopify hosts files on its own CDN and does not run uploaded code on your behalf, so this issue does not apply to its file storage.
Check third-party apps
If an app collects uploads and stores them on its own server, ask the vendor how files are validated and whether upload storage can run scripts.
Nothing to configure
Wix stores uploads on its own infrastructure and you cannot change server execution rules. Review any custom code or third-party upload apps instead.
Nothing to configure
Squarespace manages hosting and file storage. If you use an external form or file-upload tool, check how that vendor stores files.
# Stop PHP and similar scripts running in this folder
<FilesMatch "(?i)\.(php|php[0-9]|phtml|phar|pl|py|cgi|sh)$">
Require all denied
</FilesMatch>
# Also turn the PHP engine off where the host allows it
<IfModule mod_php.c>
php_flag engine off
</IfModule>
Options -ExecCGI
RemoveHandler .php .phtml .php5
RemoveType .php .phtml .php5location ~* ^/wp-content/uploads/.*\.(php|php[0-9]|phtml|phar)$ {
deny all;
return 403;
}Before
- A .php file in uploads runs as code
- Any upload flaw leads to full takeover
- No rule on which file types are saved
After
- Script files in uploads return 403
- A bad upload is just an inert file
- Only allow-listed file types are accepted and renamed
How to confirm it's fixed
Repeat the harmless test file
Upload
fg-exec-test.phpagain and open its URL. You should get a 403 or 404, not the word EXECUTED.Check normal files still work
Open a few existing images and PDFs from the uploads folder to make sure they still load.
Test your upload forms
Try uploading an allowed file (a small JPG) and a blocked one (a .php or .exe file). The first should work and the second should be refused with a clear message.
Delete the test file
Remove it again and clear any server or CDN cache for the folder.
How to prevent it happening again
- Keep CMS core, plugins and themes updated, since most malicious uploads come through known flaws
- Remove plugins and form add-ons you no longer use
- Allow-list file types on every upload form and cap file size
- Give editors and contributors only the permissions they need
- Turn on two-factor login for admin accounts
- Keep off-site backups so you can restore a clean copy
- Run a scheduled malware or file-integrity scan that alerts you to new script files in uploads
- After any server move or host change, repeat the test file check
| Layer | What it does | Stops |
|---|---|---|
| Server rule (this guide) | Refuses to run scripts in the upload folder | A bad file turning into running code |
| File type allow-list | Accepts only expected extensions and MIME types | Most malicious files at the door |
| Random renaming | Saves files with a safe fixed extension | Double-extension tricks |
| Updates and permissions | Closes known flaws and limits who can upload | The ways attackers get in |
| Scanning and backups | Spots new bad files and lets you restore | Long-lived hidden infections |
How FunnelGuard handles this
This issue is outside what FunnelGuard checks. FunnelGuard runs your real customer journeys, such as lead forms, checkouts and booking buttons, and checks the steps, the tracking hits and whether test leads arrive. It does not inspect your server's folder settings or look for malicious files.
Questions people ask
Why is PHP running in my uploads folder?
Most web servers are set to run PHP for any file ending in .php, in any folder. Unless you add a rule that blocks this in the uploads directory, a PHP file placed there will execute when someone opens its URL.
How do I disable PHP execution in the WordPress uploads folder?
On Apache or LiteSpeed, add an .htaccess file in wp-content/uploads that denies access to .php, .phtml and .phar files. On Nginx, add a location block that returns 403 for those extensions, then reload Nginx. Test with a harmless file afterwards.
How can I test if my upload directory executes PHP?
Copy a file containing <?php echo 'EXECUTED'; ?> into the folder using SFTP, open its URL, and see whether the word appears. If it does, PHP runs there. Delete the file straight after, and only test sites you own or have permission to test.
Is a .htaccess file enough to secure file uploads?
No. It is one layer that stops uploaded scripts running, but you should also allow-list file types, rename uploaded files, keep software updated and limit who can upload. It does nothing on Nginx, which ignores .htaccess files.
What is a webshell?
A webshell is a small script an attacker uploads to a website so they can run commands on the server from a browser. It often hides in the uploads folder with an innocent-looking name. It only works if the server is allowed to execute it.
I found a strange PHP file in wp-content/uploads. What should I do?
Assume the site is compromised. Save a copy for evidence, delete the file, change all admin, hosting, database and FTP passwords, update everything, and scan for other changes. Find the entry point or it will happen again, and ask your host for help if needed.
Does FunnelGuard detect executable upload folders?
No. FunnelGuard tests customer journeys, tracking and lead delivery, not server security settings. Use a vulnerability scanner, a malware scanner or a security review for this issue.