WPCode 403 Forbidden on save: the firewall read your snippet as an attack
I pasted a snippet into WPCode and clicked save. Hostinger’s firewall answered with a 403. The snippet never saved.
Short version for the skimmers. A WPCode 403 Forbidden on save almost never comes from WordPress or from WPCode. It comes from your host’s web application firewall, which reads the snippet you just submitted, sees PHP function calls inside a form field, and blocks it as an attack. The code is fine. The firewall cannot tell you apart from someone uploading a web shell. You can ask the host for a narrow exception, or do what I did and move the code into a must-use plugin file, which never goes through that form at all.
KEY FACTS
A WAF block arrives as HTTP 403 before WordPress or the snippet plugin sees the request. The plugin never gets a chance to show its own error.
Six of my WPCode snippets saved without a problem. The one with file functions in it was refused with a 403.
The OWASP Core Rule Set flags PHP in form fields at paranoia level 1, its default. Rule 933150 matches high-risk function names such as base64_decode, file_get_contents and shell_exec.
Hostinger ships ModSecurity enabled by default. Its own help article turns it off for the whole website, not for one rule.
My fix was one .php file uploaded into wp-content/mu-plugins/. The site now runs 10 of my own must-use plugins, all uploaded that way.
How a firewall 403 differs from a WordPress error
A firewall answers before PHP runs. So its reply carries nothing from WordPress. No admin notice, no plugin message, no JSON error code. When WordPress or WPCode refuses something, the refusal comes from WordPress code, and it looks like it.
The better clue is which snippets fail. I set this site up with several WPCode snippets, and six of them saved with no trouble. They force application passwords on, relay the auth header, open Shortcoder and Rank Math fields to the REST API, turn off sitemap caching and send a signup notification. The one that failed had file functions in it. Same admin, same plugin. The only thing that changed was the text of the code.
Why a WPCode 403 Forbidden comes from the firewall
Hostinger runs ModSecurity, an open source web application firewall, and says plainly that it is enabled by default and recommends keeping it on. Firewalls like this inspect every request against a list of attack patterns. One of the most common pattern sets is the OWASP Core Rule Set, and its PHP rules live in one file, REQUEST-933-APPLICATION-ATTACK-PHP.conf.
Reading that file explains the whole thing. The rules inspect request arguments, which includes every field of a form you submit. A snippet editor is a form field. So your code arrives in exactly the place the rules are watching for injected PHP.
| Rule | Message in the rule file | What it matches |
|---|---|---|
| 933100 | PHP Injection Attack: PHP Open Tag Found | <?php followed by whitespace |
| 933150 | PHP Injection Attack: High-Risk PHP Function Name Found | Names from a list, such as base64_decode, file_get_contents, shell_exec, plus a bracket in the same field |
| 933160 | PHP Injection Attack: High-Risk PHP Function Call Found | Calls such as eval, exec, system, fopen |
| 933200 | PHP Injection Attack: Wrapper scheme detected | Stream wrappers such as phar:// and zip:// |
All four run at paranoia level 1, the first detection level and the rule set’s default. A snippet that reads or writes files trips the default rules. You do not need a strict setup to hit this.
One honest limit. Hostinger does not publish which rules it runs or how it has tuned them. So I cannot tell you which rule fired on my save. What I can say is that the Core Rule Set’s PHP rules target exactly the kind of code that failed.
The same firewall turned up again weeks later, on a different path. My automation tried to create a redirect through Rank Math’s own API route and got a 403 with a CAPTCHA page, twice. Not a PHP snippet that time, but the same lesson. When a 403 comes back with no WordPress in it, look at the layer in front of WordPress first.
How to confirm it is the firewall
The clearest guide I found is written for a different snippet plugin. It is Themeisle’s page for Woody Code Snippets, and the method carries over to WPCode unchanged. Its key line: the failure depends on the content of the snippet, not on whether the code runs.
So test the content. Save a copy of the snippet with the suspicious line removed. If that saves, put the line back inside a comment and save again. If the commented version also fails, you have your answer. A comment never runs. Only a rule that reads raw text would object to it.
Then open your browser’s developer tools, go to the Network tab and save once more. The failed request shows status 403. Write down the time. Your host needs it.
Three ways out, compared
| Option | Who does it | WAF still on for the site? | The catch |
|---|---|---|---|
| Ask the host for a rule exception | The host, from the audit log | Yes | You need the time of the block, and you wait on support |
| Turn ModSecurity off in .htaccess | You | No | Removes the firewall from every form on the site |
| Move the code to a must-use plugin | You, once, with file access | Yes | No deactivate button if the file has a typo |
Themeisle’s advice for the first route is the right shape. Ask for a narrow exception that covers that one rule on authenticated admin requests, and do not ask the host to switch the firewall off. Give them the time and the URL so they can find the entry.
Why I did not turn ModSecurity off
Hostinger’s article does give a way to disable it. Add these two lines to the site’s .htaccess file:
SecFilterEngine Off
SecFilterScanPOST Off
Two problems. The first is scope. By Hostinger’s own description, those lines disable ModSecurity for your website. Every contact form, every login form, every comment box loses the filter, so that one administrator can save one snippet.
The second is that I am not sure those lines do anything on a current server. The ModSecurity project’s own migration guide from version 1 to version 2 lists SecFilterEngine as the old name and says to replace it with SecRuleEngine. It gives SecRequestBodyAccess as the replacement for SecFilterScanPOST. My site answers with a LiteSpeed server header, and LiteSpeed’s docs say it has its own ModSecurity engine. I have not tested whether it honours the old names, and I am not going to switch my firewall off to find out.
The fix I use: a must-use plugin
WordPress loads every PHP file it finds directly inside wp-content/mu-plugins/, automatically, on every request. There is no activate step. The WordPress developer handbook calls these must-use plugins.
So the code that would not save as a snippet goes in a file instead. Same code, plus a short header:
<?php
/**
* Plugin Name: Site helper
* Description: Code that used to live in a snippet.
*/
defined( 'ABSPATH' ) || exit;
add_action( 'rest_api_init', function () {
register_rest_route( 'sitehelper/v1', '/ping', array(
'methods' => 'GET',
'callback' => function () {
return array( 'ok' => true, 'user_id' => get_current_user_id() );
},
'permission_callback' => '__return_true',
) );
} );
That example registers a harmless ping route under a made-up sitehelper/v1 namespace. Yours will hold whatever the snippet was doing. Then:
- Save it as a .php file on your computer, for example
site-helper.php. - Open your host’s file manager and go to
wp-content/. Createmu-pluginsif it does not exist. - Upload the file into that folder. Not into a subfolder, because WordPress only looks one level deep there.
- Load any page on the site. If it renders, the plugin is running. Check it under Plugins, in the Must-Use tab.
The upload went through where the save did not. That became my standard route for anything with real PHP in it, and it is the route I described in the full write-up of how this site runs itself. Ten of my own must-use plugins have gone onto this site the same way.
The one thing to respect is the missing off switch. A must-use plugin cannot be deactivated from the admin. If a typo in the file breaks the site, you fix it by renaming or deleting the file in the file manager. Keep that tab open the first time you upload.
Where this fits with the other WordPress walls
This is the third wall I hit getting an API client to work on shared hosting, and they look alike from the outside. The missing application passwords panel was a filter. The stripped Authorization header was a 401 that had nothing to do with the password. This one is a 403 that has nothing to do with WordPress permissions. In each case the error message pointed at the wrong layer.
The habit that helped: before changing anything, ask which layer produced the response. A WordPress error is JSON or an admin page. A bare server page came from in front of WordPress.
FAQ
Why does WPCode show a 403 instead of its own error message?
Because the request never reached WPCode. The firewall sits in front of WordPress, reads the form you submitted, and answers on its own. A 403 page with no WordPress styling is the sign that something upstream of PHP made the call.
Is my snippet actually dangerous?
Probably not. The firewall is matching patterns, not reading intent. A snippet that writes a file looks a lot like an attacker uploading a web shell, because both send PHP function calls in a form field. The rule cannot tell an administrator from an attacker by the text alone.
Should I just turn ModSecurity off?
I would not. Hostinger’s own method switches it off for the entire website, which removes protection from every form on the site to fix one save in the admin. A must-use plugin or a narrow exception from your host solves the same problem without that trade.
Does moving the code to a must-use plugin make it less safe?
No. It is the same code running in the same WordPress. The difference is how it gets onto the server. The trade is that a must-use plugin has no deactivate button, so a typo in it can take the site down until you rename the file.
How do I find out which rule blocked me?
Ask your host. Note the exact time of the failed save, then ask them to check the firewall audit log for that time and URL and tell you the rule ID. With the ID they can write an exception for that one rule on admin requests.
The short version
A WPCode snippet that fails to save with a bare 403 page was blocked by the host’s firewall, not by WordPress. The firewall reads PHP function calls in a form field as an attack. Prove it by saving the suspect line inside a comment. Then either ask your host for an exception on that one rule, or put the code in a file in wp-content/mu-plugins/ and leave the firewall alone.
Everything I moved into must-use plugins, and why, is in how I let Claude run this WordPress site.
Stay in the loop.
No spam, just signal.
I send one email when I publish something worth reading. Stock deep dives, new projects, tech breakdowns, and what I'm learning from building in public.
Free forever. Unsubscribe anytime. I respect your inbox.