DEV Community

Divinelab.io
Divinelab.io

Posted on

How to Stop Bad Bots and AI Scrapers

--

Automated scrapers, AI training crawlers, and credential stuffing bots account for over 40% of all internet traffic.

Allowing bots to scrape your web application without restrictions inflates hosting bills, degrades performance for real users, and drains database connection pools.

In this tutorial, we are going to use Aegis—an open-source, self-hosted Web Application Firewall (WAF) and reverse proxy—to configure automated bot defense, manage AI scrapers, and deploy client-side cryptographic browser challenges.

Aegis Smart Challenge Bot Defense


Step 1: Access Bot Defense Settings

  1. Open your Aegis Admin Console at http://server-ip:8081.
  2. In the left navigation menu, navigate to Traffic Control > Bot Defense.
  3. Toggle on Enable Bot Protection.

Aegis evaluates incoming client fingerprints, request headers, and traffic behavioral patterns in real time.


Step 2: Configure AI Crawlers and Scraper Policies

Manage how automated crawlers access your site:

  1. Search Engine Crawlers: Toggle on Allow Verified Search Engines (Googlebot, Bingbot, DuckDuckGo). Aegis verifies reverse-DNS signatures to ensure fake bots cannot spoof search engine user-agents.
  2. AI Scrapers & Training Bots: Select your policy for known AI crawlers (GPTBot, CCBot, Anthropic, Bytespider):
    • Block: Immediately drop requests with HTTP 403 Forbidden.
    • Challenge: Require the bot to pass a client-side challenge.
  3. Click Apply Policy.

Step 3: Deploy Client-Side Browser Challenges (Smart Challenge)

For requests that exhibit suspicious behavior or exceed baseline request velocities:

  1. Under Mitigation Strategy, select Browser Challenge (Smart Challenge).
  2. When a suspected bot requests a protected page, Aegis returns a lightweight HTML payload that executes a fast cryptographic challenge in the background.
  3. Genuine human visitors running modern web browsers solve the challenge automatically in milliseconds without seeing a CAPTCHA.
  4. Headless scripts, scraping tools, and automated botnets fail the execution and are dropped at the edge.

Step 4: Verify Bot Mitigation

Test the endpoint with an automated CLI client:

curl -i -A "GPTBot/1.0" http://localhost:8080/
Enter fullscreen mode Exit fullscreen mode

Response:

HTTP/1.1 403 Forbidden
Content-Type: text/html; charset=utf-8
X-Aegis-Action: bot-blocked

Access denied: Automated AI scraper blocked by security policy.
Enter fullscreen mode Exit fullscreen mode

The request is rejected at the ingress proxy and never reaches your origin web server.


Resources

The Community Edition is free to self-host:

Top comments (2)

Collapse
 
furqan_ashraf profile image
Furqan Ashraf •

Good walkthrough of the Aegis setup. One addition for the IP reputation denylist part: many scrapers now rotate through residential proxies, so a static list of bad IPs misses a lot of them. Classifying each IP by type (hosting, residential proxy, VPN, Tor, known bot) lets you apply different rules per type instead of one blanket list. The ipgeolocation.io IP Security API returns those flags plus a threat score in one call (ipgeolocation.io/ip-security-api.html).

Collapse
 
baumgaerben profile image
baumgaerben •

40% là con số đáng lo, nhưng thực tế nhiều trang web nội bộ của mình thấy con số này còn cao hơn — đặc biệt là các endpoint API public và trang login. Một vài điều mình áp dụng và thấy hiệu quả:

  1. Rate limiting theo fingerprint chứ không chỉ IP — bot farm hiện nay xoay proxy liên tục, nhưng fingerprint trình duyệt (canvas, fonts, timing) khó giả mạo hơn. Thư viện open-source như FingerprintJS (phiên bản community) giúp khá nhiều.

  2. Challenge-response cho traffic đáng ngờ — thay vì block ngay, trả về JavaScript challenge hoặc proof-of-work nhẹ. Bot headless thường fail ở đây vì không thực thi JS đầy đủ, còn user thật hầu như không cảm thấy.

  3. Honeypot field ẩn — thêm input display:none vào form login/register. Bot tự động fill hết field, user thật không thấy. Cực đơn giản nhưng lọc được 80% credential stuffing cơ bản.

  4. Behavioral analysis — track mouse movement, scroll pattern, time-between-requests. Bot script thường có pattern quá đều hoặc quá nhanh. Có thể dùng Cloudflare Turnstile hoặc tự xây rule đơn giản.

  5. Block known ASN/datacenter ranges — AWS, DigitalOcean, Hetzner... ít user thật duyệt web từ IP này. Maintain list tự cập nhật hàng tuần.

Điểm yếu chung: false positive. Luôn cần logging chi tiết và quy trình appeal cho user bị chặn nhầm. Mình hay để "soft block" (challenge) trước 2-3 tuần, mới hard block khi dữ liệu đủ thuyết phục.

Bạn nào đang dùng WAF nào (ModSecurity (site: labagent .tech)