Ensure ufw Default Policy for Routed (Forwarded) Traffic is Disabled

Description

The default policy for routed (forwarded) traffic in ufw should be set to disabled or deny, ensuring that the system does not forward packets between interfaces unless explicitly configured to do so.

Rationale

Unless the system is intended to act as a router, forwarding traffic between network interfaces should be disabled. Disabling the routed default policy prevents the system from accidentally or maliciously forwarding traffic.

Remediation

Shell script

The following script can be run on the host to remediate the issue.

#!/bin/bash

# Remediation is applicable only in certain platforms
if dpkg-query --show --showformat='${db:Status-Status}' 'linux-base' 2>/dev/null | grep -q '^installed$' && { dpkg-query --show --showformat='${db:Status-Status}' 'ufw' 2>/dev/null | grep -q '^installed$'; }; then

ufw default deny routed

else
    >&2 echo 'Remediation is not applicable, nothing was done'
fi

Warning

Changing firewall settings while connected over network can result in being locked out of the system.