Protection

12 min readUpdated

WAF vs firewall: what each one stops, and when you need both

Quick answer

A network firewall decides which connections may reach a host, using IP addresses, ports, protocols and connection state at layers 3 and 4. A web application firewall (WAF) sits in front of a website or API and inspects each HTTP or HTTPS request, including its path, headers and body, at layer 7. A firewall cannot tell a harmful request from a harmless one on an open port, and a WAF does nothing for services that do not speak HTTP. Next-generation firewalls overlap with both. A public website normally needs both: a WAF in front, and an origin firewall that only admits the WAF.

01WAF vs firewall: the short answer

The two tools answer different questions. A firewall asks whether a connection should exist at all: is the source allowed, is the port open, does this packet belong to a connection already in progress? A web application firewall asks whether one particular HTTP request is safe to hand to the application. Every visitor to a public website connects to the same open port, so the firewall's answer is the same for a customer and an attacker; only the request differs, and the request is what a WAF reads.

NIST's firewall guideline, SP 800-41, describes web application firewalls as specialised application firewalls that reside in front of the web server, and notes that because of that position they are often considered very different from traditional firewalls. For how a WAF works on its own, see what is a WAF; this page compares the two.

02What a network or host firewall does

A firewall applies a ruleset to packets. In its basic form, the packet filter, it decides from the source and destination address, the protocol (TCP, UDP or ICMP), the source and destination ports, and the interface and direction the packet is travelling. SP 800-41 puts the limit plainly: packet filters 'are not concerned about the content of packets'.

Stateful inspection adds memory. The firewall keeps a state table of connections, typically with addresses, ports and connection state, and checks each new packet against it: a packet claiming to belong to a connection the table does not know is refused, and replies to allowed traffic return without a rule of their own. Linux packet filtering with nftables, iptables or ufw, appliances such as pfSense, and cloud security groups all work this way; the pfSense and AWS documentation both describe their firewalls as stateful.

There are two common placements. A network firewall sits at a boundary, between the internet and a data centre or between internal segments, and protects every host behind it. A host-based firewall runs on the server itself and, in NIST's words, monitors and controls the incoming and outgoing network traffic for a single host. The recommended policy is the same for both: block all traffic that has not been expressly permitted, which NIST calls deny by default. Firewall configuration has Linux baselines that follow it.

03What a web application firewall does

OWASP defines a WAF as an application firewall for HTTP applications that applies a set of rules to an HTTP conversation. To apply those rules it has to see each request the way the application will: method, path, query string, headers, cookies and body, decoded and, for HTTPS, decrypted. That is why a WAF is usually deployed as a reverse proxy that terminates TLS and opens its own connection to the origin, although OWASP also lists appliances, server plugins and filters as forms it can take.

Rules decide what happens to each request: allow, log, block, challenge the client or apply a rate limit. Managed rules are maintained by the WAF provider or an open project such as the OWASP Core Rule Set (CRS) and target attack classes that look alike in every application, including SQL injection, cross-site scripting, local file inclusion and command injection. Custom rules are written for one site, for example a request limit on the login path or an admin URL closed to everyone outside an office network.

Because it works on requests, a WAF can act on things a firewall has no way to see: an exploit string in a form field, a client hammering the password-reset endpoint, or a burst of expensive search queries in an HTTP flood. The price is scope. A WAF understands HTTP and nothing else, so a mail server, a database port or a game server gets no protection from it.

04Firewall vs NGFW vs WAF side by side

The table compares the three categories as they are commonly deployed. Products differ, and many combine features from more than one column. Tools are examples of each category, in no particular order.

Network or host firewallNext-generation firewall (NGFW)Web application firewall (WAF)
OSI layer3 and 43 and 4, plus 77 (HTTP and HTTPS)
SeesAddresses, ports, protocol and connection stateThe same, plus which application a flow belongs to and, with TLS decryption, the payloadMethod, path, query string, headers, cookies and body of each request
Typical placementNetwork edge, between segments, on each host, or as a cloud security groupNetwork edge and internal segments, covering many hosts and users in both directionsIn front of specific websites or APIs, usually as a reverse proxy
BlocksClosed ports, unwanted sources, packets that do not fit a known connectionUnwanted applications, traffic matching intrusion-prevention signatures, policy violationsInjection, cross-site scripting, path traversal, abusive request rates, unwanted paths and methods
MissesAnything carried inside an allowed connection, such as an exploit sent to port 443Encrypted traffic it is not set up to decrypt, and application details it has no rules forNon-HTTP protocols, traffic that bypasses it, and flaws in business logic
Default modelPositive: deny by default, allow listed ports and sourcesPositive for access policy, negative for intrusion signaturesManaged rules mostly negative, with positive rules where the application is well defined
Examples by categorynftables, iptables, ufw, pfSense, cloud security groupsHardware appliances, virtual appliances and firewall-as-a-service offeringsModSecurity or Coraza with the OWASP CRS; cloud WAFs run by CDN, hosting and cloud providers

