-
Notifications
You must be signed in to change notification settings - Fork 846
Jetpack Connection: Add inline comments when whole input is processed #37392
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Jetpack Connection: Add inline comments when whole input is processed #37392
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 🤖 The e2e test report can be found here. Please note that it can take a few minutes after the e2e tests checks are complete for the report to be available. Once your PR is ready for review, check one last time that all required checks appearing at the bottom of this PR are passing or skipped. Jetpack plugin: The Jetpack plugin has different release cadences depending on the platform:
If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack. |
bindlegirl
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM but maybe @jeherve will have more advice
…verify_json_api_authorization_request
…setup_xmlrpc_handlers
sergeymitr
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code looks great, works as expected 👍
| $request_params_needed_for_auth = array( | ||
| 'data', | ||
| 'jetpack_json_api_original_query', | ||
| 'nonce', | ||
| 'signature', | ||
| 'timestamp', | ||
| 'token', | ||
| ); | ||
| $environment = array_intersect_key( $request_params_needed_for_auth, $_REQUEST ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended,WordPress.Security.ValidatedSanitizedInput.MissingUnslash,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- nonce verification handled later in function and request data are 1) used to verify a cryptographic signature of the request data and 2) sanitized later in function. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This won't work right, for two reasons:
- You need to put
$_REQUESTfirst so it uses the values from the request. - The
$request_params_needed_for_authneeds to have keys 'data', 'nonce', and so on. So either define it like'data' => true,or usearray_flip( $request_params_needed_for_auth ).
As written, $environment will probably be empty. If there's a $_REQUEST[0] or the like, it might be array( 0 => 'data' ) or the like.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch, thanks Brad!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you Brad and Sergey and apologies for any trouble caused.
I decided to keep things simple and removed the whole logic of extracting the auth request params in verify_json_api_authorization_request so we can focus on exactly what the original issue was about.
The debugger related test instructions/unit tests are only applicable for deprecating the input arg in setup_xmlrpc_handlers anyways.
I also audited where we actually use verify_json_api_authorization_request and it looks like it’s mainly under the context of SSO anyways where the $environment is passed here.
The other usage, comes from Jetpack-the-plugin as an action handler for login_form_jetpack_json_api_authorization here
Final PR: #37445
We are adding inline comments in the Connection package to explain cases where the whole
$_POSTinput is used.We are also refactoring
setup_xmlrpc_handlersinManagerclass to avoid using the whole$_POSTinput.Proposed changes:
Jetpack_Signature::sign_current_request: We need the whole$_POSTin order to verify a cryptographic signature of the post data.Automattic\Jetpack\Connection\Manager::internal_verify_xml_rpc_signature: We need the whole$_POSTin order to verify a cryptographic signature of the post data.Automattic\Jetpack\Connection\Manager::setup_xmlrpc_handlers: Deprecate the$request_paramsmethod argument and check for$_GET['for']and$_GET['jetpack']inside the method instead. I've audited the usage of this method and confirmed it's used only by the same class.Other information:
Jetpack product discussion
p9dueE-8ca-p2
Does this pull request change what data or activity we track or use?
No
Testing instructions:
setup_xmlrpc_handlers: I believe the best way to test this change (apart from the code review) would be to use the JP Debugger and confirm the same results for a given site with/without the PR applied. The JP Debugger will make a bunch of REST and XML-RPC requests to the site with/without authentication too. Also make sure to set the site to use the alternate XML-RPC url in order to set thecommsparam is properly checked too.