Jump to content

SQL Injection prevention and wildcards


siric

Recommended Posts

Hi,

 

I am doing a search on a table with a string that will be submitted by a user and want to prevent sql injection and am using mysql_real_escape_string.

 

The thing is that my search is a wildcard search

 

$search = mysql_real_escape_string($contains);
$search = "%".$search."%";

 

If attempts an injection, the $search string equates to '%%', when then returns results for the entire table.

 

Even if I add

if ($calysponiansearch == '%%') {
      $calypsoniansearch = "%a";
}

 

that does not work as the escaped characters are there but not displayed.

 

 

How can I prevent this?

 

Thanks

 

Steve

 

 

Link to comment
https://forums.phpfreaks.com/topic/202109-sql-injection-prevention-and-wildcards/
Share on other sites

If I pass

"" OR 1

in the $contains variable, I end up with $searchstring being equal to %% which then displays everything in the table.

 

Did you ever check it?

 

mysql_connect('localhost','root','');

$contains = '"" OR 1';
$search = mysql_real_escape_string($contains);
$search = "%".$search."%";
echo $search;

 

%\"\" OR 1%

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.