mirror of
git://develop.git.wordpress.org/
synced 2025-01-17 21:08:44 +01:00
Fix for URL sanitization in wp_kses_bad_protocol_once()
.
Merges [45997] to the 4.6 branch. Props irsdl, sstoqnov, whyisjake. git-svn-id: https://develop.svn.wordpress.org/branches/4.6@46008 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
e57576ef1d
commit
f4e42693a5
@ -1397,6 +1397,7 @@ function wp_kses_html_error($string) {
|
|||||||
* @return string Sanitized content
|
* @return string Sanitized content
|
||||||
*/
|
*/
|
||||||
function wp_kses_bad_protocol_once($string, $allowed_protocols, $count = 1 ) {
|
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 );
|
$string2 = preg_split( '/:|�*58;|�*3a;/i', $string, 2 );
|
||||||
if ( isset($string2[1]) && ! preg_match('%/\?%', $string2[0]) ) {
|
if ( isset($string2[1]) && ! preg_match('%/\?%', $string2[0]) ) {
|
||||||
$string = trim( $string2[1] );
|
$string = trim( $string2[1] );
|
||||||
|
@ -137,6 +137,8 @@ EOF;
|
|||||||
'javascript:alert(1)//?:',
|
'javascript:alert(1)//?:',
|
||||||
'feed:javascript:alert(1)',
|
'feed:javascript:alert(1)',
|
||||||
'feed:javascript:feed:javascript: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 ) {
|
foreach ( $bad as $k => $x ) {
|
||||||
$result = wp_kses_bad_protocol( wp_kses_normalize_entities( $x ), wp_allowed_protocols() );
|
$result = wp_kses_bad_protocol( wp_kses_normalize_entities( $x ), wp_allowed_protocols() );
|
||||||
@ -146,10 +148,23 @@ EOF;
|
|||||||
case 12:
|
case 12:
|
||||||
$this->assertEquals( str_replace( '&', '&', $x ), $result );
|
$this->assertEquals( str_replace( '&', '&', $x ), $result );
|
||||||
break;
|
break;
|
||||||
case 22: $this->assertEquals( 'javascript&#0000058alert(1);', $result ); break;
|
case 22:
|
||||||
case 23: $this->assertEquals( 'javascript&#0000058alert(1)//?:', $result ); break;
|
$this->assertEquals( 'javascript&#0000058alert(1);', $result );
|
||||||
case 24: $this->assertEquals( 'feed:alert(1)', $result ); break;
|
break;
|
||||||
default: $this->fail( "wp_kses_bad_protocol failed on $x. Result: $result" );
|
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" );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user