---
title: "WAF"
description: "Inspect every request to a load balancer's HTTP and HTTPS listeners with managed rule sets and rules of your own, in block or log-only mode."
---

> 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

A WAF (web application firewall) inspects each request to a [load balancer](/load-balancers)'s
`http` and `https` listeners before it reaches a target. It runs EZGH-managed rule sets, such as the
OWASP Core Rule Set, and simple rules of your own: IP ranges, countries, autonomous systems, regular
expressions and rate limits. A WAF can block what it matches, or only log it.

The same WAF can also protect a [CDN distribution](/cdn): see
[Protect a distribution with a WAF](/cdn/guides/protect-with-a-waf).

- [Concepts](/waf/concepts) — Modes, evaluation order and attaching to a load balancer.
- [Managed rule sets](/waf/managed-rule-sets) — The Core Rule Set and EZGH's CVE rule sets, paranoia levels and rule overrides.
- [Custom rules](/waf/custom-rules) — Conditions on IP, ASN, country, path, query, headers, cookies and body.
- [Rate limits](/waf/rate-limits) — Limit each client IP's matching requests over a window.
- [Logging](/waf/logging) — Request logs in Observability: what's in a record and where it lands.
- [Pricing](/waf/pricing) — Per load balancer or distribution with a WAF attached.

The WAF API is at `https://waf-api.ezghcloud.com`. In the console, open **WAF**.

## Create a WAF and attach it

1. Write the WAF. This one runs the Core Rule Set and the PHP rule set, in log-only mode while you
   check what it would block:

   ```json title="waf.json"
   {
     "name": "storefront",
     "mode": "log",
     "managedRuleSets": [
       { "name": "ezgh/core" },
       { "name": "ezgh/php" }
     ],
     "logging": { "scope": "matched", "environment": "production" }
   }
   ```

2. Create it:

   ```sh
   ezgh waf create --from-file waf.json
   ```

3. Attach it to a load balancer:

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

4. [Find what it matched](/waf/guides/find-blocked-requests) in Observability. When it only matches
   attacks, set `mode` to `block`.

In the API, [CreateWaf](/waf-api/CreateWaf/) creates a WAF, and `wafId` on
[UpdateLoadBalancer](/lb-api/UpdateLoadBalancer/) attaches it.

## Limits

| Limit | Value |
| --- | --- |
| WAFs per project | 10 by default, up to 50 |
| Custom rules per WAF | 100 |
| Conditions per rule | 1 to 5 |
| Addresses and CIDR blocks per IP set condition | 1,000 |
| ASNs per condition | 100 |
| Countries per condition | 250 |
| Value or regular expression | 1,024 bytes |
| Rule overrides per managed rule set | 100 |
| Request body inspected | The first 16 KB of a request body |

A create over a quota is refused with [`409 quota_exceeded`](/quotas/quota-exceeded). Request an
increase on the console's **Service quotas** page.

## IAM

| Policy | Allows |
| --- | --- |
| `WafFullAccess` | Create, change, attach and delete WAFs. |
| `WafReadOnlyAccess` | View WAFs and the managed rule sets. `ReadOnlyAccess` includes the same. |

| Action | Allows |
| --- | --- |
| `waf.wafs.list` | List a project's WAFs |
| `waf.wafs.get` | View a WAF and its rules |
| `waf.wafs.create` | Create WAFs |
| `waf.wafs.update` | Change a WAF and its rules |
| `waf.wafs.delete` | Delete a WAF |
| `waf.wafs.attach` | Attach a WAF to a load balancer, and detach it |
| `waf.managedRuleSets.list` | List the managed rule sets |
| `waf.managedRuleSets.get` | View a managed rule set |

Attaching also needs `lb.loadBalancers.update` on the load balancer. Creating or changing a
WAF with [logging](/waf/logging) on needs `obs.logs.ingest` on its project.

## Trails

[Trails](/trails) records every change, with the caller and the WAF:

| Kind | Events |
| --- | --- |
| Changes | `CreateWaf`, `UpdateWaf`, `DeleteWaf` |
| Attachments | `AttachWaf`, `DetachWaf`, when a load balancer's `wafId` attaches or detaches the WAF, beside the load balancer's `UpdateLoadBalancer` |

- A change that's refused is recorded too, with `errorCode`.
- Reads, such as `GetWaf`, `ListWafs`, `GetManagedRuleSet` and `ListManagedRuleSets`, aren't recorded,
  allowed or refused.
- Rule values (regular expressions, addresses) and individual requests are never recorded.

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