Firewall vs IDS vs IPS vs WAF: What They Inspect, Block or Alert, and What They Protect

All four defend against attacks that travel over the network, but they differ in what they inspect and what they do when they find something. A firewall lets through only the traffic its rules allow, based on IP addresses, port numbers and similar fields. An IDS (intrusion detection system) inspects traffic down to its contents, finds what looks like an attack and alerts administrators, but does not stop the traffic. An IPS (intrusion prevention system) sits in the traffic path and blocks the attacks it finds on the spot. A WAF (web application firewall) inspects the contents of HTTP requests and blocks attacks on web applications such as SQL injection. None of them covers everything on its own, so they are used together.

AspectFirewallIDSIPSWAF
What it mainly inspectsSource and destination IP addresses, port numbers and connection state (network and transport layers); some products also identify applicationsPacket headers through contents (network layer up to the application layer)Like an IDS, packet headers through contentsThe contents of HTTP and HTTPS requests and responses (application layer)
Placement relative to the traffic pathIn the path (inline)Usually outside the path, receiving a copy of the traffic from a switch mirror port or similarIn the path (inline)In the path, in front of the web server, as a reverse proxy or a cloud service
Action on detectionBlocks traffic its rules do not allowRaises an alert and logs it; the traffic itself is not stoppedBlocks the traffic or drops the connectionBlocks requests judged to be attacks; a detect-and-log-only mode is also common
Detection methodAllow and deny rules (addresses, ports, connection state)Matching against known attack patterns (signatures) and anomaly detection that looks for deviations from normal trafficLike an IDS, signatures and anomaly detectionRules for attack patterns such as SQL injection and cross-site scripting, and rules defining which input is allowed
What it mainly protectsThe network's entry and exit points, keeping disallowed traffic outMonitoring of networks and servers, noticing signs of attack or intrusionServers and endpoints on the network, against known attacksWeb applications, against attacks that exploit application vulnerabilities
Impact of false positivesA rule mistake stops legitimate trafficMany false alarms bury real alerts and burden operators, but business traffic is not stoppedA false positive directly blocks legitimate traffic, so careful tuning is neededLegitimate input, such as text containing symbols, judged as an attack makes users' operations fail
Example placementAt the boundary between the internal network and the internet, between network segments, and on each server or endpointOn the network segment to be monitored (network-based) or on a server (host-based)At the internet boundary, for example just inside the firewallIn front of a public web server
LimitationsCannot stop attacks that pass through allowed ports, such as those exploiting web application flaws; has no function to encrypt trafficOnly detects and cannot stop; cannot inspect TLS-encrypted traffic unless placed where it can be decryptedUnknown attacks without signatures depend on anomaly detection and are easily missed; cannot see encrypted contents; its capacity can become a traffic bottleneckDoes not protect non-web traffic; does not fix the application's vulnerabilities themselves

Figures are typical orders of magnitude and vary by process generation and product.

When to use which

Firewall
The basic measure placed first on any network: allow only the traffic that is needed and block the rest.
IDS
When you want to notice signs of attack or intrusion without risking stopping traffic. It also keeps records for investigations.
IPS
When known attacks should be stopped automatically without waiting for a human decision. It is common to tune it first in detection-only mode before enabling blocking, so false positives do not stop business traffic.
WAF
When you publish a web application. It can serve as a stopgap while vulnerability fixes are pending, but it does not replace fixing the application.

FAQ

What is the main difference between an IDS and an IPS?

Whether it stops the attacks it finds. An IDS usually inspects a copy of the traffic and only raises alerts, leaving the traffic untouched. An IPS sits in the traffic path and blocks traffic judged to be an attack on the spot. With an IPS, false positives therefore block legitimate traffic, and care is needed so that a failure of the device does not stop all traffic. Many products can switch between the two modes.

If I have a firewall, do I still need a WAF?

They do different jobs, so if you publish a web application it makes sense to use both. Once a firewall allows traffic to port 443 of a web server, it does not distinguish whether the contents are legitimate requests or attacks. A WAF inspects the contents of HTTP requests and finds and blocks attack patterns such as SQL injection and cross-site scripting.

Can an IDS or IPS inspect encrypted traffic?

Not as is. To inspect the contents of TLS-encrypted traffic, it must sit behind a device that terminates TLS (such as a reverse proxy or a WAF), or the device itself must decrypt the traffic to inspect it. Without decryption, anomalies have to be found from destinations, volumes and timing patterns of the traffic.

What is a next-generation firewall (NGFW)?

A name for firewalls that combine, in one device, the traditional address-and-port rules with functions such as identifying applications from traffic contents and IPS features. The functions included vary by product, so check which layers it inspects and what it can block.

