The Code Snippets 403 That Comes From Your Host’s Firewall, Not WordPress

Date:

You change a few lines in a snippet, press Save, and get “Could not update snippet. Request failed with status code 403”. Press Save on the unchanged snippet and it works. Your login is fine. Something between you and WordPress is reading the code itself.

The short answer: a Code Snippets 403 that appears only when a snippet’s code changes is a web application firewall at your host, not WordPress and not the plugin. It inspects every request body for patterns that look like code injection, and PHP you write on purpose looks exactly like that. Prove it by re-saving the unchanged snippet, find the line by comparing with the last version that saved, and rewrite that line with an equivalent the firewall leaves alone. If you’d rather not work around it, ask the host to exclude the rule for the plugin’s save path.
Finding what the firewall objects to in a refused snippet saveThree checks, each ruling one cause in or out
1. Re-save unchanged

Saves? Login and role are fine: the new code is what is refused.

2. Compare with last save

Only the changed lines matter. One holds the pattern it matched.

3. Rewrite that line

Use an equivalent it leaves alone. Save, then read the code back.

The lasting fix is the host's: exclude the matching rule for the plugin's save path only.

The symptom: a Code Snippets 403 that depends on what you typed

The Code Snippets plugin saves through the WordPress REST API, so the failure looks the same in two places:

  • In wp-admin, the editor shows “Could not update snippet. Request failed with status code 403”.
  • Over REST, a POST to the snippet’s route answers 403 Forbidden, often with a plain host error page instead of WordPress’s usual JSON.

That second detail is the first clue. A refusal from WordPress itself comes back as JSON with a code such as rest_forbidden. A bare page in the host’s own style means the request never reached WordPress.

On the test site this happened on a WordPress multisite behind a managed host. Over a week, five different snippet changes were refused. Each one was found and fixed with the steps below.

1. Re-save the unchanged snippet

Open the snippet, undo your edit (or reload the editor without saving), and press Save.

  • It saves: your account, its permissions and the plugin are all fine. The only difference between the request that worked and the one that failed is the code in its body. Go to step 2.
  • It fails too: this is not the firewall’s content rules. Check that you are still signed in, that your role can edit snippets, and whether a security plugin is blocking the REST API (a 401 from the REST API is a different problem with its own checks).

On the test site the unchanged code saved every time, and the changed code was refused every time, three tries in a row. Nothing else was different.

If the unchanged code saves and the changed code doesn’t, the code is what is being judged.

2. Compare with the last version that saved

The firewall doesn’t say which rule matched. You find it by difference: put the refused version next to the last one that saved and look only at the lines that changed. On the test site every refusal came down to one of these:

What the new code containedRefusedThe rewrite that saved
PHP’s globals array, used twice to pass a flag between functions2026-10-11a function holding a static variable
one call to a regular-expression split2026-10-15strtok() over the same text
a comment that named the PHP open tag and an HTML page-head tag, written as tags2026-10-18the same comment in words (“the PHP open tag”)
a style block printed straight from PHP2026-10-11 (likely)the same CSS through wp_add_inline_style()
a raw SQL query reading a server variable2026-10-18 (suspected)the database layer’s own helper method

Two things in that list surprise people. Comments count: the firewall reads the raw text of the request, so a tag written inside a comment is matched like any other. And the request arrays count: reading form input or the query string directly through PHP’s built-in request arrays looks, to the firewall, like code that handles untrusted input.

The firewall reads the raw text of the request, comments included.

3. Rewrite the line with an equivalent the firewall leaves alone

Each pattern has a plain WordPress or PHP equivalent. None of them changes what the snippet does.

Pass state between functions with a static variable, not the globals array:

function myprefix_flag( $set = null ) {
    static $flag = false;
    if ( null !== $set ) {
        $flag = $set;
    }
    return $flag;
}
Code language: PHP (php)

Read the query string with filter_input(), not the request arrays:

$round = (string) filter_input( INPUT_GET, 'round', FILTER_UNSAFE_RAW );Code language: PHP (php)

Split text with string functions where a regular expression isn’t needed:

$line = strtok( $text, "\r\n" );
while ( false !== $line ) {
    // handle one line
    $line = strtok( "\r\n" );
}
Code language: PHP (php)

Add CSS with wp_add_inline_style(), and let WordPress print the tags:

wp_register_style( 'myprefix', false, array(), '1' );
wp_enqueue_style( 'myprefix' );
wp_add_inline_style( 'myprefix', '.myprefix-box { padding: 8px; }' );
Code language: PHP (php)

