Skip to content

Commit c8bbd79

Browse files
committed
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
1 parent d770428 commit c8bbd79

2 files changed

Lines changed: 9 additions & 2 deletions

File tree

src/wp-includes/https-detection.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ function wp_cron_conditionally_prevent_sslverify( $request ) {
204204
function wp_is_local_html_output( $html ) {
205205
// 1. Check if HTML includes the site's Really Simple Discovery link.
206206
if ( has_action( 'wp_head', 'rsd_link' ) ) {
207-
$pattern = esc_url( site_url( 'xmlrpc.php?rsd', 'rpc' ) ); // See rsd_link().
207+
$pattern = preg_replace( '#^https?:(?=//)#', '', esc_url( site_url( 'xmlrpc.php?rsd', 'rpc' ) ) ); // See rsd_link().
208208
return false !== strpos( $html, $pattern );
209209
}
210210

@@ -218,7 +218,7 @@ function wp_is_local_html_output( $html ) {
218218
// 3. Check if HTML includes the site's REST API link.
219219
if ( has_action( 'wp_head', 'rest_output_link_wp_head' ) ) {
220220
// Try both HTTPS and HTTP since the URL depends on context.
221-
$pattern = esc_url( preg_replace( '#^https?:(?=//)#', '', get_rest_url() ) ); // See rest_output_link_wp_head().
221+
$pattern = preg_replace( '#^https?:(?=//)#', '', esc_url( get_rest_url() ) ); // See rest_output_link_wp_head().
222222
return false !== strpos( $html, $pattern );
223223
}
224224

tests/phpunit/tests/https-detection.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ public function test_wp_cron_conditionally_prevent_sslverify() {
171171

172172
/**
173173
* @ticket 47577
174+
* @ticket 52542
174175
*/
175176
public function test_wp_is_local_html_output_via_rsd_link() {
176177
// HTML includes RSD link.
@@ -183,6 +184,12 @@ public function test_wp_is_local_html_output_via_rsd_link() {
183184
$html = $this->get_sample_html_string( $head_tag );
184185
$this->assertTrue( wp_is_local_html_output( $html ) );
185186

187+
// HTML includes RSD link with alternative URL scheme.
188+
$head_tag = get_echo( 'rsd_link' );
189+
$head_tag = false !== strpos( $head_tag, 'https://' ) ? str_replace( 'https://', 'http://', $head_tag ) : str_replace( 'http://', 'https://', $head_tag );
190+
$html = $this->get_sample_html_string( $head_tag );
191+
$this->assertTrue( wp_is_local_html_output( $html ) );
192+
186193
// HTML does not include RSD link.
187194
$html = $this->get_sample_html_string();
188195
$this->assertFalse( wp_is_local_html_output( $html ) );

0 commit comments

Comments
 (0)