Repository navigation
Unslash cookies forwarded by async requests - #148
Open
bealinawaz wants to merge 1 commit into
Open
bealinawaz wants to merge 1 commit into
bealinawaz wants to merge 1 commit into
Conversation
WordPress slashes $_COOKIE in wp_magic_quotes(), so each chained async request added another layer of backslashes to cookie values until the Cookie header was too large. Cookies are only unslashed once WordPress has slashed them, so requests dispatched earlier (for example on plugins_loaded) keep their values.
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 #147
Problem
WordPress adds slashes to
$_COOKIEinwp_magic_quotes().WP_Async_Request::get_post_args()passes$_COOKIEas-is, so cookie values with quotes or backslashes are sent with extra backslashes. When the receiving request dispatches again, asWP_Background_Processdoes, they are slashed again, and the backslashes double on every hop until the Cookie header is too large.Fix
Unslash the cookies, but only once WordPress has slashed them.
wp_magic_quotes()runs afterplugins_loaded, just beforesanitize_comment_cookiesfires, so a request dispatched earlier still has the raw values. Unslashing those would strip real backslashes: PHP decodes a cookie sent asC:%5CtempintoC:\temp, which a plainwp_unslash()would turn intoC:temp. So the fix checksdid_action( 'sanitize_comment_cookies' ).The
{identifier}_post_argsfilter now receives unslashed cookies, so code that worked around this withwp_unslash()in that filter can drop it.Result
Tested on a local site (WordPress 7.1.4, PHP 8.5) with an async request whose
handle()dispatches again, and ajson_cookie={"a":"b"}; dir=C:%5Ctempcookie:init).initor onplugins_loaded, andC:\tempis kept.New tests in
tests/Test_WP_Async_Request.php:test_dispatch_sends_unslashed_cookiesfails on master and passes with this change.test_dispatch_before_magic_quotes_keeps_cookiescovers an early dispatch, and fails with a plainwp_unslash().make test-unit(single site and multisite) andmake test-stylepass locally.