Make WordPress Core


Ignore:
Timestamp:
02/02/2021 12:08:01 AM (4 years ago)
Author:
flixos90
Message:

Security, Site Health: Make migrating a site to HTTPS a one-click interaction.

Switching a WordPress site from HTTP to HTTPS has historically been a tedious task. While on the surface the Site Address and WordPress Address have to be updated, existing content still remains using HTTP URLs where hard-coded in the database. Furthermore, updating _two_ URLs to migrate to HTTPS is still a fairly unintuitive step which is not clearly explained.

This changeset simplifies migration from HTTP to HTTPS and, where possible, makes it a one-click interaction.

  • Automatically replace insecure versions of the Site Address (home_url()) with its HTTPS counterpart on the fly if the site has been migrated from HTTP to HTTPS. This is accomplished by introducing a https_migration_required option and enabling it when the home_url() is accordingly changed.
    • A new wp_replace_insecure_home_url() function is hooked into various pieces of content to replace URLs accordingly.
    • The migration only kicks in when the Site Address (home_url()) and WordPress Address (site_url()) match, which is the widely common case. Configurations where these differ are often maintained by more advanced users, where this migration routine would be less essential - something to potentially iterate on in the future though.
    • The migration does not actually update content in the database. More savvy users that prefer to do that can prevent the migration logic from running by either deleting the https_migration_required option or using the new wp_should_replace_insecure_home_url filter.
    • For fresh sites that do not have any content yet at the point of changing the URLs to HTTPS, the migration will also be skipped since it would not be relevant.
  • Expose a primary action in the Site Health recommendation, if HTTPS is already supported by the environment, built on top of the HTTPS detection mechanism from [49904]. When clicked, the default behavior is to update home_url() and site_url() in one go to their HTTPS counterpart.
    • A new wp_update_urls_to_https() function takes care of the update routine.
    • A new update_https meta capability is introduced to control access.
    • If the site's URLs are controlled by constants, this update is not automatically possible, so in these scenarios the user is informed about that in the HTTPS status check in Site Health.
  • Allow hosting providers to modify the URLs linked to in the HTTPS status check in Site Health, similar to how that is possible for the URLs around updating the PHP version.
    • A WP_UPDATE_HTTPS_URL environment variable or wp_update_https_url filter can be used to provide a custom URL with guidance about updating the site to use HTTPS.
    • A WP_DIRECT_UPDATE_HTTPS_URL environment variable or wp_direct_update_https_url filter can be used to provide a custom URL for the primary CTA to update the site to use HTTPS.

Props flixos90, timothyblynjacobs.
Fixes #51437.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/default-filters.php

    r50109 r50131  
    177177add_filter( 'the_content', 'prepend_attachment' );
    178178add_filter( 'the_content', 'wp_filter_content_tags' );
     179add_filter( 'the_content', 'wp_replace_insecure_home_url' );
    179180
    180181add_filter( 'the_excerpt', 'wptexturize' );
     
    184185add_filter( 'the_excerpt', 'shortcode_unautop' );
    185186add_filter( 'the_excerpt', 'wp_filter_content_tags' );
     187add_filter( 'the_excerpt', 'wp_replace_insecure_home_url' );
    186188add_filter( 'get_the_excerpt', 'wp_trim_excerpt', 10, 2 );
    187189
     
    210212add_filter( 'widget_text_content', 'shortcode_unautop' );
    211213add_filter( 'widget_text_content', 'wp_filter_content_tags' );
     214add_filter( 'widget_text_content', 'wp_replace_insecure_home_url' );
    212215add_filter( 'widget_text_content', 'do_shortcode', 11 ); // Runs after wpautop(); note that $post global will be null when shortcodes run.
     216
     217add_filter( 'wp_get_custom_css', 'wp_replace_insecure_home_url' );
    213218
    214219// RSS filters.
     
    347352add_action( 'wp_https_detection', 'wp_update_https_detection_errors' );
    348353add_filter( 'cron_request', 'wp_cron_conditionally_prevent_sslverify', 9999 );
     354
     355// HTTPS migration.
     356add_action( 'update_option_home', 'wp_update_https_migration_required', 10, 2 );
    349357
    350358// 2 Actions 2 Furious.
Note: See TracChangeset for help on using the changeset viewer.