Skip to content
← Network defense for a single computer

Lesson 2 of 4 · 9 min

Firewalls: stateful filtering and macOS’s options

How a stateful firewall decides what to let through, the difference between inbound and egress filtering, and the tools macOS gives you for each.

A firewall’s job sounds simple: let good traffic through, keep bad traffic out. The interesting part is how it decides, and at what level. This lesson covers stateful filtering as a concept, then the specific, separate tools macOS offers, each working at a different layer.

Stateful filtering: remembering the conversation

An early, “stateless” firewall inspects each packet in isolation against a fixed set of rules. A stateful firewall instead keeps track of open connections, and as Cloudflare’s networking glossary describes it, “saves information regarding open connections and uses this information to analyze incoming and outgoing traffic, rather than inspecting each packet” from scratch. In practice this means a stateful firewall can keep ports effectively closed until a connection you initiated asks for a response, then let that specific reply back in, without opening the port to anything else. Nearly every consumer and operating-system firewall in use today, including macOS’s, is stateful.

Inbound vs egress filtering

Inbound filtering controls connections arriving at the machine, uninvited, from outside: someone or something trying to reach a service running on it. Egress (outbound) filtering controls connections the machine itself, or an app on it, tries to make outward. The two matter for different reasons. Inbound filtering stops a machine from being reached and probed in the first place. Egress filtering matters after something has gone wrong: harmful software that gets onto a machine still needs to phone home, receive instructions, or send data out, and every one of those needs an outbound connection. A machine with a strong inbound firewall and no egress filtering at all can still leak everything on it, one outbound connection at a time.

What macOS actually gives you

Three different mechanisms, at three different layers; verify current behaviour on Apple’s own pages before relying on any of them.
ToolLayerDirectionNotes
Application FirewallPer app, in System Settings → Network → FirewallInboundDecides whether each app may accept incoming connections at all; does not filter what apps send outward. Covered with commands to check it in this site’s macOS hardening course.
pf (packet filter)Kernel-level packet filtering, inherited from BSDBoth, rule-basedA powerful, general-purpose firewall Apple uses internally (for example for Internet Sharing), documented for administrators in the pfctl and pf.conf manual pages rather than in a graphical settings pane. Hand-written pf rules are a legacy BSD firewall, not an Apple product with a support page, and macOS does not officially document editing them for end-user hardening.
Network Extension content filtersApp-level, via Apple’s NetworkExtension frameworkOutbound (and inbound for the flows a filter is given)The framework third-party apps use to inspect or block network traffic per app or per domain, with the user’s permission; it is what makes an outbound, per-app firewall on macOS possible at all, rather than only inbound.

The practical read of this table is that macOS’s built-in, supported firewall (the Application Firewall) covers inbound connections well but says nothing about what leaves the machine. pf can technically do both, but it is a low-level, script-based tool aimed at administrators comfortable editing configuration files and reasoning about rule order, not something this course will walk through configuring, since a mistake in a hand-written ruleset can silently fail open or lock out network access entirely, and Apple does not treat it as a first-class, supported end-user setting the way it does the Application Firewall. Community hardening guides that publish ready-made pf rulesets or scripts that pull in third-party IP blocklists go further than this course recommends: those lists need to be trusted and kept updated by someone, and a broken update can break connectivity with no clear error message.

That gap, an inbound-only built-in firewall with no simple, supported way to see or control outbound connections per app, is exactly what Apple’s Network Extension framework exists to let third-party developers fill, with the user’s explicit permission at installation.

Key takeaways

  • A stateful firewall tracks open connections and allows return traffic for a connection you initiated, without inspecting every packet against a fixed rule list.
  • Inbound filtering stops a machine from being reached from outside; egress (outbound) filtering matters once something is already on the machine and trying to communicate out.
  • The macOS Application Firewall filters inbound connections per app; it does not filter outbound traffic.
  • `pf` is a powerful, kernel-level BSD firewall macOS uses internally, but it is not a supported, documented end-user hardening setting the way the Application Firewall is.
  • Apple’s Network Extension framework is what lets third-party apps provide per-app outbound filtering, the gap the built-in firewall leaves open.

Check yourself

  1. 1. What does a stateful firewall do differently from a simple, stateless packet filter?

    • It blocks all traffic by default with no exceptions
    • It tracks open connections and uses that context to allow expected return traffic — Right.
    • It only works on Wi-Fi networks
    • It encrypts all network traffic

    Stateful firewalls remember the state of open connections rather than judging every packet in isolation, which lets them safely allow replies to connections you started.

  2. 2. Why does egress (outbound) filtering matter, given a strong inbound firewall?

    • It does not matter if inbound filtering is strong
    • Because software that is already on the machine still needs an outbound connection to send data out or receive instructions — Right.
    • Outbound connections are always safe
    • It only matters for web servers

    Inbound filtering stops unsolicited connections from reaching the machine, but does nothing once something is already running on it and trying to communicate outward.

  3. 3. What does the macOS Application Firewall NOT do?

    • Decide whether an app may accept incoming connections
    • Filter outbound connections an app makes — Right.
    • Work on a per-app basis
    • Run without any additional software

    The Application Firewall is inbound-only; controlling what apps send outward requires a different mechanism, such as one built on Apple’s Network Extension framework.

Do it with FireAI

Put this lesson into practice on your own Mac.

Sources

Put it into practice on your Mac

Try every feature free for 17 days, no card needed.

Download for Mac Docs