PrestaShop Under Siege: Taming Exploding Connections and Bot Traffic with Cloudflare

PrestaShop Under Siege: Taming Exploding Connections and Bot Traffic with Cloudflare

A PrestaShop merchant recently faced a critical issue: an alarming explosion in the number of connections to their online store, with several new visitors appearing every second. Despite using Cloudflare for security and blocking identified AI robots, the problem persisted, raising concerns about performance, database bloat, and accurate analytics.

The community quickly identified the culprit: sophisticated bots, often leveraging residential proxies and not declaring themselves as traditional AI, making simple User-Agent blocking ineffective. These bots were primarily originating from non-target regions, continuously hitting the store and creating new guest IDs, which rapidly inflated the ps_connections, ps_guest, and ps_connections_page tables in the PrestaShop database, leading to potential slowdowns.

Key Strategies to Combat Malicious Bot Traffic:

  • Advanced Identification: Relying solely on User-Agent headers is insufficient. Merchants must dive into Cloudflare's Security Analytics (grouping by path, ASN, country, User-Agent, and IP) and server access logs. Common PrestaShop targets for bots include faceted search URLs (e.g., ?q=Category-..., ?order=, ?resultsPerPage=), /search?s= queries, and add-to-cart links (?add=1), which bots can exploit to generate an infinite number of unique URLs.
  • Cloudflare WAF & Rate Limiting:
    • Implement custom WAF rules with a 'Managed Challenge' or 'Block' action for problematic ASNs, countries where you don't sell, or URLs containing unusually large query strings.
    • Utilize Rate Limiting to restrict requests (e.g., more than 20-30 requests per 10 seconds per IP) on high-value or resource-intensive pages like /search, /cart, and filtered category URLs.
    • Activate 'Bot Fight Mode' (or 'Super Bot Fight Mode' for paid plans) and consider challenging requests from unverified bots with low bot scores.
    • Critical Configuration: Ensure your domain is properly proxied through Cloudflare (orange cloud icon) and your server is configured to only accept traffic from Cloudflare's IP ranges. This prevents bots from bypassing Cloudflare. Also, verify that your server retrieves the true visitor IP from the CF-Connecting-IP header, otherwise, all traffic will appear to originate from Cloudflare, skewing statistics and rendering server-side blocking tools like fail2ban ineffective.
  • PrestaShop Internal Optimizations:
    • Update your robots.txt file to 'Disallow' indexing of faceted search parameters and sorting options.
    • Configure filter pages with the 'noindex' meta tag.
    • To prevent database bloat, if detailed statistics are not crucial, consider disabling the statsdata module or the 'Record global page views' option, and regularly purge old entries from your connection tables.
    • Implement full-page caching or Cloudflare cache rules for category pages to ensure bot requests don't constantly hit your PHP and MySQL resources.
  • Security Best Practices: Always ensure your back-office URL is not the default, and implement challenge rules on login pages to mitigate brute-force attacks.

The merchant, initially overwhelmed by the technical jargon, was guided step-by-step to implement a Cloudflare WAF rule to challenge visitors from non-selling countries. A crucial refinement was added to this rule to prevent legitimate search engine bots (like Googlebot, which often originates from US IPs) from being challenged, thereby protecting SEO:

and not cf.client.bot

This comprehensive approach, combining Cloudflare's robust security features with PrestaShop-specific optimizations, proved effective in mitigating the exploding connections and restoring normal store operations.

Start with the tools

Explore migration tools

See options, compare methods, and pick the path that fits your store.

Explore migration tools