Build page markup in JavaScript with DOM calls, so neither the PHP nor its output holds a literal tag. The script itself goes in with wp_add_inline_script() on a handle registered without a file:

var box = document.createElement('div');
box.className = 'myprefix-box';
box.textContent = 'Saved';
container.appendChild(box);
Code language: JavaScript (javascript)

Use the database layer’s helpers ($wpdb->get_col_charset(), $wpdb->prepare() with the table helpers) instead of writing a raw query into the snippet.

After each rewrite, save, then read the code back. A save that answered 200 but stored something else has happened before. On the test site the plugin’s REST route returns the stored code, and comparing it with what you sent byte for byte settles it.

Write the snippet to the firewall’s rules from the start, and it saves on the first try.

4. Write new snippets to these rules from the start

Once the rules are known, they cost almost nothing to follow. On 2026-11-19 a new snippet of about 800 lines went onto the same host in one save. It registers REST routes, builds a whole review page in JavaScript and adds its CSS inline. It was written with no globals array, no request arrays, no regular-expression calls, no raw SQL and no literal tag anywhere, comments included. It read back identical.

Before saving a large change, search it for those five things. Ten seconds of searching beats ten minutes of bisecting a refused save.

5. Or ask the host to exclude the rule

The rewrites are workarounds for a false positive. The lasting fix belongs to the host. Send them:

  • the time of a refused save and the request path, which for this plugin is under /wp-json/code-snippets/ (and /wp-admin/ if you save there);
  • a request to find the matching rule in the firewall log and exclude it for those paths only, rather than switching the firewall off.

Many managed hosts run rule sets such as the OWASP Core Rule Set and can exclude one rule for one path. Some will instead pause the firewall for a few minutes while you save. That works, but you’ll need it again for the next change.

When to rewrite and when to ask the host

  • One refused save, an obvious trigger in the diff: rewrite the line.
  • The trigger is the point of the code (a snippet that must handle raw SQL, or print a tag the browser needs): ask the host for an exclusion.
  • Several people edit snippets on the site: ask the host. Not everyone will remember the rules.
  • Saves fail even unchanged: stop here. It isn’t the firewall’s content rules (step 1).

The short version

A 403 that appears only when a snippet’s code changes comes from the host’s firewall reading the request. Re-save the unchanged snippet to prove it, compare with the last version that saved to find the line, and rewrite it: a static variable for globals, filter_input() for request data, string functions for simple splits, wp_add_inline_style() for CSS, DOM calls for markup, the database helpers for SQL. Read the code back after every save. For a lasting fix, ask the host to exclude the rule for the plugin’s save path.

Frequently Asked Questions

Does this happen with other code snippet plugins?

Yes, with any plugin that saves PHP through a form or a REST request: the firewall sees the same request body whichever plugin sends it. The steps are the same. Only the save path you give the host changes.

Is my code unsafe if the firewall flags it?

Not because of the flag. These rules match patterns that attackers also use, so ordinary code that reads input or prints markup trips them. If you choose a snippet over a plugin, the review of what the code does is still yours.

Can I avoid the firewall by uploading the code as a file?

A must-use plugin uploaded over SFTP never passes through the web request the firewall inspects, so it saves. You lose the snippet plugin’s editor, its on/off switch and its safe mode, and every change needs a file upload. For a one-time change, a short-lived snippet is often the better trade.

Share post:

Subscribe

Popular

More like this
Related

Can AI CLI Conversation History Leak Answers Into a Blind Test?

You use an AI command-line tool to grade or answer hundreds of questions, one fresh run each. Then you find out it keeps every conversation on disk, answer keys included. Is run 200 quietly reading run 199?

Why a Flaky Test Passes Alone and Fails When the Machine Is Busy

Run the test by itself and it passes, every time. Run the whole suite in parallel and it fails, but only some days, and its failure looks exactly like a real bug. In our case the code was fine. The test was waiting on a clock.

Why Multisite Subsite Registration Sends Visitors to the Main Site

You put a "create an account" link on one site of a WordPress multisite. Visitors who click it land on the main site, which either says "Registration has been disabled" or signs them up there instead.

Why Your Pre-Push Hook Gets Slower Every Week, and What Fixes It

Every feature arrives with its tests. Nobody times the hook. Then one day git push takes 25 minutes for a one-line change, and the suite is still running one test at a time on a 16-core machine.