Security: remove the cron event that checked for https support.

Fix an issue where a cron job ran every 12 hours to check for https support - even when https support was already enabled. The check is now run only when the user visits the Site Health page. Reducing the unneeded requests lowers the impact and load of hosting WordPress sites.

The `wp_update_https_detection_errors` function is deprecated and the `https_detection_errors` option that was previously set by the cron job is no longer maintained. The `pre_wp_update_https_detection_errors` filter is deprecated and replaced by the `pre_wp_get_https_detection_errors` filter  which serves the same function.

Props audrasjb, johnbillion, Michi91.
Fixes #58494.


Built from https://develop.svn.wordpress.org/trunk@56664


git-svn-id: http://core.svn.wordpress.org/trunk@56176 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Adam Silverstein 2023-09-22 19:08:19 +00:00
parent 61ed1cb48e
commit 77582c4be9
6 changed files with 54 additions and 50 deletions

View File

@ -1555,10 +1555,9 @@ class WP_Site_Health {
*/ */
public function get_test_https_status() { public function get_test_https_status() {
/* /*
* Enforce fresh HTTPS detection results. This is normally invoked by using cron, * Check HTTPS detection results.
* but for Site Health it should always rely on the latest results.
*/ */
wp_update_https_detection_errors(); $errors = wp_get_https_detection_errors();
$default_update_url = wp_get_default_update_https_url(); $default_update_url = wp_get_default_update_https_url();

View File

@ -2340,6 +2340,12 @@ function upgrade_640() {
if ( $wp_current_db_version < 56657 ) { if ( $wp_current_db_version < 56657 ) {
// Enable attachment pages. // Enable attachment pages.
update_option( 'wp_attachment_pages_enabled', 1 ); update_option( 'wp_attachment_pages_enabled', 1 );
// Remove the wp_https_detection cron. Https status is checked directly in an async Site Health check.
$scheduled = wp_get_scheduled_event( 'wp_https_detection' );
if ( $scheduled ) {
wp_clear_scheduled_hook( 'wp_https_detection' );
}
} }
} }

View File

@ -387,11 +387,6 @@ if ( ! defined( 'DOING_CRON' ) ) {
add_action( 'init', 'wp_cron' ); add_action( 'init', 'wp_cron' );
} }
// HTTPS detection.
add_action( 'init', 'wp_schedule_https_detection' );
add_action( 'wp_https_detection', 'wp_update_https_detection_errors' );
add_filter( 'cron_request', 'wp_cron_conditionally_prevent_sslverify', 9999 );
// HTTPS migration. // HTTPS migration.
add_action( 'update_option_home', 'wp_update_https_migration_required', 10, 2 ); add_action( 'update_option_home', 'wp_update_https_migration_required', 10, 2 );

View File

@ -5870,3 +5870,41 @@ function _wp_theme_json_webfonts_handler() {
add_action( 'wp_enqueue_scripts', $fn_generate_and_enqueue_styles ); add_action( 'wp_enqueue_scripts', $fn_generate_and_enqueue_styles );
add_action( 'admin_init', $fn_generate_and_enqueue_editor_styles ); add_action( 'admin_init', $fn_generate_and_enqueue_editor_styles );
} }
/**
* Runs a remote HTTPS request to detect whether HTTPS supported, and stores potential errors.
*
* This internal function is called by a regular Cron hook to ensure HTTPS support is detected and maintained.
*
* @since 5.7.0
* @deprecated 6.4.0 The `wp_update_https_detection_errors()` function is no longer used and has been replaced by
* `wp_get_https_detection_errors()`. Previously the function was called by a regular Cron hook to
* update the `https_detection_errors` option, but this is no longer necessary as the errors are
* retrieved directly in Site Health and no longer used outside of Site Health.
* @access private
*/
function wp_update_https_detection_errors() {
_deprecated_function( __FUNCTION__, '6.4.0' );
/**
* Short-circuits the process of detecting errors related to HTTPS support.
*
* Returning a `WP_Error` from the filter will effectively short-circuit the default logic of trying a remote
* request to the site over HTTPS, storing the errors array from the returned `WP_Error` instead.
*
* @since 5.7.0
* @deprecated 6.4.0 The `wp_update_https_detection_errors` filter is no longer used and has been replaced by `pre_wp_get_https_detection_errors`.
*
* @param null|WP_Error $pre Error object to short-circuit detection,
* or null to continue with the default behavior.
*/
$support_errors = apply_filters( 'pre_wp_update_https_detection_errors', null );
if ( is_wp_error( $support_errors ) ) {
update_option( 'https_detection_errors', $support_errors->errors );
return;
}
$support_errors = wp_get_https_detection_errors();
update_option( 'https_detection_errors', $support_errors );
}

