Skip to content
FunnelGuard

Fix guide by FunnelsGuard

Uploaded files executable: how to stop PHP running in uploads

OPS-191High impactOther toolBy FunnelGuardPublished Updated
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:

What a successful attack can do to your funnel
  • 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
How an executable upload folder becomes lost leads
  1. Upload form or pluginAccepts a file with a .php extension or a disguised one
  2. File saved in uploadsServer allows PHP to run in that folder
  3. Attacker opens the file URLCode runs with your site's permissions
  4. Site taken overRedirects, hijacked forms, blacklisting
  5. 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.

Test whether uploads can run PHP
  1. Create a harmless test file

    On your computer, make a file named fg-exec-test.php containing exactly: <?php echo 'EXECUTED'; ?>

  2. 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.

  3. 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.

  4. Delete the test file

    Remove it straight away, whatever the result.

  5. Look for files that should not be there

    List the uploads folder for any .php, .phtml, .phar or .php5 files, and for double extensions such as photo.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.

Block script execution in the upload folder
  1. 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.

  2. Add an .htaccess file (Apache/LiteSpeed)

    Create wp-content/uploads/.htaccess with the Apache snippet shown below this block.

  3. 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.

  4. Restrict who can upload

    Make sure only trusted roles have the upload_files capability, and remove form or file-manager plugins you do not use.

Apache / LiteSpeed: put this in the uploads folder's .htaccesshtaccess
# 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 .php5
Nginx: deny scripts in uploads (place before the general PHP block)nginx
location ~* ^/wp-content/uploads/.*\.(php|php[0-9]|phtml|phar)$ {
    deny all;
    return 403;
}
Upload folder behaviour

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

Re-run the test
  1. Repeat the harmless test file

    Upload fg-exec-test.php again and open its URL. You should get a 403 or 404, not the word EXECUTED.

  2. Check normal files still work

    Open a few existing images and PDFs from the uploads folder to make sure they still load.

  3. 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.

  4. Delete the test file

    Remove it again and clear any server or CDN cache for the folder.

How to prevent it happening again

Ongoing habits
  • 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
Layers of protection for uploads
LayerWhat it doesStops
Server rule (this guide)Refuses to run scripts in the upload folderA bad file turning into running code
File type allow-listAccepts only expected extensions and MIME typesMost malicious files at the door
Random renamingSaves files with a safe fixed extensionDouble-extension tricks
Updates and permissionsCloses known flaws and limits who can uploadThe ways attackers get in
Scanning and backupsSpots new bad files and lets you restoreLong-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.

Does FunnelGuard catch this?

Other tool

Needs a different kind of tool.

Stop finding out from your customers

FunnelGuard runs your real forms and checkouts on a schedule, checks the tracking and the leads behind them, and alerts you once, with a screenshot. Try any paid plan free for 3 days.