05WAF vs NGFW: where application-aware firewalls overlap

The line between the categories blurred once firewalls learned to read layer 7. SP 800-41 already described application firewalls that use stateful protocol analysis, which some vendors call deep packet inspection, to notice instant messaging running over port 80 or to stop users issuing the FTP put command. NIST's later guide to enterprise networks, SP 800-215, names application data awareness as the distinguishing feature of a next-generation firewall and lists deep packet inspection, TLS decryption and inspection of the payload, and intrusion prevention among its capabilities.

So an NGFW can look inside HTTP, and the overlap with a WAF is real, but the jobs differ. An NGFW enforces network policy for many hosts and users: which applications may run, which segments may talk to each other, what may leave the network. A WAF protects particular web applications from the requests sent to them; OWASP's summary is that while proxies generally protect clients, WAFs protect servers. SP 800-215 lists NGFWs and WAFs as separate classes, and describes web application and API protection (WAAP) as an enhancement over the WAF.

The difference shows up in three places. Decryption: a firewall has to decrypt HTTPS to inspect it, and SP 800-41's general rule is that firewalls only work effectively on traffic they can inspect. Granularity: WAF rules use the application's own terms, such as hostname, path, parameter or cookie, and can answer with an HTTP response such as a block page or 429 Too Many Requests. Placement: an NGFW usually sits on your network, a cloud WAF on the provider's, in front of your origin. An NGFW that already decrypts your inbound web traffic with rules that fit your application may cover part of a WAF's job; how much is for your own testing to show.

06Positive vs negative security model

Every filter, at any layer, follows one of two models or a mix of both. OWASP describes a positive security model, also called an allowlist, as one that 'defines what is allowed, and rejects everything else', and a negative security model, or blocklist, as one that defines what is disallowed while implicitly allowing everything else.

The two layers lean in opposite directions. Network firewalls are positive by design: a deny-by-default ruleset names the few ports and sources that are allowed, and an AWS security group accepts allow rules but no deny rules at all. That works because the legitimate connections to a server are few and stable. WAF managed rules lean negative: CRS describes its rules as providing 'generic attack detection capabilities', and its rule files look for SQL injection, cross-site scripting, command injection and other known patterns in any request. The legitimate requests to a web application are many and change with every release, and OWASP's virtual patching guidance calls positive rules often a manual process that does not scale and is difficult to maintain for large or dynamic sites.

Neither model is pure in practice. CRS blocks HTTP methods missing from its configured list of allowed methods and only allows content types it knows the WAF can parse safely: allowlists inside a mostly negative ruleset. APIs are a clear case for a positive model at layer 7, because an OpenAPI description already names every path, operation and parameter, where each parameter appears and the schema it must match, so a gateway or WAF can reject requests that break the contract. OWASP's REST security guidance does the same for methods and media types: allowlist the permitted methods and answer others with 405, and refuse unsupported content types with 415.

Positive model (allowlist)Negative model (blocklist)
DefinesWhat valid traffic looks likeWhat known attacks look like
Anything not listedRejectedAllowed
Network-layer exampleDeny by default; allow TCP 443 from anywhere and SSH from an admin rangeDrop a list of known bad source addresses
Application-layer exampleA parameter that must match ^[0-9]+$; requests checked against an OpenAPI schemaCRS rules for SQL injection or cross-site scripting; a rule that blocks a single quote in one parameter
StrengthStops attacks nobody anticipated, as OWASP's description of the model points outQuick to deploy and works without detailed knowledge of the application
WeaknessHas to be written per application and kept in step with it, or new legitimate features are rejectedMisses new or rewritten payloads, flags legitimate input that resembles an attack, and the list keeps growing
The same parameter protected both ways, from OWASP's Virtual Patching Cheat Sheet (ModSecurity rule language). Only the conditions are shown; the full rules also restrict the URL and set the block action.
# positive: reqID may only contain digits; any other value matches and is blocked
SecRule ARGS:/reqID/ "!@rx ^[0-9]+$"

# negative: block the single quote seen in the attack; other payloads may still pass
SecRule ARGS:/reqID/ "@pm '"

07Do you need both?

For a public website or API, yes. Each covers a gap the other leaves open. NIST defines defence in depth as 'the application of multiple countermeasures in a layered or stepwise manner', and SP 800-41 notes that multiple layers of firewalls are common for that reason.

The usual layout is simple. The WAF receives all web traffic. The origin's firewall, on the host or as a cloud security group, denies by default, admits ports 80 and 443 only from the WAF provider's published address ranges, and limits SSH and other administration to a management network. Without that restriction, anyone who finds the origin address can skip every WAF rule by connecting directly; hiding your origin IP covers how addresses leak, and nginx real IP restores visitor addresses in your logs once only the proxy connects. AWS documents the same pattern with web servers that accept HTTP and HTTPS only from a load balancer's security group, and SP 800-41 advises filtering by IP address at the perimeter so that an application firewall can spend its capacity on content.

