Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does FILTER_VALIDATE_EMAIL make a string safe for insertion in database?

$str = '"mynam@blabl"@domanin.com';

filter_var($str, FILTER_VALIDATE_EMAIL);//return valid email.

the above email returns true... Fair enough that RFC 2822 says it's a legal email address.

my question is if you validate an email using the above could an email carry sql injections that can harm the db even though you have filtered it with filter_var?

like image 241
Val Avatar asked Nov 11 '10 13:11

Val


2 Answers

my question is if you validate an email using the above could an email carry sql injections that can harm the db even though you have filtered it with filter_var?

filter_var is not a replacement for database specific sanitation like mysql_real_escape_string()! One needs to always apply that, too.

like image 166
Pekka Avatar answered Sep 19 '22 00:09

Pekka


Yes - do not rely on anything besides the database specific escaping mechanism for safety from SQL injection.

Always use mysql_real_escape_string() on it before using it in SQL.

like image 27
alex Avatar answered Sep 22 '22 00:09

alex