Sync: say why the dedicated-request URL check reads the request raw - #51348
Sync: say why the dedicated-request URL check reads the request raw#51348Nikschavan wants to merge 3 commits into
Conversation
|
Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.
Interested in more tips and information?
|
|
Thank you for your PR! When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:
This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖 Follow this PR Review Process:
If you have questions about anything, reach out in #jetpack-developers for guidance! |
Code Coverage SummaryThis PR did not change code coverage! That could be good or bad, depending on the situation. Everything covered before, and still is? Great! Nothing was covered before? Not so great. 🤷 |
cd0a96f to
1d63a8e
Compare
coder-karen
left a comment
There was a problem hiding this comment.
👋 Thanks for looking into this @Nikschavan .
The nonce sanitization looks to be safe here, and is a similar pattern as used elsewhere in the monorepo in other packages / plugins in a handful of other places (but not in far, far more instances). That said, it shouldn't be needed.
The esc_url_raw changes on the other hand have no security benefit, and can result in a real behavior change.
rest_routeis a REST route path rather than a URL, andesc_url_raw()treats it as one, appending 'http://' if a value reaches$_GETstill percent-encoded. In our case, the strpos would still work, but we're changing the behavior unnecessarily here, potentially dangerously if we then make any further changes later.
The comments could be updated to mention that the value is only substring-matched against a fixed literal; never output or stored (and that can be mentioned to the WP.org reviewers).
Noting as well that the existing comments were added due to a WP.org review itself: p9dueE-8ca-p2 (related PR: #37402)
These files already exist within WP.org for several plugins as the vendor files and have done for some time. So it would seem these were likely from AI reviews not considering the history and context, and given the current state was already approved by them it should warrant some push back here.
wp_verify_nonce() is pluggable, so its input cannot be assumed safe. The dedicated-sync URL checks now go through esc_url_raw(), which preserves the percent-encoding that the following urldecode() relies on.
These fail if the URL is passed through sanitize_text_field(), which strips the percent-encoding the following urldecode() depends on.
1d63a8e to
3f58292
Compare
|
Thank you for the context from the previous review — I did not have it, and it is the strongest point for the reply to .org. I reverted the nonce and |
Proposed changes
phpcs:ignorelines inDedicated_Sendernamed the sniffs but not the reason. They now say it: the value is only substring-matched against a fixed literal, never output or stored.REQUEST_URI/rest_routethroughesc_url_raw(); the last commit reverts that — the nonce lines were a no-op andesc_url_raw()on a route path changes the value without a security gain.Flagged by the WordPress.org plugin review tooling while the standalone Jetpack Stats plugin was under review. The current comments were added for an earlier .org review (p9dueE-8ca-p2, #37402), which approved the code; that context goes into the reply.
Related product discussion/links
Does this pull request change what data or activity we track or use?
No.
Testing instructions
composer phpcs:lint projects/packages/sync/src/class-dedicated-sender.phppasses with the reasons on the two ignores.