Web Security

What Is a Web Application Firewall (WAF)?

A plain-English guide to web application firewalls: what a WAF filters, the deployment types, OWASP rule sets, false positives, and when a site needs one.

StackOptic Research Team18 May 202610 min read
What a web application firewall (WAF) is and how it filters traffic

A web application firewall is a protective layer that stands between the internet and your website, reading every incoming request and blocking the malicious ones before they reach your application. In plain terms, a WAF filters HTTP traffic — it inspects each request for the signatures of common attacks (injection, cross-site scripting, malicious bots, application-layer floods) and stops the bad ones while letting genuine visitors through. This guide explains what a WAF actually does, the different ways it can be deployed, how its rule sets work, the all-important question of false positives, and how to decide whether your site needs one.

It is a natural companion to how to protect your website from common attacks, where a WAF appears as one layer in a wider defence, and to HTTP security headers explained.

What a WAF actually does

Every request to your website is an HTTP message: a method (GET, POST), a URL, a set of headers, and sometimes a body carrying form data or an API payload. A web application firewall parses that message and evaluates it against a set of rules before passing it on to your application — or rejecting it. If a request carries the hallmarks of a SQL injection attempt, a cross-site scripting payload, or a known exploit pattern, the WAF can block it, challenge it (for example with a CAPTCHA or a JavaScript test), or simply log it, depending on how it is configured.

The crucial point is that a WAF operates at the application layer and understands web traffic specifically. It does not just look at where a request came from; it looks at what the request is trying to do. That is what lets it catch an attack hidden inside an otherwise ordinary-looking request — a malicious string smuggled into a search box or a URL parameter — that a lower-level control would wave straight through.

Beyond blocking classic application attacks, modern WAFs typically also handle:

  • Bot mitigation — distinguishing real users from automated scrapers, credential-stuffing bots and vulnerability scanners, and throttling or blocking the abusive ones.
  • Application-layer (Layer 7) DDoS protection — absorbing or filtering floods of HTTP requests designed to exhaust your application, as opposed to the raw network floods a network-layer defence handles.
  • Rate limiting — capping how many requests a single client can make in a window, which blunts brute-force and scraping attacks.
  • Virtual patching — adding a rule that blocks exploitation of a specific known vulnerability, buying you time to deploy a real fix in your code.

WAF versus a traditional firewall

People often conflate a WAF with the network firewall they already know, so it is worth drawing the line clearly.

A traditional network firewall works at the network and transport layers. It decides whether to allow a connection based on IP addresses, ports and protocols — for example, "allow inbound traffic on port 443, block everything else." It is essential, but it has no idea what is inside the web requests it permits. Once a request is allowed through on port 443, the network firewall's job is done.

A web application firewall works at the application layer (Layer 7). It inspects the content of the HTTP request itself and judges whether that content is malicious. It is the difference between a security guard who checks whether you are allowed into the building (the network firewall) and one who inspects what you are carrying once you are inside (the WAF).

The two are not alternatives; they are layers in defence in depth. You want both: the network firewall to control connectivity, and the WAF to inspect the web traffic that connectivity allows.

The three types of WAF

WAFs differ mainly in where they sit relative to your application. There are three broad deployment models, each with tradeoffs.

Cloud / CDN-based WAF. This is the most common model for ordinary websites today. The WAF runs as a reverse proxy in the cloud: you point your domain's DNS at the provider, all traffic flows through their network first, and clean traffic is forwarded to your origin server. Because it sits at the edge — often bundled with a content delivery network — it can also absorb large DDoS attacks far from your server and serve cached content. It requires no hardware and little maintenance, and the provider keeps the rules updated. Cloudflare, AWS WAF (with CloudFront), Akamai, Fastly, Imperva and Azure's offering are well-known examples. The tradeoff is that your traffic passes through a third party, and configuration lives on their platform.

Host-based WAF. Here the WAF runs as a module inside your own web server or application. The classic example is ModSecurity, an open-source engine that plugs into web servers such as Apache and Nginx and traditionally ships with the OWASP Core Rule Set. A host-based WAF gives you deep control and keeps everything on your own infrastructure, but it consumes your server's resources, scales only as your servers do, and demands more hands-on maintenance and tuning.

