All posts
·6 min read

How to Secure APIs Against Bot Attacks

APIs are built for machines, which makes telling a good machine from a bad one the whole challenge. Here's a layered approach to keeping bots out of your API.

1. Fingerprint, don't trust the user-agent

User-agent strings are trivially spoofed. Score clients on signals they can't easily fake: TLS/JA3 fingerprint, HTTP/2 header order, timing, and request sequencing. A headless scraper looks nothing like a real browser under that lens.

2. Rate limit on the right key

Limit by API token or authenticated user, not just IP. Attackers rotate IPs cheaply. Tight limits on login, signup, and checkout endpoints make credential stuffing and inventory hoarding uneconomical.

3. Challenge, don't just block

  • Serve a proof-of-work or JS challenge to clients that score as automated.
  • Reserve hard blocks for clients that fail challenges or hit abuse thresholds.
  • Allowlist verified partners and crawlers by validated identity.

4. Watch for abuse patterns

High failure rates on auth endpoints, enumeration of sequential IDs, and bursts against a single route are all tells. Behavioral baselines flag them automatically.

Karbon combines bot fingerprinting, edge rate limiting, and graduated challenges into one reverse proxy. See bot management and rate limiting for details.