How Firewalls Inspect UDP Headers
This article provides an overview of how network firewalls analyze User Datagram Protocol (UDP) headers to enforce security policies and filter network traffic. It covers the specific fields examined within the 8-byte UDP header, the mechanics of stateless versus stateful UDP evaluation, and how modern firewalls handle connectionless transport-layer protocols to protect network perimeters.
Understanding the UDP Header Structure
The UDP header is a lightweight, 8-byte (64-bit) fixed-length
structure operating at Layer 4 of the OSI model. When an IP packet
arrives, the firewall identifies the transport protocol via the IP
header’s Protocol field (value 17 for UDP). The firewall
then extracts the subsequent 8 bytes, which consist of four 16-bit
fields:
- Source Port (16 bits): Identifies the sending application or process.
- Destination Port (16 bits): Identifies the receiving service or daemon on the target host.
- Length (16 bits): Specifies the total size of the UDP header plus the encapsulated payload in bytes (minimum value is 8).
- Checksum (16 bits): Used for error-checking the header, payload, and a pseudo-IP header.
The Inspection Process
When a UDP packet reaches the firewall, the inspection engine processes the header through several sequential steps:
- Protocol Demultiplexing: The firewall parses the IP packet and verifies that the payload begins with a valid UDP structure based on the IP header length and protocol identifier.
- Field Extraction: The firewall reads the four UDP fields directly from the first 8 bytes of the transport segment.
- Port Matching Against Access Control Lists (ACLs): The firewall compares the destination and source port numbers against defined security policies (e.g., permitting inbound traffic to destination port 53 for DNS, or blocking destination port 69 for TFTP).
- Header Validation and Anomaly Detection: The firewall validates that the value in the Length field matches the actual length of the received transport data. Discrepancies often indicate malformed packets, buffer overflow attempts, or packet fragmentation attacks. The firewall may also verify the Checksum to drop corrupted packets immediately.
Stateless vs. Stateful UDP Inspection
Because UDP is a connectionless protocol without handshakes (like TCP’s SYN/ACK) or explicit session teardowns, firewalls handle UDP headers using two primary methodologies:
Stateless Filtering
Stateless (packet-filtering) firewalls inspect each UDP packet in isolation. The firewall evaluates the Source Port, Destination Port, and IP addresses exclusively against static rules. It does not track previous packets, making it unable to determine whether an incoming UDP packet is a legitimate response to an internally initiated request.
Stateful Inspection
Stateful firewalls create a virtual state table to track pseudo-connections for UDP traffic:
- State Creation: When an outbound UDP packet passes through, the firewall logs a dynamic session entry containing the 5-tuple: Source IP, Destination IP, Source Port, Destination Port, and Protocol (UDP).
- Return Traffic Matching: When an inbound UDP packet arrives, the firewall checks its header against active state table entries (reversing the source and destination IP/port pairs). If a match is found, the firewall permits the packet.
- Timer Management: Since UDP lacks a termination flag (such as TCP FIN or RST), the stateful firewall applies an inactivity timeout (typically ranging from 30 to 120 seconds). If no subsequent packets match the state entry within this window, the entry is flushed, and any future inbound packets targeting that port are blocked.
Deep Packet Inspection and Application-Aware Processing
Next-Generation Firewalls (NGFWs) extend header inspection by examining the payload following the 8-byte UDP header. This ensures that the traffic running over a specific port genuinely matches the expected protocol (e.g., detecting non-DNS traffic attempting to bypass filters via UDP port 53) and mitigates threats such as UDP-based amplification attacks and unauthorized tunneling.