Network-based WAF. This is a dedicated appliance (hardware or a virtual appliance) deployed close to your servers, typically in a data centre. It offers high performance and low latency and is favoured by large enterprises with their own infrastructure, but it is the most expensive and operationally heavy option, and it does not, by itself, give you the globally distributed edge that a cloud WAF does.

WAF typeWhere it runsBest forTradeoffs
Cloud / CDNReverse proxy at the provider's edgeMost websites; easy DDoS + bot mitigationTraffic routes via a third party; config on their platform
Host-basedModule inside your web server (e.g. ModSecurity)Teams wanting full control on their own serversUses server resources; more maintenance and tuning
Network-basedDedicated appliance near your serversLarge enterprises with own data centresCostly; heavy to operate; no global edge by itself

For most site owners reading this, a cloud/CDN WAF is the pragmatic default: low effort to switch on, no hardware, automatic rule updates, and DDoS protection included.

Rule sets: how a WAF decides what to block

A WAF is only as good as its rules. Most WAFs combine two complementary philosophies.

Negative security (blocklist). This is the default for most WAFs: maintain a library of known-bad patterns — attack signatures — and block any request that matches one. Negative security is broad and low-effort because you do not have to describe your application; you just block recognised attacks. Its weakness is that it can miss novel attacks that do not match a known signature, and overly broad patterns can catch innocent traffic.

Positive security (allowlist). The inverse approach: define what legitimate traffic looks like for your application — which URLs, parameters, methods and value formats are valid — and block everything else by default. Positive security is stronger because it can stop attacks no one has seen before, but it is far more work to build and maintain, because you must accurately model your whole application and keep that model in step as the app changes.

The strongest posture uses both: a positive-security core that permits only well-formed requests, backed by negative-security rules that catch known attacks within that envelope.

Underpinning much of this is the OWASP Core Rule Set (CRS) — a free, open-source, vendor-neutral set of generic detection rules maintained by the OWASP community. The CRS detects common attack classes aligned with the OWASP Top 10 and is widely used as a baseline by both open-source engines like ModSecurity and many commercial WAFs, which then layer their own managed rules (frequently updated, sometimes with threat intelligence) on top. OWASP is the authoritative, reputable reference here, and its documentation on the CRS is the place to understand exactly what those baseline rules cover.

The catch: false positives

The single biggest operational challenge with a WAF is the false positive — a legitimate request that the WAF wrongly identifies as an attack and blocks. A rule meant to catch SQL injection might trip on a genuine search for a string that happens to contain SQL-like characters; a strict rule set might block a perfectly valid form submission. Get this wrong and you do not just annoy users — you can break your checkout, your contact form or your API for real customers, which is worse than the attack you were guarding against.

The remedy is process, not luck. The standard, safe rollout mirrors the one used for a Content Security Policy:

  1. Deploy in detection / log-only mode first. The WAF evaluates traffic and records what it would have blocked, without actually blocking anything.
  2. Observe over a representative period. Real usage — every page, every form, every legitimate integration and bot you rely on — reveals which rules generate false positives.
  3. Tune. Adjust rule sensitivity, create targeted exceptions for the legitimate traffic that was flagged, and (for managed rule sets) raise or lower the paranoia/aggressiveness level to balance protection against noise.
  4. Switch to blocking only once the logs show that enforcement would stop attacks without harming genuine traffic.
  5. Keep watching. As your application changes, revisit the rules so a new feature is not silently blocked by an old rule.

The opposite failure mode is the false negative — a real attack the WAF misses — which is why a WAF is a layer, not a guarantee. Tuning is the art of pushing both kinds of error as low as you reasonably can.

Where a WAF fits — and where it does not

It is vital to frame a WAF correctly: it is a defence-in-depth layer, not a substitute for secure software. A WAF can block many exploitation attempts and give you breathing room through virtual patching, but the underlying vulnerability is still there until you fix it. The fundamentals remain non-negotiable: validate input and use parameterised queries to stop injection, encode output and deploy a CSP to stop cross-site scripting, keep all your software patched, enforce strong authentication, and run HTTPS everywhere. A WAF sits on top of those, catching what slips through and absorbing automated noise — it does not let you skip them.