View File

@ -86,25 +86,25 @@ function wp_is_https_supported() {
* *
* This internal function is called by a regular Cron hook to ensure HTTPS support is detected and maintained. * This internal function is called by a regular Cron hook to ensure HTTPS support is detected and maintained.
* *
* @since 5.7.0 * @since 6.4.0
* @access private * @access private
*/ */
function wp_update_https_detection_errors() { function wp_get_https_detection_errors() {
/** /**
* Short-circuits the process of detecting errors related to HTTPS support. * Short-circuits the process of detecting errors related to HTTPS support.
* *
* Returning a `WP_Error` from the filter will effectively short-circuit the default logic of trying a remote * Returning a `WP_Error` from the filter will effectively short-circuit the default logic of trying a remote
* request to the site over HTTPS, storing the errors array from the returned `WP_Error` instead. * request to the site over HTTPS, storing the errors array from the returned `WP_Error` instead.
* *
* @since 5.7.0 * @since 6.4.0
* *
* @param null|WP_Error $pre Error object to short-circuit detection, * @param null|WP_Error $pre Error object to short-circuit detection,
* or null to continue with the default behavior. * or null to continue with the default behavior.
* @return null|WP_Error Error object if HTTPS detection errors are found, null otherwise.
*/ */
$support_errors = apply_filters( 'pre_wp_update_https_detection_errors', null ); $support_errors = apply_filters( 'pre_wp_get_https_detection_errors', null );
if ( is_wp_error( $support_errors ) ) { if ( is_wp_error( $support_errors ) ) {
update_option( 'https_detection_errors', $support_errors->errors ); return $support_errors->errors;
return;
} }
$support_errors = new WP_Error(); $support_errors = new WP_Error();
@ -153,41 +153,7 @@ function wp_update_https_detection_errors() {
} }
} }
update_option( 'https_detection_errors', $support_errors->errors ); return $support_errors->errors;
}
/**
* Schedules the Cron hook for detecting HTTPS support.
*
* @since 5.7.0
* @access private
*/
function wp_schedule_https_detection() {
if ( wp_installing() ) {
return;
}
if ( ! wp_next_scheduled( 'wp_https_detection' ) ) {
wp_schedule_event( time(), 'twicedaily', 'wp_https_detection' );
}
}
/**
* Disables SSL verification if the 'cron_request' arguments include an HTTPS URL.
*
* This prevents an issue if HTTPS breaks, where there would be a failed attempt to verify HTTPS.
*
* @since 5.7.0
* @access private
*
* @param array $request The cron request arguments.
* @return array The filtered cron request arguments.
*/
function wp_cron_conditionally_prevent_sslverify( $request ) {
if ( 'https' === wp_parse_url( $request['url'], PHP_URL_SCHEME ) ) {
$request['args']['sslverify'] = false;
}
return $request;
} }
/** /**

View File

@ -16,7 +16,7 @@
* *
* @global string $wp_version * @global string $wp_version
*/ */
$wp_version = '6.4-alpha-56663'; $wp_version = '6.4-alpha-56664';
/** /**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema. * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.