I have seen a few people on here state that concatenating queries using mysql_real_escape_string
will not protect you (entirely) from SQL injection attacks.
However, I am yet to see an example of input that illustrates an attack that mysql_real_escape_string
would not protect you from. The majority of examples forget that mysql_query
is limited to one query and use mysql_real_escape_string
incorrectly.
The only example I can think of is the following:
mysql_query('DELETE FROM users WHERE user_id = '.mysql_real_escape_string($input));
This would not protect you from the following input:
5 OR 1=1
I would see this as incorrect usage of mysql_real_escape_string
rather than a shortcoming, it is designed for strings not numeric values. You should either cast to a numeric type or if you are going to treat the input as a string when sanitising you should do the same in your query and wrap quotation marks around it.
Can anyone provide an example of input that can get around mysql_real_escape_string
that does not rely on incorrect handling of numeric values or forget that mysql_query
can only execute one query?
Edit: I am interested in the limitations of mysql_real_escape_string
and not comparing it to alternatives, I realise there are better options for new projects and am not disputing that.
mysql_*
when you have good alternatives? – Hinze%_
), which are wildcards inLIKE
. Does that count as a shortcoming? – Ivanivanamysql_*
has begun, but I fully understand your wanting to know about possible malicious requests and how given functions fend them off – Bushwhack