Skip to content

Commit fafead9

Browse files
committed
Fix for URL sanitization in wp_kses_bad_protocol_once().
Merges [45997] to the 4.5 branch. Props irsdl, sstoqnov, whyisjake. git-svn-id: https://develop.svn.wordpress.org/branches/4.5@46009 602fd350-edb4-49c9-b593-d223f7449a82
1 parent db04e39 commit fafead9

2 files changed

Lines changed: 20 additions & 4 deletions

File tree

src/wp-includes/kses.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1396,6 +1396,7 @@ function wp_kses_html_error($string) {
13961396
* @return string Sanitized content
13971397
*/
13981398
function wp_kses_bad_protocol_once($string, $allowed_protocols, $count = 1 ) {
1399+
$string = preg_replace( '/(&#0*58(?![;0-9])|&#x0*3a(?![;a-f0-9]))/i', '$1;', $string );
13991400
$string2 = preg_split( '/:|&#0*58;|&#x0*3a;/i', $string, 2 );
14001401
if ( isset($string2[1]) && ! preg_match('%/\?%', $string2[0]) ) {
14011402
$string = trim( $string2[1] );

tests/phpunit/tests/kses.php

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,8 @@ function test_wp_kses_bad_protocol() {
137137
'javascript&#0000058alert(1)//?:',
138138
'feed:javascript:alert(1)',
139139
'feed:javascript:feed:javascript:feed:javascript:alert(1)',
140+
'javascript&#58alert(1)',
141+
'javascript&#x3ax=1;alert(1)',
140142
);
141143
foreach ( $bad as $k => $x ) {
142144
$result = wp_kses_bad_protocol( wp_kses_normalize_entities( $x ), wp_allowed_protocols() );
@@ -146,10 +148,23 @@ function test_wp_kses_bad_protocol() {
146148
case 12:
147149
$this->assertEquals( str_replace( '&', '&', $x ), $result );
148150
break;
149-
case 22: $this->assertEquals( 'javascript&#0000058alert(1);', $result ); break;
150-
case 23: $this->assertEquals( 'javascript&#0000058alert(1)//?:', $result ); break;
151-
case 24: $this->assertEquals( 'feed:alert(1)', $result ); break;
152-
default: $this->fail( "wp_kses_bad_protocol failed on $x. Result: $result" );
151+
case 22:
152+
$this->assertEquals( 'javascript&#0000058alert(1);', $result );
153+
break;
154+
case 23:
155+
$this->assertEquals( 'javascript&#0000058alert(1)//?:', $result );
156+
break;
157+
case 24:
158+
$this->assertEquals( 'feed:alert(1)', $result );
159+
break;
160+
case 26:
161+
$this->assertEquals( 'javascript&#58alert(1)', $result );
162+
break;
163+
case 27:
164+
$this->assertEquals( 'javascript&#x3ax=1;alert(1)', $result );
165+
break;
166+
default:
167+
$this->fail( "wp_kses_bad_protocol failed on $k, $x. Result: $result" );
153168
}
154169
}
155170
}

0 commit comments

Comments
 (0)