Update the way we generate / verify XMLRPC connections#7115
Update the way we generate / verify XMLRPC connections#7115dereksmart merged 18 commits intomasterfrom
Conversation
Re-factoring Jetpack_XMLRPC_Server::verify_action to look for transients. See discussion in p2-p7rcWF-lF
Requires D5453
zinigor
left a comment
There was a problem hiding this comment.
Great work, thank you! I have tested it, seems to work fine! Plus, I have added some unit tests that cover edge cases.
There are several things that worry me here:
- transients can fail on save, I have added a check in case we can't save a transient, but it needs proper handling - especially when
generate_secretsgets called frombuild_connect_url, we're not really expecting it to fail anywhere. Should we throw a fatal if a transient doesn't get saved? - transients can disappear faster than their expiration time, they aren't a reliable storage solution. Do you think that's a potential problem? I know that it's probably fine because the time slot is only 10 minutes now, but still it's something to think about.
|
Perhaps we can use a generic option ( rather than a Jetpack Option ) instead of a transient. |
| 'fallback_no_verify_ssl_certs', | ||
| ) | ||
| ); | ||
|
|
| public function generate_secrets( $action, $exp = 600 ) { | ||
| $secret = wp_generate_password( 32, false ) // secret_1 | ||
| . ':' . wp_generate_password( 32, false ) // secret_2 | ||
| . ':' . ( time() + $exp ) // eol ( End of Life ) |
per a Slack conversation with @zinigor.
class.jetpack.php
Outdated
| Jetpack_Options::delete_option( | ||
| array( | ||
| 'register', | ||
| 'authorize', |
There was a problem hiding this comment.
Did you mean secrets here as well?
There was a problem hiding this comment.
Thanks for catching that!
| * @author zinigor | ||
| * @covers Jetpack::generate_secrets | ||
| */ | ||
| function test_generate_secrets_works_with_filters() { |
zinigor
left a comment
There was a problem hiding this comment.
I have fixed two minor issues and left some questions. But otherwise everything seems to work as it's supposed to, thanks!
class.jetpack.php
Outdated
| . ':' . get_current_user_id(); // ties the secrets to the current user | ||
| Jetpack_Options::update_option( $action, $secret ); | ||
| return Jetpack_Options::get_option( $action ); | ||
| public static function generate_secrets( $action, $exp = 600 ) { |
There was a problem hiding this comment.
While I don't think we'll ever need it, what do you think about adding the user ID as the second argument to the method? It will let us keep the method interfaces more consistent.
class.jetpack.php
Outdated
| return $secrets[ $secret_name ]; | ||
| } | ||
|
|
||
| public static function get_secret( $action, $user_id ) { |
There was a problem hiding this comment.
Let's use get_secrets here and delete_secrets down there?
class.jetpack.php
Outdated
| public static function get_secret( $action, $user_id ) { | ||
| $secret_name = 'jetpack_' . $action . '_' . $user_id; | ||
| $secrets = Jetpack_Options::get_option( 'secrets', array() ); | ||
| if ( isset( $secrets[ $secret_name ] ) ) { |
There was a problem hiding this comment.
What do you think about checking for expiration here and deleting the secret if it has expired? Currently it's sort of backwards: we check for expiration time after calling generate_secrets, when it should (and does, i think) guarantee secret freshness.
3cb6dfb to
f6517ef
Compare
…Options instead of Jetpack_Options to avoid any cacheing issues while generating / validating secrets.
…zinigor Added new unit tests to cover errors.
|
Awesome job, thank you! |
zinigor
left a comment
There was a problem hiding this comment.
Uh oh! Just got a fatal error trying to connect:
PHP Fatal error: Uncaught Error: Class 'Jetpack_Sync_Options' not found in /wordpress/wp-content/plugins/jetpack/class.jetpack.php:4576
Stack trace:
#0 /wordpress/wp-content/plugins/jetpack/class.jetpack.php(4690): Jetpack::generate_secrets('register')
#1 /wordpress/wp-content/plugins/jetpack/class.jetpack.php(2950): Jetpack::register()
#2 /wordpress/wp-content/plugins/jetpack/class.jetpack.php(3709): Jetpack::try_registration()
#3 /wordpress/wp-content/plugins/jetpack/_inc/lib/admin-pages/class.jetpack-admin-page.php(113): Jetpack->admin_page_load()
#4 /wordpress/wp-includes/class-wp-hook.php(298): Jetpack_Admin_Page->admin_page_load('')
#5 /wordpress/wp-includes/class-wp-hook.php(323): WP_Hook->apply_filters(NULL, Array)
#6 /wordpress/wp-includes/plugin.php(453): WP_Hook->do_action(Array)
#7 /wordpress/wp-admin/admin.php(212): do_action('load-toplevel_p...')
#8 {main}
thrown in /wordpress/wp-content/plugins/jetpack/class.jetpack.php on line 4576
Using `require_once` will only be a temporary measure because for 5.0 we also plan to move Jetpack_Sync_Options methods into Jetpack_Options.
|
Tested very well for the following:
Thank you Rocco. 🐑 ! |
* Changelog: first pass at a changelog for 5.0 * Changelog: delete 4.9 testing list. * Changelog: update minimum WP version to match ver. in jetpack.php Fixes #7158 * Changelog: add #6051 * Changelog: add #6753 * Changelog: add #6928 * Changelog: add #6964 * Changelog: add #7014 * Changelog: add #7057 * Changelog: add #7060 * Changelog: add #7068 * Changelog: add #7070 * Changelog: add #7072 * Changelog: add #7071 * Changelog: add release date and post shortlink. * Changelog: add #7094 * Changelog: add #7100 * Changelog: add #7108 * Changelog: add #7113 * Changelog: add #7123 * Changelog: add #7135 * Changelog: add #7143 * Changelog: add #7151 * Changelog: add #6996 * Changelog: add #7105 * Changelog: add #7132 * Changelog: add #7166 * Changelog: fix typo in 4.9 changelog. * Changelog: remove older releases' changelogs. @see p1HpG7-42e-p2 * Changelog: add #7090 * Changelog: add #7095 * Changelog: add #7112 * Changelog: add #7115 * Changelog: add #7122 * Changelog: add #7137 * Changelog: add #7138 * Changelog: add #7140 * Changelog: add #7154 * Changelog: add ##7155 * Changelog: add #7163 * Changelog: add #7167 * Changelog: add #7171 * Changelog: add #7180 * Changelog: add #7181 * Changelog: add #7183 * Changelog: add #7184 * Changelog: add #7189 * Changelog: add #7191 * Changelog: add #7193 * Changelog: add #7198 * Changelog: add #7200 * Changelog: add #7209 * Changelog: add #7212 * Testing list: add instructions for #7115 * Changelog: add #7188 * Changelog: add #7205 * Changelog: add #7225 * Changelog: add #6872 * Changelog: add #7107 * Changelog: add #7118 * Changelog: add #7142 * Changelog: add #7170 * Changelog: add #7210 * Changelog: add #7218 * Changelog: add #7232 * Changelog: add #7211 * Changelog: add #7213 * Changelog: add #7229 * Changelog: add #7230 * Changelog: add #7214 * Draft changelog for 5.0 * Changelog updates: 2nd pass at a clearer changelog. - Fix typos. - Use consistent tense and tone across all changelog. - Remove unclear items. * Changelog: add #7026 * Changelog: add #7058 * Changelog: add #7125 * Changelog: add #7249 * Changelog: add #7185 * add mentions of image widget migration * Changelog: add info about new output for CLI command. * Changelog: add WP version number matching the new Image Widget.
Fixes #6879 and #6882 and ensures that each verification secret is unique.
Testing instructions:
Proposed changelog entry for your changes:
Fixes a bug that causes connection errors.