-
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
Changes from all commits
a24433a
96d39a1
f2e877d
82a5f66
2281c4d
45bd688
d05d62b
fed7693
cb77207
914cd6b
cdbf018
7ea4300
1cbe47d
27fce9d
43180fc
d469817
ebab7e2
b88ccae
ada5a67
369d209
3d68471
1153459
8aa9581
ac19937
1fe0ed0
3090b1a
18b2de3
4ae0f89
4c94ded
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| Significance: patch | ||
| Type: deprecated | ||
|
|
||
| Jetpack Connection Manager: Deprecate `request_params` arg in setup_xmlrpc_handlers method | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -40,9 +40,17 @@ class Authorize_Json_Api { | |
| * @return void | ||
| */ | ||
| public function verify_json_api_authorization_request( $environment = null ) { | ||
| $environment = $environment === null | ||
| ? $_REQUEST // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- nonce verification handled later in function. | ||
| : $environment; | ||
| if ( null === $environment ) { | ||
| $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. | ||
|
Comment on lines
+44
to
+52
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This won't work right, for two reasons:
As written,
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch, thanks Brad!
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 I also audited where we actually use Final PR: #37445 |
||
| } | ||
|
|
||
| if ( ! isset( $environment['token'] ) ) { | ||
| wp_die( esc_html__( 'You must connect your Jetpack plugin to WordPress.com to use this feature.', 'jetpack-connection' ) ); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -111,7 +111,7 @@ public static function configure() { | |
| ); | ||
|
|
||
| $manager->setup_xmlrpc_handlers( | ||
| $_GET, // phpcs:ignore WordPress.Security.NonceVerification.Recommended | ||
fgiannar marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| null, | ||
| $manager->has_connected_owner(), | ||
| $manager->verify_xml_rpc_signature() | ||
| ); | ||
|
|
@@ -161,32 +161,31 @@ public static function configure() { | |
| * Sets up the XMLRPC request handlers. | ||
| * | ||
| * @since 1.25.0 Deprecate $is_active param. | ||
| * @since $$next-version$$ Deprecate $request_params param. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not just deprecated, you removed it entirely. Deprecated would probably mean the parameter still exists, but is no longer used inside the function. Or it's still used but you raise a deprecation message if it's not passed
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Back to deprecated as per @sergeymitr 's suggestion :) |
||
| * | ||
| * @param array $request_params incoming request parameters. | ||
| * @param array|null $deprecated Deprecated. Not used. | ||
| * @param bool $has_connected_owner Whether the site has a connected owner. | ||
| * @param bool $is_signed whether the signature check has been successful. | ||
| * @param Jetpack_XMLRPC_Server $xmlrpc_server (optional) an instance of the server to use instead of instantiating a new one. | ||
| */ | ||
| public function setup_xmlrpc_handlers( | ||
| $request_params, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. While it looks safe to change the function signature, I believe this is something we usually avoid for public methods.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure, updated it as suggested
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry if I'm being too nitpicky here, but can I suggest we go with something like this:
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice suggestion, thanks! the first argument in Also I'd avoid setting it to |
||
| $deprecated, | ||
| $has_connected_owner, | ||
| $is_signed, | ||
| Jetpack_XMLRPC_Server $xmlrpc_server = null | ||
| ) { | ||
| add_filter( 'xmlrpc_blog_options', array( $this, 'xmlrpc_options' ), 1000, 2 ); | ||
|
|
||
| if ( | ||
| ! isset( $request_params['for'] ) | ||
| || 'jetpack' !== $request_params['for'] | ||
| ) { | ||
| if ( $deprecated !== null ) { | ||
| _deprecated_argument( __METHOD__, '$$next-version$$' ); | ||
| } | ||
| // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- We are using the 'for' request param to early return unless it's 'jetpack'. | ||
| if ( ! isset( $_GET['for'] ) || 'jetpack' !== $_GET['for'] ) { | ||
| return false; | ||
| } | ||
|
|
||
| // Alternate XML-RPC, via ?for=jetpack&jetpack=comms. | ||
| if ( | ||
| isset( $request_params['jetpack'] ) | ||
| && 'comms' === $request_params['jetpack'] | ||
| ) { | ||
| // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- This just determines whether to handle the request as an XML-RPC request. The actual XML-RPC endpoints do the appropriate nonce checking where applicable. Plus we make sure to clear all cookies via require_jetpack_authentication called later in method. | ||
| if ( isset( $_GET['jetpack'] ) && 'comms' === $_GET['jetpack'] ) { | ||
| if ( ! Constants::is_defined( 'XMLRPC_REQUEST' ) ) { | ||
| // Use the real constant here for WordPress' sake. | ||
| define( 'XMLRPC_REQUEST', true ); | ||
|
|
@@ -455,9 +454,9 @@ private function internal_verify_xml_rpc_signature() { | |
| } | ||
|
|
||
| $jetpack_signature = new \Jetpack_Signature( $token->secret, (int) \Jetpack_Options::get_option( 'time_diff' ) ); | ||
| // phpcs:disable WordPress.Security.NonceVerification.Missing | ||
| // phpcs:disable WordPress.Security.NonceVerification.Missing -- Used to verify a cryptographic signature of the post data. | ||
| if ( isset( $_POST['_jetpack_is_multipart'] ) ) { | ||
| $post_data = $_POST; | ||
| $post_data = $_POST; // We need all of $_POST in order to verify a cryptographic signature of the post data. | ||
| $file_hashes = array(); | ||
| foreach ( $post_data as $post_data_key => $post_data_value ) { | ||
| if ( ! str_starts_with( $post_data_key, '_jetpack_file_hmac_' ) ) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| Significance: patch | ||
| Type: other | ||
| Comment: Jetpack: Update connection related unit tests | ||
|
|
||
|
|
Uh oh!
There was an error while loading. Please reload this page.