Prompt
How do I protect a website from layer 7 DDoS attacks?
Latest observation
Oct 29, 2026
OpenAI APIWeb search: off
Protecting a website from Layer 7 (application-layer) DDoS attacks means defending the app itself, not just the network. These attacks often look like normal user traffic, so the goal is to filter, absorb, and rate-limit bad behavior without blocking real users.
Practical defenses
1) Put a CDN/WAF in front of the site
- Use a CDN to cache static content and absorb traffic spikes.
- Enable a Web Application Firewall (WAF) to filter suspicious requests.
- Turn on vendor DDoS protections (Cloudflare, Fastly, Akamai, AWS Shield + WAF, Azure DDoS Protection, etc.).
2) Rate limit aggressively
Apply limits by:
- IP
- ASN/geo if appropriate
- session/user/account
- endpoint (especially expensive routes like login, search, password reset, API calls)
Examples:
- limit
/loginattempts per IP and per username - limit search endpoint requests per minute
- cap API requests per token
3) Add bot detection and challenge mechanisms
- Use CAPTCHA / challenge pages for suspicious traffic.
- Use JS challenges, proof-of-work, or device/browser fingerprinting where appropriate.
- Detect non-browser clients hitting browser-only pages.
4) Cache as much as possible
- Cache HTML where feasible, and definitely cache static assets.
- Use microcaching for dynamic pages that can tolerate short staleness.
- Cache expensive backend responses and API results.
- Serve from edge/CDN when possible.
5) Protect expensive endpoints
Identify endpoints that are costly in CPU, DB, or upstream calls:
- login
- search
- report generation
- password reset
- signup
- API endpoints that fan out to other services
Mitigations:
- add authentication before expensive work
- queue long-running jobs
- precompute results
- use pagination and hard limits
- reject oversized requests early
6) Harden your app against resource exhaustion
- Set strict request timeouts
- Limit request body size
- Limit header size and number of headers
- Cap concurrency per worker/process
- Use connection limits
- Ensure database query timeouts and pool limits are configured
7) Separate critical and noncritical workloads
- Put frontend, API, and admin panels on different hosts/subdomains.
- Isolate databases and background jobs.
- Use separate rate limits for admin or partner APIs.
8) Monitor and alert
Track:
- requests per second
- 4xx/5xx rates
- latency percentiles
- origin CPU, memory, DB load
- top URLs, IPs, user agents, ASN/geo, referrers
Alert on:
- sudden spikes in low-value endpoints
- abnormal login/search rates
- unusual geographic or ASN concentration
- increased origin traffic despite CDN caching
9) Use IP reputation and allowlists carefully
- Block known bad IPs, datacenters, or ASNs if that fits your audience.
- Allowlist trusted partners and health checks.
- Don’t rely only on IP blocking; attackers rotate IPs.
10) Build an incident response plan
Have a playbook for:
- turning on “under attack” mode
- tightening WAF rules
- increasing challenge levels
- temporarily disabling expensive features
- scaling origin capacity
- contacting upstream provider support
Good architecture pattern
A common setup is:
Users → CDN/WAF → reverse proxy → app servers → cache → database
This lets you:
- absorb volume at the edge
- challenge suspicious traffic
- rate-limit at multiple layers
- keep the origin from being overwhelmed
Important notes
- Don’t only focus on bandwidth; Layer 7 attacks are about request cost.
- Avoid blocking all traffic from whole countries or networks unless you’re sure it won’t hurt legitimate users.
- Test your defenses in a controlled environment so you don’t accidentally block real customers.
If you want, I can help you design a specific protection stack for your site based on your platform, traffic size, and hosting provider.