Skip to content

fix: send REST writes as POST with a method override - #467

Merged
imantsk merged 1 commit into
corefrom
fix/rest-method-override-release/core
Aug 28, 2026
Merged

fix: send REST writes as POST with a method override#467
imantsk merged 1 commit into
corefrom
fix/rest-method-override-release/core

Conversation

@TallblokeUK

@TallblokeUK TallblokeUK commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

Draft — targeting core for 3.10.1, and the approach is worth a look before it goes further.

Reported

Cause

The admin talks to the REST API over axios and sends real DELETE and PUT verbs. Many hosts permit only GET and POST, so the request is rejected upstream and never reaches WordPress.

The first reporter suspected missing nonces or auth headers. That part isn't it — X-WP-Nonce is sent correctly. Nothing the plugin does with credentials can help, because the request is refused before WordPress runs.

It worked before 3.10 because the old admin went through admin-post and only ever sent POST. The REST rewrite introduced the verb, which is why it appears "since the update".

Change

Requests using those verbs go out as POST, naming the intended method in X-HTTP-Method-Override. WP_REST_Server::serve_request() reads that header and dispatches the route exactly as it would have, so WordPress sees an identical request — only the verb on the wire changes. One axios request interceptor; GET and POST are untouched.

Verified

Against WordPress 7.0.4 / PHP 8.2.33 / Code Snippets 3.10.0, with a stand-in firewall rejecting DELETE/PUT:

before after
firewall present 403 DELETE, snippet remains 200 POST, snippet deleted
no firewall 200 DELETE 200 POST, snippet deleted

Worth discussing

  • Unconditional, or fall back only on failure? This overrides always, which is simple and predictable. The alternative — try DELETE, retry as POST on rejection — keeps true verbs where they work, but a genuine permission 403 from WordPress is hard to tell from a firewall 403, so it risks pointless retries. I went with the simpler behaviour; happy to swap.
  • Bulk actions delete through the same call, so they're covered, but I haven't specifically exercised a large bulk delete behind the firewall.
  • No changelog entry, consistent with the other fixes.

Fixes #473

Deleting a snippet fails on hosts whose firewall permits only GET and
POST. The browser reports "DELETE 403 (Forbidden)" against
`code-snippets/v1/snippets/`, or a severed connection, and no snippet is
removed. Bulk actions fail the same way, since they delete through the
same call.

The admin talks to the REST API over axios and sends real DELETE and PUT
verbs. Authentication is not the problem — `X-WP-Nonce` is sent, and the
request is rejected before WordPress sees it, so nothing the plugin does
with credentials can help. It worked before 3.10 because the old admin
went through admin-post and only ever sent POST.

Requests using those verbs now go out as POST naming the intended method
in `X-HTTP-Method-Override`, which the REST server reads and dispatches
exactly as it would have. WordPress sees an identical request; only the
verb on the wire changes.

Verified both ways against WordPress 7.0.4 / PHP 8.2.33 / 3.10.0 with a
stand-in firewall rejecting DELETE and PUT. Before: 403 with the snippet
still present. After: 200 and the snippet removed, with and without the
firewall in place.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@TallblokeUK TallblokeUK added the run-tests Trigger automated tests label Aug 27, 2026
@imantsk imantsk added the build Adding this label will trigger the zip build action label Aug 28, 2026
@code-snippets-bot

code-snippets-bot commented Aug 28, 2026

Copy link
Copy Markdown
Contributor

Download and install

📦 code-snippets.3.10.0.zip

@imantsk imantsk removed the run-tests Trigger automated tests label Aug 28, 2026
@imantsk
imantsk marked this pull request as ready for review August 28, 2026 11:37
@imantsk
imantsk merged commit 67fb936 into core Aug 28, 2026
43 checks passed
@imantsk
imantsk deleted the fix/rest-method-override-release/core branch August 28, 2026 11:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

build Adding this label will trigger the zip build action

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants