All ArticlesHosting2026-11-09T17:48:15+08:00

Block PHP Execution in wp-content/uploads Before the Next Plugin Upload Flaw

Arbitrary file upload bugs in popular plugins like Contact Form 7 turn into remote code execution when the web server runs any .php file dropped into the uploads folder. After reading, you will be able to deny PHP execution there on Apache, LiteSpeed, and Nginx, test that the rule works, and recheck it after migrations or server rebuilds.

When a plugin advisory says "unauthenticated arbitrary file upload," most site owners update the plugin and move on. That is the right first step, but it skips the part that makes these bugs so damaging. A file upload flaw only becomes remote code execution (RCE, meaning an attacker can run their own code on your server) if the web server agrees to execute whatever PHP file lands in wp-content/uploads. On many default setups, it does.

The recent Contact Form 7 advisory makes a useful case study. According to the published advisory, CVE-2026-114432 affects versions 6.2 through 6.2.3 and carries a CVSS score of 9.8. It comes from improper file type validation combined with a cleanup failure, which lets unauthenticated visitors upload files such as PHP scripts that the server can then execute. The fix is version 6.2.4 or later. What follows is the usual post-mortem pattern for this class of incident, not a write-up of one specific site. The fix at the end applies to whichever plugin has the next flaw.

What the first signs usually look like

The first report is rarely "my site was hacked through a contact form." It is usually something indirect. Outbound spam fills the mail queue. The hosting account hits resource limits. An admin user appears that nobody created. Some visitors get redirected to a site the owner has never seen, or a malware scanner flags a file the owner does not recognize.

Support tends to see the symptom first and the cause last. By the time someone opens a ticket, the vulnerable plugin may already be updated, because auto-updates ran or the owner read the advisory. That is why "I already updated, so I'm fine" is a common and risky assumption. The update closes the door. It does not remove anything that came through while the door was open.

How the investigation usually runs

The quickest first check is the filesystem. On a typical WordPress site, the uploads folder holds media and plugin-generated assets, not executable code. Running find wp-content/uploads -type f -name '*.php' from the site root lists every PHP file in there. A few may be harmless, such as an empty index.php some plugins add to stop directory listing. Read anything else before trusting it. Webshells (small scripts that accept commands over HTTP) are often short, obfuscated, or named to look like core files.

Next, match the file's modification timestamp against the web server access logs. If a suspicious PHP file was created at 14:22:10, search the access logs for POST requests around that window. You will usually find an unauthenticated hit to an AJAX or REST endpoint (such as wp-json or admin-ajax.php), followed seconds later by a GET request directly targeting the newly planted PHP file inside wp-content/uploads/.

That single direct GET request is all it takes to trigger execution. Once run, the shell reads database credentials from wp-config.php, drops secondary backdoors in root or wp-includes/, or injects spam redirects into .htaccess.

Updating the vulnerable plugin eliminates the entry vector, but web server-level hardening ensures that even if an arbitrary file lands on disk, the server refuses to run it.

How to block PHP execution in uploads

Media folders should only serve static content. Implementing this requires web server configuration tailored to your stack.

1. Apache and LiteSpeed (.htaccess)

If you are running Apache or LiteSpeed (including OpenLiteSpeed with rewrite rules enabled), drop a dedicated .htaccess file directly inside the wp-content/uploads/ directory:

# wp-content/uploads/.htaccess
<FilesMatch "(?i)\.(php|phtml|php3|php4|php5|php7|php8|phar|inc)$">
    <IfModule mod_authz_core.c>
        Require all denied
    </IfModule>
    <IfModule !mod_authz_core.c>
        Order deny,allow
        Deny from all
    </IfModule>
</FilesMatch>

Note: For Apache, ensure AllowOverride Limit or AllowOverride All is enabled in your virtual host configuration. If overrides are disabled globally, rules inside .htaccess will be ignored silently.

2. Nginx

Nginx does not read .htaccess files. You must enforce the block inside the virtual host server { ... } block, placed before your general PHP-FPM processing block (location ~ \.php$):

# Block script execution inside uploads
location ~* ^/wp-content/uploads/.*\.php$ {
    deny all;
    return 403;
}

If you want comprehensive directory hardening across your entire WordPress installation:

# Deny direct PHP execution across uploads and includes
location ~* ^/(?:wp-content/uploads|wp-includes)/.*\.php$ {
    deny all;
    return 403;
}

Test and reload Nginx:

nginx -t && systemctl reload nginx

Testing the rule

Never assume a hardening directive is working without testing it directly:

  1. Create a dummy test file inside your uploads directory:
    echo "<?php echo 'sec-check'; ?>" > wp-content/uploads/sec-test.php
    
  2. Request the file locally using curl:
    curl -I https://localhost/wp-content/uploads/sec-test.php
    
  3. Verify the HTTP response code:
    • Expected: 403 Forbidden (or 404 Not Found).
    • Vulnerable: 200 OK (especially if executing or serving the raw script contents).
  4. Remove the test file immediately:
    rm wp-content/uploads/sec-test.php
    

Hardening the media path at the web server layer turns an otherwise critical zero-day Remote Code Execution into an inert, unexecutable file on disk.