Check your understanding

Which correctly describes the basic function of a (packet-filtering) firewall?

  1. AIt encrypts communication to prevent eavesdropping along the path
  2. BIt passes only permitted traffic and blocks the rest, according to rules based on source and destination IP addresses, port numbers and so on
  3. CIt distributes incoming packets among several servers to spread the processing load
Show answer and explanation

Answer: B. It passes only permitted traffic and blocks the rest, according to rules based on source and destination IP addresses, port numbers and so on

A firewall is placed, for example, at the boundary between an internal network and the internet, and allows or denies traffic according to predefined rules. A typical setting is "from outside, allow only traffic to port 443 of the public web server and deny all other incoming connections." Most firewalls today perform stateful inspection, keeping track of connection state and automatically letting through the return packets of connections started from inside. They do not encrypt, so they are combined with TLS or a VPN to protect traffic. They also cannot stop attacks that come through an allowed port (such as those exploiting web application vulnerabilities), so other measures such as a WAF are used as well.

In a web application, entering a string such as ' OR '1'='1 in the password field of the login screen lets someone log in without knowing the password. What is this attack called?

  1. ASQL injection
  2. BCross-site scripting
  3. CDirectory traversal
Show answer and explanation

Answer: A. SQL injection

SQL injection exploits a web application that builds database commands (SQL statements) by simply concatenating user input as strings. For example, when ' OR '1'='1 is inserted where the condition "the password equals 'input'" is built, the quotation mark closes the string and the always-true condition "or '1' equals '1'" gets added. As a result the condition holds without the password, and the login succeeds. The same method can also be used to steal, alter or delete data. The fundamental countermeasure is a mechanism that never interprets input as part of the command: prepared statements with placeholders.

A bulletin-board web application had a vulnerability in which scripts contained in text posted by users were executed in other visitors' browsers. Which combination correctly gives the name of this vulnerability and its fundamental countermeasure?

  1. ASQL injection. Lengthen the password used to connect to the database
  2. BCross-site scripting (XSS). Escape characters with special meaning, such as < and >, when outputting posted text as HTML
  3. CCross-site scripting (XSS). Encrypt communication between the server and the browser with HTTPS
Show answer and explanation

Answer: B. Cross-site scripting (XSS). Escape characters with special meaning, such as < and >, when outputting posted text as HTML

Cross-site scripting (XSS) is a vulnerability in which a web application outputs user input into HTML as is, so a script contained in the input runs in visitors' browsers as part of the page. Because the script runs as a page of that site, it may steal the visitor's session information (cookies) or display fake input fields. The fundamental countermeasure is to escape characters with special meaning, such as <, >, & and quotation marks, according to where they are output (for example, converting < to &lt;) so they are displayed as plain characters. Supplementary measures include giving cookies the HttpOnly attribute so scripts cannot read them, and restricting which scripts may run with a Content Security Policy. HTTPS protects the communication channel and cannot prevent a script embedded in a legitimate page from running.

  1. Which statement correctly describes a zero-day attack?
  2. Which statement correctly describes a DDoS attack?
  3. Which of the following correctly describes a reverse proxy?

Practice Information Security Basics questions

Key terms explained

Port number
A number from 0 to 65535 used by TCP and UDP to identify which application on a host the traffic is for. Ports 0–1023, such as 80 for HTTP, 443 for HTTPS and 53 for DNS, are called well-known ports.
OSI reference model
A model that organizes communication functions into seven layers: physical, data link, network, transport, session, presentation and application. It serves as a common vocabulary for thinking about each layer's role separately.
SQL injection
An attack that exploits a web application building SQL statements by simply concatenating user input, using the input to change the meaning of the command and manipulate the database without authorization. Prepared statements with placeholders are the fundamental countermeasure.
Cross-site scripting (XSS)
A vulnerability in which a web application outputs user input into HTML as is, so that a script contained in the input runs in visitors' browsers as a page of that site. Escaping characters with special meaning on output is the fundamental countermeasure.
Reverse proxy
A server placed in front of web servers that receives users' requests on the servers' behalf and relays them to one or more servers behind it. It takes on roles such as handling HTTPS encryption in one place (TLS termination), storing and returning frequently used responses, spreading load over several servers and hiding the configuration of the servers behind it. It differs in placement and in what it protects from a forward proxy, which sits on the users' side and connects to outside sites on their behalf.
TLS
Transport Layer Security. A protocol that encrypts communication, detects tampering and authenticates servers with certificates. HTTPS is HTTP protected by TLS.
Zero-day attack
An attack that exploits a software vulnerability in the period after it is discovered but before a fix (patch) is provided. Since patches cannot prevent it, damage is limited with multiple layers of defense.

Related comparisons