All ArticlesSecurity2026-11-27T13:45:50+08:00

Thinking DDoS Mitigation Blocks All Bad Traffic? Check What Passes as Legit at Layer 7

You enabled DDoS protection but application-layer attacks still exhaust your web workers because they look like normal browser requests. After reading, you will understand how L7 attacks bypass volumetric filters and how to identify them using request patterns, rate anomalies, and header analysis.

DDoS protection is enabled, the provider dashboard shows attack traffic being dropped, and the site still returns 503 errors. CPU is pinned, PHP workers are maxed out, and bandwidth looks almost normal. The usual first reaction is that the protection isn't working. More often it is working as designed. It filters the traffic it was built to recognize, and an application-layer attack doesn't look like that kind of traffic.

To see why, follow a single request from the network edge to the PHP worker and note what each layer checks.

What volumetric filtering actually inspects

Most DDoS mitigation sits in front of your server, at the network edge or in a scrubbing center. It works on layers 3 and 4, the IP and TCP/UDP level. At that level it sees packets: source address, destination port, protocol flags, packet size, and packets per second.

Those properties are enough to catch the classic floods. A SYN flood sends huge numbers of TCP SYN packets and never completes the handshake. The filter can answer with SYN cookies or drop sources that never send the final ACK. A UDP reflection attack shows up as large responses from DNS, NTP, or memcached servers that your host never queried. The filter drops them by source port and protocol. These attacks win by volume, and volume is what the filter measures.

The filter makes no judgment about what a request means. It cannot tell whether a GET for /search?q=x7k2p is a person searching or a bot. That decision happens several layers later.

The path a layer 7 request takes

An application-layer (L7) attack works one level up, at HTTP. Here is what one attacking client does, step by step:

  1. It opens a real TCP connection: SYN, SYN-ACK, ACK. The handshake completes, so SYN-flood protection has nothing to flag.
  2. It completes a TLS handshake if the site uses HTTPS. That costs your server or CDN some CPU for the key exchange, and the session is valid.
  3. It sends a well-formed HTTP request with a Host header, a believable User-Agent string, and a normal path.
  4. The web server (Nginx, Apache, or LiteSpeed) parses the request and checks its rules. If the page isn't served from cache, the request goes to the application backend.
  5. A PHP worker picks up the request, runs WordPress or whatever the app is, opens database connections, runs queries, and builds the page.

At the packet level, steps 1 to 3 look the same as a real visitor. The packets are normal size, the rate per source can be low, and the source IPs often belong to botnets or residential proxy networks with clean reputations. Once TLS is on, the network filter can't even read the HTTP layer unless TLS terminates at the protection service.

The damage happens at step 5, which is limited by a fixed number of workers. PHP-FPM caps concurrent PHP processes with pm.max_children. Apache caps them with MaxRequestWorkers. LiteSpeed has its own process and connection limits for lsphp. When every worker is busy, new requests wait in a queue. When the queue fills or a timeout expires, visitors get a 502, 503, or 504 depending on the stack.

This is why bandwidth looks fine while the site is down. A small GET request can make the server spend real effort: an uncached page, a search query that scans a large table, a WooCommerce cart action, or a call to wp-login.php that triggers password hashing. The attacker sends little data and the server does most of the work. A few thousand requests per minute against an expensive endpoint can saturate a worker pool that handles normal traffic easily. (That figure is an illustrative example. The real threshold depends on how long each request takes and how many workers you have.)

A related variant, Slowloris, starves connections by holding them open instead of making each request expensive. It is covered separately in Thinking DDoS Only Floods Bandwidth? Application-Layer Slowloris Starves Connections Instead.

Why you can't just block it all

It is tempting to block whole countries, ASNs, or everything that isn't on an allowlist. As Fortinet's DDoS overview notes, crude blocking methods often lock out legitimate users along with the attackers. The goal of a DDoS attack is to make the site unavailable to real users. If your mitigation does the same thing, the attacker gets the result without the effort. The work is to find the features that separate attack traffic from real traffic and filter on those.

Separating attack traffic from real traffic in the logs

Start with the access log. Before trusting any IP-based numbers, check whether the server sits behind a CDN or reverse proxy. If it does and real-IP handling isn't set up, every request appears to come from a few proxy addresses. In that case IP analysis tells you nothing until you log the forwarded client address.

