Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions class.jetpack-heartbeat.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,12 @@ public static function generate_stats_array( $prefix = '' ) {
$return["{$prefix}plugins"] = implode( ',', Jetpack::get_active_plugins() );
$return["{$prefix}manage-enabled"] = true;

$xmlrpc_errors = Jetpack_Options::get_option( 'xmlrpc_errors', array() );
if ( $xmlrpc_errors ) {
$return["{$prefix}xmlrpc-errors"] = implode( ',', array_keys( $xmlrpc_errors ) );
Jetpack_Options::delete_option( 'xmlrpc_errors' );
}

// Missing the connection owner?
$connection_manager = new Manager();
$return["{$prefix}missing-owner"] = $connection_manager->is_missing_connection_owner();
Expand Down
31 changes: 31 additions & 0 deletions class.jetpack.php
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,8 @@ private function __construct() {
};
} );

add_action( 'jetpack_verify_signature_error', array( $this, 'track_xmlrpc_error' ) );

$this->connection_manager = new Connection_Manager();
$this->connection_manager->init();

Expand Down Expand Up @@ -4306,6 +4308,35 @@ function admin_notices() {
<?php endif;
}

/**
* We can't always respond to a signed XML-RPC request with a
* helpful error message. In some circumstances, doing so could
* leak information.
*
* Instead, track that the error occurred via a Jetpack_Option,
* and send that data back in the heartbeat.
* All this does is increment a number, but it's enough to find
* trends.
*
* @param WP_Error $xmlrpc_error The error produced during
* signature validation.
*/
function track_xmlrpc_error( $xmlrpc_error ) {
$code = is_wp_error( $xmlrpc_error )
? $xmlrpc_error->get_error_code()
: 'should-not-happen';

$xmlrpc_errors = Jetpack_Options::get_option( 'xmlrpc_errors', array() );
if ( isset( $xmlrpc_errors[ $code ] ) && $xmlrpc_errors[ $code ] ) {
// No need to update the option if we already have
// this code stored.
return;
}
$xmlrpc_errors[ $code ] = true;

Jetpack_Options::update_option( 'xmlrpc_errors', $xmlrpc_errors, false );
}

/**
* Record a stat for later output. This will only currently output in the admin_footer.
*/
Expand Down
1 change: 1 addition & 0 deletions packages/options/legacy/class.jetpack-options.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ public static function get_option_names( $type = 'compact' ) {
'static_asset_cdn_files', // (array) An nested array of files that we can swap out for cdn versions.
'mapbox_api_key', // (string) Mapbox API Key, for use with Map block.
'mailchimp', // (string) Mailchimp keyring data, for mailchimp block.
'xmlrpc_errors', // (array) Keys are XML-RPC signature error codes. Values are truthy.
);

case 'private':
Expand Down