Skip to content
Permalink
Browse files

WP-r46005: Fix for URL sanitization in `wp_kses_bad_protocol_once()`.

Merges https://core.trac.wordpress.org/changeset/45997 to the 4.9 branch.

WP:Props irsdl, sstoqnov, whyisjake.

----
Merges https://core.trac.wordpress.org/changeset/46005 / WordPress/wordpress-develop@f782423 to ClassicPress.
  • Loading branch information...
desrosj authored and nylen committed Sep 5, 2019
1 parent 7b5700b commit 489488a36cf06929c76907e6e5ddbb1f5c95c379
Showing with 20 additions and 4 deletions.
  1. +1 −0 src/wp-includes/kses.php
  2. +19 −4 tests/phpunit/tests/kses.php
@@ -1385,6 +1385,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( '/(&#0*58(?![;0-9])|&#x0*3a(?![;a-f0-9]))/i', '$1;', $string );
$string2 = preg_split( '/:|&#0*58;|&#x0*3a;/i', $string, 2 );
if ( isset($string2[1]) && ! preg_match('%/\?%', $string2[0]) ) {
$string = trim( $string2[1] );
@@ -137,6 +137,8 @@ function test_wp_kses_bad_protocol() {
'javascript&#0000058alert(1)//?:',
'feed:javascript:alert(1)',
'feed:javascript:feed:javascript:feed:javascript:alert(1)',
'javascript&#58alert(1)',
'javascript&#x3ax=1;alert(1)',
);
foreach ( $bad as $k => $x ) {
$result = wp_kses_bad_protocol( wp_kses_normalize_entities( $x ), wp_allowed_protocols() );
@@ -146,10 +148,23 @@ function test_wp_kses_bad_protocol() {
case 12:
$this->assertEquals( str_replace( '&', '&', $x ), $result );
break;
case 22: $this->assertEquals( 'javascript&#0000058alert(1);', $result ); break;
case 23: $this->assertEquals( 'javascript&#0000058alert(1)//?:', $result ); break;
case 24: $this->assertEquals( 'feed:alert(1)', $result ); break;
default: $this->fail( "wp_kses_bad_protocol failed on $x. Result: $result" );
case 22:
$this->assertEquals( 'javascript&#0000058alert(1);', $result );
break;
case 23:
$this->assertEquals( 'javascript&#0000058alert(1)//?:', $result );
break;
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 $k, $x. Result: $result" );
}
}
}

0 comments on commit 489488a

Please sign in to comment.
You can’t perform that action at this time.