Better validation of the URL used in core HTTP requests.

Merges [30443] to the 3.9 branch.

Built from https://develop.svn.wordpress.org/branches/3.9@30445


git-svn-id: http://core.svn.wordpress.org/branches/3.9@30440 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Andrew Nacin 2014-11-20 14:02:14 +00:00
parent 5594f44f40
commit ca3e6728d1
1 changed files with 4 additions and 4 deletions

View File

@ -451,8 +451,9 @@ function send_origin_headers() {
* @return mixed URL or false on failure.
*/
function wp_http_validate_url( $url ) {
$original_url = $url;
$url = wp_kses_bad_protocol( $url, array( 'http', 'https' ) );
if ( ! $url )
if ( ! $url || strtolower( $url ) !== strtolower( $original_url ) )
return false;
$parsed_url = @parse_url( $url );
@ -462,7 +463,7 @@ function wp_http_validate_url( $url ) {
if ( isset( $parsed_url['user'] ) || isset( $parsed_url['pass'] ) )
return false;
if ( false !== strpos( $parsed_url['host'], ':' ) )
if ( false !== strpbrk( $parsed_url['host'], ':#?[]' ) )
return false;
$parsed_home = @parse_url( get_option( 'home' ) );
@ -480,8 +481,7 @@ function wp_http_validate_url( $url ) {
}
if ( $ip ) {
$parts = array_map( 'intval', explode( '.', $ip ) );
if ( '127.0.0.1' === $ip
|| ( 10 === $parts[0] )
if ( 127 === $parts[0] || 10 === $parts[0]
|| ( 172 === $parts[0] && 16 <= $parts[1] && 31 >= $parts[1] )
|| ( 192 === $parts[0] && 168 === $parts[1] )
) {