Does FILTER_VALIDATE_EMAIL make a string safe for insertion in database?

后端 未结 5 474
借酒劲吻你
借酒劲吻你 2020-12-11 19:35
$str = \'\"mynam@blabl\"@domanin.com\';

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

the above email returns true... Fair enough

5条回答
  •  情书的邮戳
    2020-12-11 19:55

    Never use VALIDATE, maybe you can use SANITILIZE but I don't recommend it anyway.


    Consider this code:

    $email = filter_var($_GET['email'], FILTER_VALIDATE_EMAIL);
    $query = mysqli_query($sql, 'SELECT * FROM table WHERE email = "'.$email.'"');
    

    The basic SQL Injection is " or 1 = 1, you have already heard about it. But we can't use espaces and we need to end this string with something like @something.com.

    So, we start with " and add or'1'='1' this will work (because or1=1 will fail). Now we need the @email.com, let's add it as a MySQL comment (--@something.com). So, this is the result:

    "or'1'='1'--"@email.com
    

    Test it.

    This is valid email for filter_var and unsafe for mysqli_query.

提交回复
热议问题