What you runFirewallWAF
Public website, shop or APIYes, admitting web traffic only from the WAFYes
Database, SSH, internal toolsYes, limited to the hosts and people that need accessOnly for tools with a web interface
Game, mail, VPN or other non-HTTP serviceYes, plus Layer 3/4 protection where floods are a riskNo: there is no HTTP to inspect
Office network and staff internet accessYes, often an NGFWOnly for web applications you host

08What neither one stops on its own

A volumetric flood that fills your internet link is a capacity problem, and neither tool adds capacity. A firewall on your server or at your network edge only sees the packets after they have used the link, and a stateful one can run out of connection-table space before the bandwidth runs out; can a firewall stop a DDoS attack works through the numbers. WAF rules apply to requests, and a packet flood never becomes a request. Where a cloud WAF keeps such floods away from an origin, the provider's network is doing that work, not the rules; what DDoS mitigation is explains the difference.

HTTP floods sit on the other side of the line. Each request is valid at the packet level, so a firewall passes it, while a WAF with rate limiting can count requests per client and per path. A few gaps remain for both tools:

  • Flaws in business logic and access control: a request for another customer's order can be perfectly well formed, which is why several categories in the OWASP Top 10 are out of reach for any request filter
  • Traffic that never passes the control: calls between internal services, a directly reachable origin, or a protocol the WAF does not handle
  • Content the filter cannot read: a firewall without decryption cannot inspect HTTPS payloads, and a WAF can only inspect body formats it can decode, which is why CRS refuses content types it cannot parse safely
  • Unpatched code: a rule can reduce exposure after a disclosure, but the vulnerability stays until the software is fixed

Questions

Frequently asked questions

01Is a WAF a type of firewall?
Yes. NIST's firewall guideline, SP 800-41, describes web application firewalls as specialised application firewalls that sit in front of a web server. Both apply a ruleset that allows or blocks traffic, but a WAF works on HTTP requests at layer 7, while a classic firewall works on packets and connections at layers 3 and 4.
02Can a WAF replace a network firewall?
No. A WAF only handles HTTP and HTTPS for the sites routed through it. SSH, databases, mail and every other port on the server still need a firewall, and the origin's firewall is also what stops attackers from bypassing the WAF by connecting to the server directly.
03Can a next-generation firewall replace a WAF?
Partly, in some set-ups. An NGFW can inspect layer 7 traffic and decrypt TLS, and some include web attack signatures. Whether that is enough depends on whether it actually decrypts your inbound HTTPS, how closely its rules fit your application, and whether it can apply per-path policies such as rate limits. NIST SP 800-215 treats NGFWs and WAFs as separate classes, so test against your own application before relying on one device for both jobs.
04What is the difference between a positive and a negative security model?
A positive security model, or allowlist, defines what valid traffic looks like and rejects everything else. A negative security model, or blocklist, defines known attacks and allows everything else. Positive models stop attacks nobody anticipated but have to be maintained for each application; negative models are quick to deploy but miss payloads they do not recognise and can flag legitimate input that resembles an attack.
05Is the OWASP Core Rule Set a positive or negative security model?
Mainly negative. CRS describes its rules as generic attack detection, looking for patterns of SQL injection, cross-site scripting, command injection and other attack classes in any request. It also contains allowlist elements, such as a configurable list of allowed HTTP methods and the content types it knows how to parse. A positive model for one application, such as validation against its OpenAPI description, can be added alongside it.

Sources

Sources and verification

  1. 01NIST SP 800-41 Rev. 1: Guidelines on Firewalls and Firewall Policy (sections 2.1, 2.2.1, 2.3, 3.3, 4 and 4.2) · NIST
  2. 02NIST SP 800-215: Guide to a Secure Enterprise Network Landscape (firewall capabilities, NGFW, WAF, WAAP) · NIST
  3. 03Glossary: defense-in-depth · NIST CSRC
  4. 04Web Application Firewall · OWASP
  5. 05Positive security model · OWASP Wiki (archived)
  6. 06Virtual Patching Cheat Sheet (positive and negative security virtual patches) · OWASP Cheat Sheet Series
  7. 07REST Security Cheat Sheet (HTTP methods, content types, input validation) · OWASP Cheat Sheet Series
  8. 08CRS documentation · OWASP CRS
  9. 09CRS documentation: What's in the rules · OWASP CRS
  10. 10CRS documentation: False Positives and Tuning · OWASP CRS
  11. 11OWASP ModSecurity project · OWASP
  12. 12OWASP Coraza Web Application Firewall · OWASP Coraza
  13. 13OpenAPI Specification (Parameter Object) · OpenAPI Initiative
  14. 14RFC 6585: Additional HTTP Status Codes (429 Too Many Requests) · IETF
  15. 15What is nftables? · Netfilter
  16. 16Firewall fundamentals · Netgate pfSense documentation
  17. 17Control traffic to your AWS resources using security groups · AWS documentation
  18. 18Security group rules (allow rules only; referencing a load balancer's group) · AWS documentation

Last updated