A WAF, or web application firewall, is a security layer that sits in front of a website or web application and inspects every HTTP and HTTPS request before it reaches the server. It blocks requests that match known attack patterns, such as SQL injection and cross-site scripting, while letting legitimate traffic through. It works at the application layer, which is why it catches attacks a network firewall cannot see.
Key takeaways
- A WAF inspects the contents of web requests at the application layer, blocking SQL injection, cross-site scripting and other OWASP Top 10 attacks before they reach your app.
- It is not a replacement for secure code or a network firewall; it is one layer that also buys time with virtual patching when a vulnerability has no fix yet.
- PCI DSS v4.0 requires a WAF or equivalent protection in front of public-facing web applications that handle cardholder data.
Your network firewall allows web traffic through port 443, as it should. Hidden inside that allowed traffic, a single request can carry a database attack or a script that hijacks your visitors. A WAF is the layer that reads what is inside the request.
What is a WAF?
A web application firewall, or WAF, is a security solution that sits in front of a web application and inspects every HTTP and HTTPS request before it reaches the server. It blocks requests that match attack patterns and lets legitimate traffic through.
OWASP defines a WAF plainly as an "application firewall for HTTP applications" that applies a set of rules to an HTTP conversation. While a proxy generally protects clients, a WAF protects servers. It is usually deployed as a reverse proxy, so all traffic to the application passes through it first.
A WAF can be an appliance, a server plugin or a cloud service, and it can be customized to a specific application. That customization takes effort and needs maintenance as the application changes, which is one reason managed cloud WAFs are popular with small teams. If you want to see how your own site looks from the outside, run our free security headers checker as a first step.
How does a WAF work?
A WAF works by parsing each incoming web request, checking it against a set of rules, and then deciding to forward it, block it, or log it and alert. The check covers the URL, headers, cookies, query parameters and request body.
Take a search box on a shop site. A normal request contains a word like "shoes". An attack request contains something like "' UNION SELECT" in the same field. A network firewall sees only an allowed connection to port 443 and forwards it. The WAF reads the field, recognizes the injection pattern, and blocks the request before the database ever sees it.
Most WAFs also handle encrypted traffic. Because the WAF terminates the TLS connection, it can inspect the decrypted request, then re-encrypt it on the way to your server. That is also why the WAF must be trustworthy: it sees your traffic in plain text.
What is the difference between a WAF and a network firewall?
A network firewall decides which traffic may reach your network, based on IP addresses, ports and protocols. A WAF decides which web requests may reach your application, based on what is inside the request. You need both, because they see different things.
| Network firewall | WAF | |
|---|---|---|
| Layer | Network and transport (layers 3–4) | Application (layer 7) |
| Sees | IP addresses, ports, protocols | URLs, headers, cookies, bodies, parameters |
| Blocks | Unwanted connections and ports | SQL injection, XSS, file inclusion, bots |
| Typical form | Appliance or router feature | Cloud service, appliance or server module |
| Protects | The whole network | Specific web apps and APIs |
| Blind spot | Attacks inside allowed web traffic | Non-web traffic such as SSH or email |
Think of it this way: the network firewall is the locked gate to the building, and the WAF is the security guard at the reception desk who checks what each visitor is carrying. Our guide to the best firewall options covers the network side of that pair.
What attacks does a WAF block?
A WAF's main job is the application-layer attacks in the OWASP Top 10, the consensus list of the most critical web application security risks. Every commercial WAF covers these at a minimum, as Cisco's WAF guide explains.
- SQL injection: attacker input is interpreted as a database command, letting the attacker read, change or delete data.
- Cross-site scripting (XSS): attacker script is injected into pages and runs in visitors' browsers, stealing sessions or defacing the site.
- Local and remote file inclusion: requests that trick the server into loading files it should never serve, such as configuration files.
- Brute-force login attempts: rapid repeated login guesses, slowed or blocked by rate limiting.
- Known vulnerability exploits: probes for unpatched plugins, themes and frameworks, blocked by managed rules.
- Malicious bots: scrapers, credential stuffing and spam that mimic real users.
- Server-side request forgery (SSRF): requests that trick the server into calling internal services.
A WAF also helps with problems that are not attacks in the usual sense. It can block access to sensitive files such as .env backups and .git directories, enforce request size limits, and mask error details that would otherwise leak information about your stack.
How do WAF rules work? Negative vs positive models
Every WAF rule follows one of two philosophies, and most deployments run both. A negative security model blocks known-bad patterns, while a positive security model allows only traffic that matches what the application legitimately accepts.
The negative model is a blocklist. It uses signatures for known attacks, such as SQL injection patterns from the OWASP Core Rule Set, and blocks anything that matches. It is easy to start with and catches known attacks, but it cannot catch a brand-new attack pattern it has never seen.
The positive model is an allowlist. It defines what normal traffic looks like for your application: which URLs exist, which parameters each form accepts, and what values are valid. Anything outside that definition is denied. It is stronger, but it takes real work to build and maintain, because every application change can break it.
In practice, teams use managed rule sets for the negative model and add positive rules only for their most sensitive endpoints, such as login pages and admin panels. The OWASP Core Rule Set, maintained with ModSecurity, is the most widely used open-source rule set, and many cloud WAFs offer managed rule groups based on it.
What are the types of WAF deployment?
WAFs are deployed in three main ways: cloud-based, network-based and host-based. The right choice depends on where your application runs and how much control you want.
Cloud-based WAF
The WAF runs in the provider's network, and your DNS points visitors to it first. There is no hardware to buy and no software to install. Cloudflare, AWS WAF and Google Cloud Armor are common examples. This is the best fit for most small businesses.
Network-based WAF
The WAF runs as an appliance or virtual appliance inside your own network, in front of your web servers. It gives you full control and keeps traffic on your infrastructure, but you buy, patch and scale the hardware yourself.
Host-based WAF
The WAF runs on the web server itself, usually as a module such as ModSecurity for Apache or Nginx. It is cheap and flexible, and it can see application context other WAFs cannot, but it consumes server resources and needs someone who can tune it.
Many teams mix them: a cloud WAF in front for scale and DDoS protection, plus ModSecurity on the server for defense in depth. The open-source ModSecurity engine, paired with the OWASP Core Rule Set, remains a common choice for host-based deployments, according to OWASP.
WAF vs IPS vs NGFW: what is the difference?
A WAF, an intrusion prevention system (IPS) and a next-generation firewall (NGFW) all inspect traffic and block attacks, but each focuses on a different layer. They complement each other rather than replace each other.
| Tool | Layer | Main job | Best at |
|---|---|---|---|
| WAF | Layer 7, HTTP only | Protect web apps and APIs | SQL injection, XSS, API abuse |
| IPS | Layers 3–7, broad | Detect and block known exploits | Network exploits, malware traffic |
| NGFW | Layers 3–7, network edge | Control all traffic in and out | App-aware network policy, VPN, IPS |
An NGFW often includes IPS features and sometimes a basic WAF, but its WAF is rarely as deep as a dedicated one. For a public-facing web application, the dedicated WAF is the specialist. For the network as a whole, the NGFW is the gatekeeper.
What is virtual patching, and why does it matter?
Virtual patching is one of the most practical benefits of a WAF. When a vulnerability is announced in your application or a plugin, and no fix exists yet, you can add a WAF rule that blocks exploit attempts for that vulnerability until a real patch is available.
This matters because the gap between disclosure and patching is when attackers strike hardest. Automated scanners probe the whole internet for a new vulnerability within hours of disclosure. A WAF rule deployed in minutes can close that window for your site, even while you wait for the vendor's update.
Virtual patching is not a substitute for patching. It blocks the known exploit pattern, not the underlying flaw, and a determined attacker may find another way in. Treat it as a time-buyer, and still apply the real fix as soon as it ships.
Who needs a WAF?
Any organization with a public-facing web application or API should have one, and for some it is mandatory. The clearest requirement is PCI DSS v4.0, which makes a WAF or equivalent automated protection mandatory in front of public-facing web applications that handle cardholder data.
PCI DSS v4.0 Requirement 6.4.2 took effect as a mandatory requirement on 31 March 2025. If you take card payments through your own site, your auditor will ask about it. A cloud WAF is usually the simplest way to meet it.
Beyond compliance, a WAF is worth having if your site has logins, forms, an online shop, an API, or any admin panel reachable from the internet. Attackers scan every public IP address, so a small site is not too small to be found. A cloud WAF with a free tier can protect a small site at no cost, and the setup is usually a DNS change.
If your site is a static brochure with no forms and no logins, a WAF adds less value. Good hosting, HTTPS and keeping software updated matter more there. Check your site's TLS setup with our free SSL checker before spending on a WAF.
What can a WAF not do?
A WAF is not a complete security solution, and treating it as one is a common mistake. It only sees HTTP traffic, so it cannot protect email, SSH, or direct database connections, and it cannot fix insecure code.
- It cannot fix broken access control. If your app lets any logged-in user view another user's data by changing an ID in the URL, a WAF may not recognize the request as an attack.
- It cannot protect stolen credentials. A login with a valid password looks like a normal request to a WAF.
- It cannot stop DDoS alone. Large volumetric attacks need DDoS protection at the network edge, though many cloud WAFs bundle it.
- It can be bypassed. Attackers probe for ways around the WAF, such as encoding tricks or hitting the origin server directly if its IP address leaks.
- It needs tuning. Out of the box, rules can block legitimate users. Without monitoring and tuning, teams often turn the WAF off, which is worse than not having one.
Use the WAF as one layer: secure code and dependency updates, strong authentication, a network firewall, and monitoring behind it. The WAF buys time and blocks the noisy attacks, so your other controls can handle the rest.
How do you set up a WAF?
Start in monitoring mode, tune the rules, and only then switch to blocking. Rushing to blocking mode is the most common reason WAF projects fail, because the first false positive takes down a real customer.
- Pick the deployment type. A cloud WAF suits most teams; a host-based WAF suits teams that already manage their own servers.
- Point your DNS at the WAF so all traffic flows through it, and lock down your origin server so it only accepts traffic from the WAF.
- Enable the managed rule set for the OWASP Top 10, plus rules for your stack, such as WordPress or your API framework.
- Run in log-only mode for a week. Review what would have been blocked and whitelist the legitimate requests.
- Switch to blocking mode for the tuned rules, and keep monitoring the logs weekly.
- Set up alerts for spikes in blocked requests, which can signal an active attack or a broken rule.
Keep a runbook for false positives: who can add an exception, how fast, and how it is reviewed. A WAF that nobody can tune quickly becomes a WAF that gets switched off during an incident.
The bottom line
A WAF reads the web requests your network firewall cannot, and blocks the injection, scripting and bot attacks aimed at your application. It is not a fix for insecure code, but it is the fastest way to buy protection while you patch, and for card-handling sites it is a compliance requirement.
Start with the free tier of a cloud WAF, run it in monitoring mode, tune it, and then enforce it. And check the basics first: a valid certificate and solid security headers, which you can verify in seconds with the free security headers checker.
Frequently asked questions
What does WAF stand for?
WAF stands for web application firewall. It is a security tool that filters and monitors HTTP and HTTPS traffic to and from a web application, blocking malicious requests before they reach the server.
What is the difference between a WAF and a firewall?
A network firewall filters traffic by IP address, port and protocol. A WAF reads the contents of web requests, including URLs, headers, cookies and request bodies, so it can block attacks hidden inside allowed web traffic.
Do I need a WAF for a small website?
If your site takes logins, payments or form submissions, yes. Attackers scan the whole internet for vulnerable sites, and a cloud WAF can protect a small site for little or no cost while you keep the software updated.
Can a WAF stop SQL injection and cross-site scripting?
Yes, those are the attacks a WAF is built to stop. It inspects request parameters for injection patterns and blocks matching requests. It cannot fix the underlying code flaw, so you should still patch and use secure coding.
Does a WAF protect APIs too?
A modern WAF protects APIs as well as websites, because APIs also speak HTTP. API protection adds checks on request structure, rate limits and authentication, which a basic website WAF may not include.
What is the difference between a cloud WAF and a host-based WAF?
A cloud WAF runs in the provider's network in front of your site and needs no hardware. A host-based WAF runs on the web server itself, often as a module such as ModSecurity, and gives you more control at the cost of more maintenance.
Can a WAF block legitimate users by mistake?
Yes, false positives happen, especially with strict rules. That is why most teams start a new WAF in monitoring mode, review what it would have blocked, tune the rules, and only then switch to blocking mode.
Is a WAF required for PCI DSS compliance?
PCI DSS v4.0 Requirement 6.4.2 requires an automated technical solution, such as a WAF, in front of public-facing web applications that handle cardholder data. It became mandatory on 31 March 2025.
Sources
The engineers and analysts who build Cysoro's domain scanner, email-authentication checks and free security tools. We test what we write about every day — SPF, DKIM, DMARC, certificates, look-alike domains and phishing — and check each guide against the relevant standards, government guidance and vendor documentation.
Checked against OWASP's WAF definition, Cisco's WAF documentation and PCI DSS v4.0 Requirement 6.4.2.
How we write and fact-check →