---
title: "WAF concepts"
description: "What a WAF inspects, how its rules are evaluated, block and log-only modes, and attaching it to a load balancer."
---

> Documentation Index
> Fetch the complete documentation index at: https://docs.ezghcloud.com/llms.txt
> Use this file to discover all available pages before exploring further.

# WAF concepts

## What a WAF inspects

A WAF attached to a load balancer inspects every request to the load balancer's `http` and `https`
listeners: its method, path, query, headers, cookies and the first 16 KB of a request body. `tcp` and
`tls` listeners pass untouched.

A WAF is in a project and a region, and attaches to load balancers and
[CDN distributions](/cdn/guides/protect-with-a-waf) in the same project and region. One WAF can be
attached to several of them; a load balancer or distribution has at most one WAF.

## Evaluation order

Each request goes through:

1. The [custom rules](/waf/custom-rules), top to bottom. The first matching rule that ends the request
   wins: `allow` lets it through and skips the managed rule sets, and `block` answers `403`. A `log`
   rule records the match and carries on, and a [rate limit](/waf/rate-limits) ends the request only for a
   client over its limit.
2. The [managed rule sets](/waf/managed-rule-sets), in the order the WAF lists them. A set that
   blocks answers `403`.
3. Requests that nothing ended are allowed.

## Block and log-only

A WAF's `mode` is `block` or `log`. In `log` (**Log only** in the console), every block of the WAF,
from any rule or managed rule set, is recorded instead, and the request goes on to its target. Each
managed rule set has its own `mode` too, so you can try a new set in log-only mode while the rest of
the WAF blocks.

Start a new WAF, or a new set, in log-only mode, read its [logs](/waf/logging), then switch it to
`block`.

## Attach and detach

A load balancer's `wafId` attaches a WAF: set it to a `waf_` ID with
[UpdateLoadBalancer](/lb-api/UpdateLoadBalancer/), or to `null` to detach.

```sh
ezgh lb load-balancers update lbr_4k2m9x0a7qpe --waf waf_8m2k4q6t9x1c
ezgh lb load-balancers update lbr_4k2m9x0a7qpe --waf none
```

- Attaching needs `waf.wafs.attach` on the WAF and `lb.loadBalancers.update` on the load balancer.
- A WAF in another project or region is refused with `409 waf_mismatch`.
- The load balancer's `waf` shows the WAF `version` it runs and its `status`: `applying` while a
  change reaches the load balancer, then `applied`, or `not_applied` if that version can't be
  applied; the load balancer's `lastChange` says so, and it keeps serving with the version before.

## Changing a WAF

[UpdateWaf](/waf-api/UpdateWaf/) replaces the whole WAF: send it with the `ETag` of the version
you read in `If-Match`. Each change raises the WAF's `version`, and reaches the load balancers it's
attached to in seconds.

| Error | Means |
| --- | --- |
| `400 invalid_request` | A field is wrong; `issues` lists each problem at its path, such as `rules.2.conditions.0.value`. |
| `412 precondition_failed` | The WAF changed since you read it. Read it again and retry. |
| `422 waf_too_large` | The WAF is too large. Use fewer or smaller country, ASN and IP set conditions. |
| `409 waf_in_use` | A delete of a WAF that's attached. The message names the load balancers; detach it from them first. |

Source: https://docs.ezghcloud.com/waf/concepts/index.mdx
