A distributed denial-of-service (DDoS) spike, a credential-stuffing campaign against a login route, or automated scrapers crawling a product catalog can take an application offline or inflate cloud bills within minutes. When a backend waits until abusive requests hit Nginx, Node.js workers, or the PostgreSQL connection pool before rejecting them, origin CPU, memory, and bandwidth have already been spent on useless traffic.
According to the OWASP API Security Project, Unrestricted Resource Consumption (API4) and Unrestricted Access to Sensitive Business Flows (API6) occur when endpoints fail to cap request frequency, payload size, or downstream compute cost. Moving filtering to the network edge drops abusive traffic across globally distributed points of presence before packets reach origin infrastructure.
1. Separating volumetric DDoS, business-logic bots, and scrapers
Not every traffic surge behaves alike, and each attack class requires a distinct edge defense:
- Network and application-layer DDoS (L3/L4 and L7 floods): Volumetric attacks saturate links with SYN or UDP floods, or open concurrent HTTP GET requests against uncached pages to exhaust origin workers. Edge networks absorb L3/L4 floods automatically and use TLS and HTTP signatures to drop L7 botnets.
- Credential stuffing and cost-amplification bots: Attackers route distributed residential proxies to test leaked credentials on
/api/auth/login, or spam SMS OTP and contact forms. Because per-IP volume stays low, generic DDoS thresholds rarely trigger. - Abusive catalog and search scrapers: Automated crawlers enumerate product feeds, pricing tables, or search routes with deep pagination (
page=200&limit=100), triggering heavy database scans and unexpected egress costs.
The most common mistake in edge rate limiting is enforcing one flat threshold across the entire domain, such as 100 requests per minute for any URL. A normal page load can fetch 35 CSS, JavaScript, font, and image files within two seconds; a tight global limit blocks legitimate visitors behind office NAT gateways, while a loose limit lets password-spraying bots probe 20 attempts per minute untouched.
Following Cloudflare Docs: Rate Limiting Rules, each rule separates three components: a matching expression (expression), counting keys (characteristics), and a mitigation action (mitigation). When architecting edge layers in our Cloud and DevOps services, ToanKhonTech segments endpoints into four tiers:
| Endpoint tier | Primary risk and origin cost | Counting key (Characteristics) | Reference threshold and edge action |
|---|
Authentication and OTP (POST /api/auth/*) | Credential stuffing, expensive Bcrypt/Argon2 hashing, paid SMS triggers | ip.src paired with header/email hash or session cookie | 5-10 req/min; trigger managed_challenge or block for 15 minutes |
Contact and lead forms (POST /api/contact, /leads) | CRM database spam, outbound SMTP queue saturation | ip.src plus cf.colo.id (or JA4 fingerprint) | 3-5 req/5 min; require Turnstile or edge interactive challenge |
Search and catalog filters (GET /api/search, /catalog) | Price scraping, heavy SQL ILIKE or Elasticsearch queries | ip.src or API key () |
A targeted Cloudflare WAF expression focusing strictly on authentication POST routes while leaving static assets untouched looks like this:
(http.request.uri.path eq "/api/auth/login" or http.request.uri.path eq "/api/auth/forgot-password")
and http.request.method eq "POST"
When triggered, the edge returns HTTP 429 Too Many Requests with a Retry-After header so compliant clients back off without opening an origin socket. Before enabling block, teams should run new rules in log mode for 48 to 72 hours to check false positives across mobile CG-NAT pools and shared corporate office IPs.
3. Locking down origin bypass paths and compute budgets
Strict edge WAF and rate limits offer zero protection if attackers uncover the origin server's real IP via historical DNS records, SPF/MX entries, or stale TLS certificates and connect directly to port 443. Closing bypass routes requires three simultaneous controls:
- 01Cloud firewall and security group allowlists: Configure AWS Security Groups, GCP Firewall, or host
nftables so ports 80 and 443 accept TCP connections only from the edge provider's published IPv4 and IPv6 ranges, dropping all other public traffic. - 02Authenticated Origin Pulls (mTLS): Configure Nginx, Caddy, or the origin load balancer to verify the edge provider's client TLS certificate during the handshake. Even if another tenant on the same CDN points a hostname at your origin IP, requests fail without a matching tenant client certificate.
- 03Backend payload and pagination bounds: Edge filtering trims external spikes, yet the API must still enforce defensive limits: reject oversized bodies (such as capping JSON payloads at 1 MB), clamp pagination (
limit <= 50), and set explicit database timeouts per the OWASP API Security Project.
Scope, caveats, and engineering boundaries
The rule expressions, counting keys, and mitigation actions follow official Cloudflare Docs: Rate Limiting Rules documentation, while the resource-consumption and business-flow risk framing aligns with the OWASP API Security Project. Thresholds in the tier table reflect starting baselines from ToanKhonTech's engineering practice rather than universal industry caps or a CDN vendor SLA.
Against botnets rotating across tens of thousands of residential IPs, IP-only rate limiting eventually hits a ceiling. Production defense requires pairing IP counters with token-scoped keys, JA4 TLS fingerprinting, Turnstile verification, and strict backend quotas to protect origin stability under sustained load.