Web Application Firewalls Explained
Understand what a web application firewall inspects, what it can and cannot stop, and how to roll one out without blocking real visitors.
Key takeaways
- A WAF works at the application layer, judging the contents and patterns of web requests.
- It helps against common injection attempts, known exploit patterns and abusive request rates.
- It can't reliably detect flaws in business logic or access control, which look like normal requests.
- Run new rules in a logging mode first and review false positives before blocking.
- If attackers can reach your server directly, they can walk around a WAF that sits in front of it.
A web application firewall, or WAF, inspects HTTP requests, and sometimes responses, and blocks or flags the ones that look harmful before they reach your application. It reads what an ordinary network firewall generally doesn't: URLs, headers, cookies and form data.
A WAF is a useful extra layer that can stop a lot of automated probing and buy time when a flaw is announced. It doesn't make vulnerable code safe, and it needs tuning so that it doesn't turn away legitimate customers.
Where it fits
A network firewall decides which addresses and ports may talk to a system. A web server has to leave ports 80 and 443 open to the public, so anything sent over those ports passes through. The WAF looks inside that permitted traffic.
Each layer covers gaps in the others. Distributed denial-of-service attacks in particular may need capacity far beyond what a rules engine on your own server can offer.
How it's deployed
- Cloud or CDN service. Your DNS points at the provider, which inspects traffic at its edge and forwards what passes. Setup is quick and capacity is large, but the provider decrypts your traffic.
- Appliance or load balancer feature. Runs in your own network or cloud account, in front of the servers.
- Server module. Software such as ModSecurity, or the Coraza engine, runs with your web server or proxy. You control everything and you maintain everything.
- Inside the application. Libraries or agents observe requests with knowledge of the framework.
Many managed hosts include one. Check whether yours does, and what it covers, before adding a second.
What rules look at
A signature or pattern rule matches things such as database syntax in a field that should hold a name, script tags in a query string, attempts to climb directories with ../, or request shapes tied to a published vulnerability. The OWASP Core Rule Set is a widely used open collection of generic rules.
Many rule sets use anomaly scoring: each suspicious feature adds points, and a request is blocked only past a threshold. That tolerates one odd character while catching a request that looks wrong in several ways.
Two broad models exist. A negative model blocks known bad patterns and allows the rest. A positive model describes what valid requests look like, for instance from an API schema, and rejects everything else. The positive model is stronger but takes more work to keep in step with the application.
Other controls often bundled in:
- Rate limits per client, key or path, especially on sign-in and password reset
- Bot detection and challenges
- Blocking or allowing by network or country
- Size limits and protocol validation
- Checks on responses for leaked error details
Rate limiting in practice
Rate limits are often the most useful WAF feature, and the easiest to get wrong. The idea is to count requests over a window and slow or refuse a client that exceeds a threshold, usually with the status 429 Too Many Requests.
Choose what you count carefully. Counting by IP address punishes a whole office or mobile network that shares one, while an attacker with many addresses slips under the limit. For signed-in traffic, counting by account or API key is fairer. For sign-in attempts, combine limits per account and per address, and be wary of rules that let a stranger lock someone else out by failing repeatedly on purpose.
Set limits from real traffic. Look at how many requests normal visitors make to the endpoint, including a single page that fires many calls, and leave generous headroom. Apply tight limits only to expensive or sensitive operations such as sign-in, search and message sending. More on the response itself is in 429 and rate limiting, and on identifying automation in how sites detect automated traffic.
What it helps with, and what it misses
| Threat | WAF usefulness |
|---|---|
| Generic injection probes | Good, though determined attackers vary their input |
| Scanning for known vulnerable software | Good, especially with updated rules |
| Newly announced flaws | Useful as a temporary "virtual patch" |
| Password guessing and credential stuffing | Helps with rate limits and bot signals |
| One user viewing another's records | Poor: the request looks normal |
| Abuse of business rules | Poor without custom logic |
| Stolen valid credentials | Limited |
The weak rows matter. If your application lets anyone change an order number in the address and see someone else's order, no generic rule knows that's wrong. Only the application can check ownership.
The same goes for injection. The real fix is parameterized queries and output encoding, covered in SQL injection and cross-site scripting for builders. A content security policy adds protection in the browser.
Virtual patching
When a serious flaw is announced in software you run, updating may take a while: a vendor fix isn't ready, a plugin needs testing, or a change window is days away. A rule that blocks requests matching the known attack can reduce exposure in the meantime. Providers of managed rule sets often publish such rules quickly for widely used products.
Treat it as temporary. A rule written against one form of an attack may miss another, and it does nothing if the system was compromised before the rule arrived. Record the rule with the flaw it covers, schedule the real update, check logs for signs of earlier exploitation, and remove the rule once the fix is in place and verified.
Rolling one out
- Inventory what you're protecting. Note unusual but legitimate behavior: rich text editors, file uploads, partner integrations, webhooks and your own monitoring.
- Start in detection mode. Log what would be blocked without blocking it.
- Review the logs over a representative period, including busy times and administrative work.
- Tune narrowly. If one rule misfires on one field of one page, exclude that combination, not the whole rule everywhere.
- Switch on blocking, perhaps for the clearest rules first.
- Show a helpful block page with a reference number so a wrongly blocked visitor can report it.
- Keep reviewing. Applications change, and so do rules.
Test only systems you own or are authorized to test, and tell your host before running anything that resembles an attack.
Reading a blocked request
When someone reports being blocked, find the log entry by its reference number or time. It should show which rule fired and which part of the request matched. Ask what the person was doing, and decide whether the input was legitimate.
If it was, scope the exception to that rule, parameter and path. If the field accepts free text, such as a comment box on a programming forum, you may need looser inspection there while the application does careful output encoding. If the request was an attack, leave the rule alone and look at what else that source tried.
Watch for patterns as well as single events: a burst of blocks against one address, probing of administrative paths, or many failed sign-ins. These deserve an alert to a person, with enough context to act. Reading the web server's own records alongside is helpful.
Protecting the origin
With a cloud WAF, your server must refuse traffic that didn't come through it. Allow web connections only from the provider's published address ranges, and where the provider supports it, require a client certificate or secret header that proves the request came from your configuration. Address ranges change, so automate the updates.
Also make sure the application reads the real client address from the provider's header, trusting it only on those connections. The pattern is the same as for any reverse proxy.
Privacy and logs
A WAF sees passwords, personal details and session cookies. Its logs may too. Mask sensitive fields, restrict who can read the logs, and set a retention period. With a third-party service, review where data is processed and what the contract says. Some industry standards and customer contracts mention WAFs or equivalent protections, so check the current wording that applies to you.
What can go wrong
- Blocking real customers. A name containing an apostrophe or a support message quoting code can trigger rules.
- Forgotten detection mode. The dashboard looks busy, but nothing is being stopped.
- Sprawling exceptions. Broad allow rules added in a hurry quietly disable protection. Date them and review them.
- False confidence. Patching gets postponed because "the firewall will catch it".
- Unclear failure behavior. Decide whether traffic flows or stops if the inspection engine fails.
- Broken integrations. Automated callers can't solve browser challenges. Authenticate them and give them their own rules.
Is one worth it for a small site?
If it comes with your host or CDN at little extra effort, enabling a managed rule set is usually sensible, especially for popular content management systems that attract constant automated probing. Running and tuning your own is a real commitment. For a static site with no forms or server code, there's little for it to protect.
Whatever you choose, keep software updated, use strong sign-in protection and have tested backups. If something does get through, follow what to do when your website is hacked.