These read-only commands assume the default combined log format. Adjust the path and field numbers to match your setup.

# Requests per minute, to see when the spike began and how sharp it is
awk '{print substr($4,2,17)}' /var/log/nginx/access.log | sort | uniq -c | tail -30

# Most requested paths (including query strings)
awk '{print $7}' /var/log/nginx/access.log | sort | uniq -c | sort -rn | head -20

# Top client IPs and top User-Agent strings
awk '{print $1}' /var/log/nginx/access.log | sort | uniq -c | sort -rn | head -20
awk -F'"' '{print $6}' /var/log/nginx/access.log | sort | uniq -c | sort -rn | head -20

Read the results together. One command alone rarely gives the full picture. A distributed L7 flood often has no single IP with an alarming count. Instead you see thousands of IPs that each made a modest number of requests, all aimed at a small set of paths. Real traffic spreads across your content: home page, product pages, images, CSS. Attack traffic tends to concentrate on one endpoint, or on one path with a random query string such as /?s=abc123. Random query strings defeat full-page caching, because each URL is new to the cache and goes through to PHP.

Also check how many connections the web server is holding, to see whether workers are stuck or the queue is growing:

# Summary of socket states
ss -s

# Established connections on port 443
ss -tn state established '( sport = :443 )' | wc -l

If established connections climb while the request rate in the log stays flat, connections are probably being held open (the Slowloris pattern). If both climb together and response times grow, workers are busy with expensive requests.

Signals a script usually gets wrong

Attack tools copy a browser User-Agent easily, because it's a single string. Copying everything else a real browser does is harder. These are the mismatches worth checking:

SignalReal browser, typicallyCommon in L7 attack traffic
Request mixHTML page followed by CSS, JS, images, fontsHTML or one endpoint only, no assets
Accept-Language, Accept-EncodingPresent and consistent with the browserMissing, or identical across thousands of IPs
CookiesSet on first visit and sent back afterNever sent back, so every request looks like a new session
RefererUsually present for navigation inside the siteEmpty, or one value repeated everywhere
HTTP versionHTTP/2 or HTTP/3 when the server supports itHTTP/1.1 from a client claiming to be a current Chrome or Firefox
TimingIrregular, with pauses between page viewsRegular intervals, or bursts in sync across many IPs

No single row is proof. Some privacy tools strip the Referer header, and corporate proxies can downgrade the HTTP version. A client that claims to be a current Chrome but sends no Accept-Language, never loads a stylesheet, never returns a cookie, and hits /?s= every two seconds is a clear case.

The default combined log format doesn't record most of these headers. During an incident it helps to add them temporarily. In Nginx, define a separate log_format that includes http_accept_language, http_cookie, and $server_protocol, and write it to its own file so normal logs stay parseable. Turn it off afterwards. The cookie header can contain session tokens, and that file should be treated as sensitive.

In support, the confusing part for customers is usually the dashboard. It shows attacks blocked, so they assume the remaining traffic is clean. A useful first check is to compare the protection service's view with the origin access log. If the edge reports nothing unusual while the origin log shows a concentrated spike on one path, the attack is passing through at L7.

Turning findings into filters

Once you know the pattern, mitigate as close to the edge as you can. Rate limiting per IP on the targeted path works when individual sources are noisy. For widely distributed floods, filter on the feature you identified instead: the path, the missing header, or the query string pattern. A JavaScript or managed challenge on that path drops clients that can't run a browser engine, while real visitors pass. Whether your DDoS or CDN provider offers L7 rules and challenges, and on which plans, depends on the provider. Check their documentation before an incident, not during one.

On the origin, lower the cost of each request. Make sure the targeted pages are cached, ignore or normalize unknown query parameters where the application allows it, and keep the worker pool sized to what RAM can support. Raising pm.max_children past available memory causes swapping and makes the outage worse.

The practical takeaway: DDoS protection usually reports what it blocked at the packet level, and an L7 flood is designed to pass that check. When workers are saturated but bandwidth is normal, go straight to the origin access log. Look for paths that are hit far more than usual, query strings that bypass the cache, and clients that send a browser User-Agent without behaving like a browser. Filter on those traits, not on whole regions, so legitimate visitors keep getting through.