When the filters take your store down
Three storefronts down, no spike in analytics. A botnet was generating filter combinations nobody would ever click. How we found it and stopped it at the edge.
Three storefronts on one Magento install went down at the same time on a weekday morning. No deployment, no traffic spike that anyone could see in analytics, nothing in the error log. The web server was fine. PHP had simply run out of workers, and every one of them was busy answering the same kind of request: a category page with a filter query string nobody would ever type.
What layered navigation costs
Layered navigation is the filter column on a category page: brand, colour, size, price. Every combination of filters is a different page, and each one is a real database query against the catalogue. On a normal day that is fine, because the number of combinations real customers click is small and the results cache.
A bot does not click like a customer. It generates the combinations. Take a filter with twenty values and request every pair, every triple, every ordering, with a different page number each time. None of those pages is cached, because none has been requested before. Each one takes the database a few hundred milliseconds. A few thousand requests a minute is enough to keep every PHP worker busy and lock real customers out of the home page.
This was not a sophisticated attack. The traffic came through a CDN, from many addresses, each sending a modest rate, which is exactly what a modern botnet looks like and exactly what per-IP rate limiting does not catch.
Finding it
The access log told the story in one command: group requests by path and query string, sort by count. The top entries were all one category with a multi-value filter parameter that no legitimate link on the site generates. Real customers select one value at a time. The bot was sending a dozen.
Stopping it
The fix was at the web server, before PHP sees the request. The site already had a rule that returns an empty response to requests carrying a known abusive query parameter. We added the filter parameter to that rule, with a pattern that matches the multi-value form bots send and leaves the single-value form customers use untouched. Dropping a request at the web server costs nothing. The stores were back within a minute of the rule going live, and the bot kept sending for another day, to no effect.
Making it harder next time
- Cap what layered navigation will accept. One value per filter, a sensible page limit, and nothing for parameters the theme does not generate. Requests outside that get an empty response.
- Tell search engines not to crawl filter combinations. They should be noindexed and, ideally, excluded in the robots file. That protects the crawl budget and removes one reason for bots to find the URLs in the first place.
- Rate limit by behaviour, not just by address. A single address making many different filter requests is suspicious even at a low rate.
- Watch worker saturation, not just uptime. The site answered health checks throughout. A graph of busy PHP workers would have shown the problem ten minutes before the first customer did.
The general lesson
Any page that is cheap to request and expensive to generate is a denial-of-service waiting to happen. Site search, filters, sort orders, pagination and APIs all qualify. The defence is to decide what shapes of request the site will answer and drop everything else at the edge, where it costs nothing.
This is the kind of operational work included when we host and run a store. If yours has ever gone slow for no reason you could find, the access log probably knows.
Got a similar problem? Talk to us.
Start a project