Magento 1.9 Security – How to Stop Spam Bots and SQL Injections

magento-1.9searchSecurity

how do I stop this?

screenshot

Hundreds upon hundreds of these searches.

Best Answer

First of all: These were blind attacks that most likely did not have any effect, a successful SQL injection should not be possible with these search queries.

But it's still bad for two reasons:

  1. the sheer number of these requests could take too many resources if they come in short time. As Anna Völk suggested in the comments, check your access logs if they come from certain IP ranges and block these IPs as soon as the requests start coming in.

  2. other users will receive these searches as suggestions because they actually returned results. This is due to Magentos default LIKE search algorithm where you get all results where at least one word matches. Changing this from OR to AND improves the search results and makes searches like these return nothing, so that they won't show up as suggestions anymore.

See also:

Search Type: Like, Full Text or Combined?

Quoting from jharrison.au's answer, change this:

if ($like) {
            $likeCond = '(' . join(' OR ', $like) . ')';
        }

To this:

if ($like) {
            $likeCond = '(' . join(' AND ', $like) . ')';
        }

To get an immediate, massive boost to the relevance of your search results.

Related Topic