api: throw when the JSON request body cannot be encoded - #857
Merged
dannyvankooten merged 1 commit intoSep 24, 2026
Merged
Conversation
Passing json_encode()'s false return value to wp_remote_request() fatals the signup request. Co-authored-by: Cursor <cursoragent@cursor.com>
Member
|
Great catch, Thanks for the PR @robertstaddon! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #856
Summary
MC4WP_API_V3_Client::request()set the HTTP body to the raw return value ofjson_encode(). When the subscribe payload cannot be encoded, that return value is booleanfalse.wp_remote_request()passes it toWpOrg\Requests\Transport\Curl::request(), which requiresarray|stringand throwsWpOrg\Requests\Exception\InvalidArgument.That exception is not an
MC4WP_API_Exception, solist_subscribe()does not catch it and the form POST fatals duringinit. No other plugin is required.mc4wp_sanitize_deep()keeps invalid UTF-8, and itssubstr($value, 0, 1024)cut can split a multibyte character. Either value reaches this method on a stock install.This encodes POST, PUT, and PATCH bodies with
wp_json_encode(), which repairs invalid UTF-8 before encoding. If the result is still not a string, it throwsMC4WP_API_Exceptionand does not callwp_remote_request(). Aftermc4wp_http_request_args, a body that is neither a string nor an array throws the same exception.list_subscribe()already turns that into a form error.Test plan
C3 28), with the honeypot empty and a normal User-Agent. The page should show the form error instead of a fatal.mc4wp_http_request_argscallback that leavesbodyas a JSON string still sends the request.Made with Cursor