mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2025-10-16 12:05:38 +00:00
Security: Fix bug in wp_is_local_html_output().
Prior to this changeset, the check for the correct RSD link output was relying on a specific protocol, although it needs to accept both the HTTP and HTTPS version of the URL. Props TimothyBlynJacobs. Fixes #52542. See #47577. git-svn-id: https://develop.svn.wordpress.org/trunk@50391 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
d77042872c
commit
c8bbd79d2d
@ -204,7 +204,7 @@ function wp_cron_conditionally_prevent_sslverify( $request ) {
|
||||
function wp_is_local_html_output( $html ) {
|
||||
// 1. Check if HTML includes the site's Really Simple Discovery link.
|
||||
if ( has_action( 'wp_head', 'rsd_link' ) ) {
|
||||
$pattern = esc_url( site_url( 'xmlrpc.php?rsd', 'rpc' ) ); // See rsd_link().
|
||||
$pattern = preg_replace( '#^https?:(?=//)#', '', esc_url( site_url( 'xmlrpc.php?rsd', 'rpc' ) ) ); // See rsd_link().
|
||||
return false !== strpos( $html, $pattern );
|
||||
}
|
||||
|
||||
@ -218,7 +218,7 @@ function wp_is_local_html_output( $html ) {
|
||||
// 3. Check if HTML includes the site's REST API link.
|
||||
if ( has_action( 'wp_head', 'rest_output_link_wp_head' ) ) {
|
||||
// Try both HTTPS and HTTP since the URL depends on context.
|
||||
$pattern = esc_url( preg_replace( '#^https?:(?=//)#', '', get_rest_url() ) ); // See rest_output_link_wp_head().
|
||||
$pattern = preg_replace( '#^https?:(?=//)#', '', esc_url( get_rest_url() ) ); // See rest_output_link_wp_head().
|
||||
return false !== strpos( $html, $pattern );
|
||||
}
|
||||
|
||||
|
||||
@ -171,6 +171,7 @@ class Tests_HTTPS_Detection extends WP_UnitTestCase {
|
||||
|
||||
/**
|
||||
* @ticket 47577
|
||||
* @ticket 52542
|
||||
*/
|
||||
public function test_wp_is_local_html_output_via_rsd_link() {
|
||||
// HTML includes RSD link.
|
||||
@ -183,6 +184,12 @@ class Tests_HTTPS_Detection extends WP_UnitTestCase {
|
||||
$html = $this->get_sample_html_string( $head_tag );
|
||||
$this->assertTrue( wp_is_local_html_output( $html ) );
|
||||
|
||||
// HTML includes RSD link with alternative URL scheme.
|
||||
$head_tag = get_echo( 'rsd_link' );
|
||||
$head_tag = false !== strpos( $head_tag, 'https://' ) ? str_replace( 'https://', 'http://', $head_tag ) : str_replace( 'http://', 'https://', $head_tag );
|
||||
$html = $this->get_sample_html_string( $head_tag );
|
||||
$this->assertTrue( wp_is_local_html_output( $html ) );
|
||||
|
||||
// HTML does not include RSD link.
|
||||
$html = $this->get_sample_html_string();
|
||||
$this->assertFalse( wp_is_local_html_output( $html ) );
|
||||
|
||||
Loading…
Reference in New Issue
Block a user