Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What else should I be doing to sanitize user input?

Recently, I had an audit run on some of my sites by a client. One of the things they came back with was that I could be sanitizing the input data a little better as people could still cause potential harm to the database.

The function below is what I am currently using (a leftover from the old developer) but I cannot see where the potential issue may lie.

The string that gets passed through to the database will be displayed via XML which in turn is read by a Flash application.

Could anyone tell me what I might be missing? Thanks

function secure_string($string)
{   
    return (strip_tags(addslashes(mysql_real_escape_string(
                      stripslashes($string)))));
}
like image 760
Drew Avatar asked Dec 07 '22 05:12

Drew


2 Answers

Better use the new PHP function filter_var() for cleaning input. New and better.

like image 97
Elzo Valugi Avatar answered Dec 10 '22 11:12

Elzo Valugi


It looks like there's too much going on in that function. mysql_real_escape_string() already escapes everything you need to escape, so there's no need to run addslashes() on that. In fact, it could do more harm than good by escaping the backslashes mysql_real_escape_string() creates.

like image 23
Kaivosukeltaja Avatar answered Dec 10 '22 12:12

Kaivosukeltaja