Skip to content
EuroVPSEuroVPS

Firewall vs WAF: what each one sees and stops

A stateful firewall reads addresses, ports and connection state; a WAF reads the HTTP request itself, and a login form needs both, in series.

By EuroVPS EngineeringThe engine room

6 min read
In this article 5 sections
TL;DR
  • A stateful firewall decides on the envelope: source, destination, port and connection state. A bot guessing passwords on a login form sends well-formed requests to a port that has to be open, so the firewall passes them.
  • A WAF, or a reverse proxy doing WAF work, decides on the content: path, method, body, response code and rate per client. Failed logins, injection attempts and scrapers are visible only there.
  • The two fit in series. The firewall narrows what can reach the proxy at all; the proxy detects abuse in the request stream and can hand an address back to the packet filter, with an expiry and an allow-list for the operator.

What a stateful firewall decides

A Layer 3/4 firewall tracks connections and judges each new one on its addresses, its port and the state of the flow it belongs to. Cisco Firepower, OPNsense and netfilter all do this well: a port that no rule opens is closed, a reply is allowed only for a connection the inside started, and management ports answer only to the ranges that are allow-listed. Its view stops at the transport layer. With TLS in the path it cannot see inside the payload at all unless it terminates the session, and even in the clear it has no concept of a URL, a header, a response status or a login.

What a WAF adds

A web application firewall reads the HTTP transaction after TLS termination, which in practice means it lives in or beside the reverse proxy. It adds three kinds of control the firewall cannot express. Signature rules, such as ModSecurity with the OWASP Core Rule Set, match injection, traversal and known exploit payloads in the request. Behavioural rules count per client and per path: requests per minute on the login route, failed-login responses per address, bot signals in headers and timing. Positive rules state what a path accepts, such as which methods, which content types and what body size, and refuse the rest.

A WAF is not a substitute for the firewall. It sees only the traffic that reaches it, and it knows nothing about SSH, database ports or the management plane.

Where login abuse becomes visible

A failed login is a fact in the response. The application answers a POST to the login path with a status or a redirect that distinguishes failure from success, and the proxy writes that into its access log on every attempt. Counting failures per client per minute is one line of awk over that log, and it is the signal a packet filter has no way to see.

The control has to be keyed on the client, not the account. Account lockout on its own stops attempts against one username and locks out its owner, while the bot moves to the next name on its list. A per-client rate limit on the login route does what the lockout cannot:

TERMINAL
# nginx: at most 5 login attempts a minute per client, small burst allowed
limit_req_zone $binary_remote_addr zone=login:10m rate=5r/m;

location = /login {
    limit_req zone=login burst=5 nodelay;
    proxy_pass http://app;
}

HAProxy expresses the same idea with a stick table keyed on source address, and a WAF rule set can count the failed-login response code directly.

How the two fit together

The order is firewall, then TLS termination and the proxy with its WAF rules, then the application. Detection belongs at Layer 7, because that is where the evidence is. Enforcement can be either layer. The proxy can answer the offending client with a 429 or a 403 on its next request, which is enough for most abuse. For a client that keeps coming, the proxy can push the address into the packet filter's dynamic table for a set period, which also drops that client's other connections and costs the firewall nothing per packet.

Two design points come before arming that feedback loop. The operator's management and monitoring ranges go on the allow-list first, so a test or a typo cannot lock out the people who run the platform. And shared addresses are real: an office NAT or a carrier-grade NAT puts many people behind one address, so blocks carry a short expiry and a documented way to lift them. The whole chain is then tested from a host outside the network, as an attacker would meet it, before anyone relies on it.

What neither of them sees

A correct password. Credential stuffing with a leaked, valid password looks like a successful login to every layer. That gap is closed by multi-factor authentication on the account and by allow-listing the administrative paths at the firewall, so that a valid credential is useless from an address that is not yours.

Straight answers

What is the difference between a firewall and a WAF?+

A stateful firewall works at Layer 3/4 and decides on addresses, ports and connection state. A WAF works at Layer 7 and decides on the content of the HTTP request and response. A login attempt is a Layer 7 event, so only the WAF or the proxy can tell whether it failed.

Can a firewall stop credential stuffing on a login form?+

Not on its own. The attempts are well-formed requests to an open port, which is what the firewall is built to allow. The failure is in the response, one layer up. Count it at the proxy and let the proxy decide, or feed the firewall from that decision.

Do I need a WAF appliance if I already run nginx or HAProxy?+

Often not. ModSecurity runs as a module in nginx and Apache, HAProxy has stick tables for rate and abuse tracking, and both log the response codes that reveal login abuse. The proxy you already have sees everything a WAF would; the question is whether anyone has written the rules.

Should blocks happen at the proxy or at the firewall?+

Detect at the proxy, because the evidence is there. Enforce at the proxy for most cases, and escalate to the packet filter for persistent sources, with an expiry, an operator allow-list and a release path for shared addresses.

Login abuse is a Layer 7 problem.

Talk to an engineer about where yours is watched.

Talk to an engineer

You’ve reached the end.

Put the reading to work

What are
you running?

Tell us about the workload, traffic and recovery requirements. Start with the server builder, or talk through the details with an engineer.

Written by the engineers who build and run the infrastructure it describes.
Talk to an engineer
XIn

6 min left