Lab note · · 9 min read
Seven WAF layers — and why one is never enough
One layer is either fast rules without context or a smart model without a cost budget. The answer is not a stronger layer, it is ordering layers by processing cost.
The usual question: why seven layers? The short answer: because each layer sees something the others cannot, and some are extremely cheap while others are expensive. The common mistake is not the count, it is the order.
The layers as built
- Validation and normalisation: the cheapest of all — shape, size and encoding checks before any analysis.
- Signature rules: known high-confidence patterns. They settle the overwhelming majority of direct injection attempts.
- Behavioural anomaly: does this request resemble this user's other requests? Deviation from expected behaviour is a strong signal.
- Rate limiting: a time-bound rather than content-bound layer; its job is to slow abuse, not to stop it alone.
- Content analysis: inspecting encoded and obfuscated payloads that passed the earlier layers.
- Source reputation: external context — address history, origin network, previously seen signals.
- Language-model arbitration: the most expensive layer, therefore the last, acting on a minority of requests only.
The "least expensive first" principle
The order follows cost, not strength. Deterministic layers settle almost everything for free, and the language model is invoked only on real doubt. The result: near-constant latency for legitimate users, and higher detection of what rules ignore.
Three design decisions I paid for
- A timeout is mandatory: a smart layer without a timeout means an attacker can reshape your response time by slowing the model. Our bound is fixed in code, not in configuration.
- On ignorance: challenge, never block. If arbitration fails or times out we send a challenge, not a block. Blocking on ignorance punishes legitimate users.
- Log every decision: each decision is stored with the contributing layer reasons. Without that you can neither explain a decision nor tune a threshold.
The mistake I made first: running every request through the language model. It cost time and money with no benefit, because 95% of requests need rules, not reasoning. Reordering is what produced the real improvement.