It also pairs naturally with detection. A WAF's logs are a rich source of signal about who is probing your site and how, which feeds directly into spotting whether a site has been compromised. A spike in blocked injection attempts, or a sudden flood from one network, is exactly the kind of anomaly worth noticing early.

When does a website need a WAF?

Not every site needs one to the same degree, so weigh your situation.

A WAF is most valuable when you:

  • Handle logins, payments or sensitive personal data, where a breach is costly.
  • Run a popular CMS or platform (WordPress especially) that is relentlessly targeted by automated attacks against known plugin and theme vulnerabilities.
  • Cannot always patch instantly, so virtual patching buys you time.
  • Suffer from bots, scraping, or application-layer DDoS, where the WAF's mitigation features directly help.
  • Have a compliance requirement (some standards expect a WAF or equivalent control in front of card-handling applications).

A WAF is least essential for a tiny, purely static site with no forms, logins or dynamic processing — there is little application surface to attack — though even then the bot and DDoS mitigation in a cloud WAF can be a nice-to-have, and it usually costs nothing extra on a CDN you might use anyway.

Because so many CDNs now bundle a WAF, the practical barrier to adding this layer has fallen dramatically. For most public-facing sites, switching on a sensibly tuned cloud WAF is a low-effort, high-value improvement to your security posture.

A quick WAF checklist

  • Decide on a deployment model — cloud/CDN is the pragmatic default for most sites.
  • Start from a reputable managed rule set (often built on the OWASP CRS) rather than writing rules from scratch.
  • Deploy in detection/log-only mode first, then tune out false positives before enforcing.
  • Enable rate limiting and bot mitigation for login and form endpoints.
  • Use virtual patching to cover a known vulnerability while you ship the real fix.
  • Review the logs periodically — they are an early-warning system as well as a defence.
  • Remember the WAF is one layer: keep patching, validating input, and enforcing strong auth and HTTPS underneath it.

Go deeper

Want a fast read on your site's headers, HTTPS and configuration gaps? Analyse any URL with StackOptic — security, performance and SEO in one free report.

Frequently asked questions

What is a web application firewall (WAF)?

A web application firewall is a security layer that sits between visitors and your website and inspects the HTTP traffic flowing to it. It applies a set of rules to each request and blocks or challenges anything that looks malicious — for example injection attempts, cross-site scripting, malicious bots and application-layer floods — before that traffic ever reaches your application. Unlike a traditional network firewall, a WAF understands web requests specifically, so it can act on the content of a request, not just its source and port.

How is a WAF different from a regular firewall?

A traditional network firewall works at the network layer, allowing or blocking traffic based on IP addresses, ports and protocols. It has no understanding of what is inside a web request. A WAF works at the application layer (Layer 7): it parses the actual HTTP request — the URL, headers, parameters and body — and decides whether the content is malicious. The two are complementary. A network firewall controls who can connect; a WAF inspects what they are trying to do once connected over HTTP.

What is the OWASP Core Rule Set?

The OWASP Core Rule Set (CRS) is a free, open-source set of generic detection rules maintained by the OWASP community and used by many WAFs as a baseline. It detects common attack patterns aligned with the OWASP Top 10 — injection, cross-site scripting, protocol violations and more — without being tied to any single vendor. Because it is well tested and widely deployed, the CRS is a sensible foundation that many commercial and open-source WAFs build on, layering their own managed rules on top.

Do false positives make a WAF risky to use?

False positives — legitimate requests wrongly blocked — are the main operational challenge of running a WAF, but they are manageable. The standard approach is to deploy the WAF in a detection or log-only mode first, watch what it would have blocked over a representative period, tune or create exceptions for the legitimate traffic it flags, and only then switch to blocking. Done this way, a WAF protects you without breaking real users. Enforcing a strict rule set blind, without tuning, is what causes problems.

Does my website need a WAF?

Most public-facing sites benefit from one, and for common platforms like WordPress a WAF is close to essential because they are heavily targeted by automated attacks. A WAF is most valuable if you handle logins, payments or sensitive data, run software you cannot always patch instantly, or face bot and scraping problems. It is least essential for a tiny static site with no dynamic functionality. Because many CDNs include a WAF, the barrier to adding this layer is now low.

Analyse any website with StackOptic

Get the full technology stack, performance, security and SEO report in seconds — free.

Analyse a website

Related articles