Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

filter_var() accepts invalid URL

Tags:

php

filter-var

Why does filter_var() accepts and validate this URL http://http://www.google.com?

$website = "http://http://www.google.com";

echo filter_var($website, FILTER_VALIDATE_URL); // This outputs the value of $website

I think this is wrong. Any solution or fixed for this?

phpinfo()

enter image description here

like image 250
Leandro Garcia Avatar asked Jun 27 '13 02:06

Leandro Garcia


1 Answers

Seems like you've found a bug in PHP. The PHP manual states that FILTER_VALIDATE_URL validates uris according to http://www.faqs.org/rfcs/rfc2396.html

If you read the spec, PHP obviously fails to properly validate per the guidelines. Specifically, in section 3 (URI Syntactic Components), it's defined that the scheme (http in your case) may only exist once, and precedes the only colon in the uri.

You should report this bug at https://bugs.php.net/

Good work finding it!

like image 133
Steven Moseley Avatar answered Nov 04 '22 13:11

Steven Moseley