From 19a8957bd073a1cfc1f75000e41b48d5676e36f7 Mon Sep 17 00:00:00 2001 From: Jonathan Desrosiers Date: Wed, 4 Sep 2019 18:00:59 +0000 Subject: [PATCH] Fix for URL sanitization in `wp_kses_bad_protocol_once()`. Merges [45997] to the 5.1 branch. Props irsdl, sstoqnov, whyisjake. git-svn-id: https://develop.svn.wordpress.org/branches/5.1@46002 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/kses.php | 1 + tests/phpunit/tests/kses.php | 10 +++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/wp-includes/kses.php b/src/wp-includes/kses.php index 465364e6de..4bbc5aeed5 100644 --- a/src/wp-includes/kses.php +++ b/src/wp-includes/kses.php @@ -1657,6 +1657,7 @@ function wp_kses_html_error( $string ) { * @return string Sanitized content. */ function wp_kses_bad_protocol_once( $string, $allowed_protocols, $count = 1 ) { + $string = preg_replace( '/(�*58(?![;0-9])|�*3a(?![;a-f0-9]))/i', '$1;', $string ); $string2 = preg_split( '/:|�*58;|�*3a;/i', $string, 2 ); if ( isset( $string2[1] ) && ! preg_match( '%/\?%', $string2[0] ) ) { $string = trim( $string2[1] ); diff --git a/tests/phpunit/tests/kses.php b/tests/phpunit/tests/kses.php index b359452b88..2205d9ed02 100644 --- a/tests/phpunit/tests/kses.php +++ b/tests/phpunit/tests/kses.php @@ -144,6 +144,8 @@ EOF; 'javascript:alert(1)//?:', 'feed:javascript:alert(1)', 'feed:javascript:feed:javascript:feed:javascript:alert(1)', + 'javascript:alert(1)', + 'javascript:x=1;alert(1)', ); foreach ( $bad as $k => $x ) { $result = wp_kses_bad_protocol( wp_kses_normalize_entities( $x ), wp_allowed_protocols() ); @@ -164,8 +166,14 @@ EOF; case 24: $this->assertEquals( 'feed:alert(1)', $result ); break; + case 26: + $this->assertEquals( 'javascript&#58alert(1)', $result ); + break; + case 27: + $this->assertEquals( 'javascript&#x3ax=1;alert(1)', $result ); + break; default: - $this->fail( "wp_kses_bad_protocol failed on $x. Result: $result" ); + $this->fail( "wp_kses_bad_protocol failed on $k, $x. Result: $result" ); } } }