Every time you allow a user to enter data in a query string like this, you are vulnerable to SQL injection and should be avoided like a plague!
You have to be very careful so you can populate the searchStrings [] array. You should always add variable data to your query using parameter objects:
+ field1 like @PropertyVal Or field2 like @PropertyVal Or field3 like @PropertyVal etc...
And if you use SQL Server, for example
Query.Parameters.Add(new SqlParameter("PropertyVal", '%' + searchStrings[i] + '%'));
Be very careful how you create the query string that you intend to run on the production server, especially if it has any data that has consequences!
In your example, you mentioned Little Bobby Tables
Robert '), students of DROP TABLE, -
And quoted it because he needed empty space, you couldn't do it, but if the attacker encoded it using something like this:
Robert');Exec(Replace('Drop_Table_students','_',Char(32)));
I would say it is better to be safe and do it right. There is no easy way to make sure that you catch every scenario otherwise ...
source share