Skip to content

Commit debfdf3

Browse files
committed
security: restrict localhost firewall β€” allowlist specific ports only
Previously the firewall allowed ALL localhost traffic (-o lo ACCEPT), meaning hornet_agent could reach every local service: Steam, CUPS, Tailscale admin UI, and unknown HTTP servers. Now localhost is restricted to: - 7890 (Slack bridge) - 11434 (Ollama) - 53 (DNS) Everything else on localhost is blocked and logged. Security audit now checks for blanket localhost access.
1 parent e805a58 commit debfdf3

2 files changed

Lines changed: 41 additions & 6 deletions

File tree

β€Žbin/security-audit.shβ€Ž

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,14 @@ fi
244244
if command -v iptables &>/dev/null; then
245245
if iptables -L HORNET_OUTPUT -n 2>/dev/null | grep -q 'DROP'; then
246246
ok "Firewall rules active (HORNET_OUTPUT chain)"
247+
248+
# Check localhost isolation (blanket -o lo ACCEPT = bad)
249+
if iptables -L HORNET_OUTPUT -n 2>/dev/null | grep -qE 'ACCEPT.*lo\s+0\.0\.0\.0/0\s+0\.0\.0\.0/0\s*$'; then
250+
finding "WARN" "Firewall allows ALL localhost traffic" \
251+
"Agent can reach every local service (Steam, CUPS, Tailscale, etc.). Update setup-firewall.sh"
252+
else
253+
ok "Localhost traffic restricted to specific ports"
254+
fi
247255
else
248256
finding "WARN" "No firewall rules for hornet_agent" \
249257
"Run: sudo ~/hornet/bin/setup-firewall.sh"

β€Žbin/setup-firewall.shβ€Ž

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,17 @@
22
# Port-based network lockdown for hornet_agent
33
# Run as root: sudo ~/hornet/bin/setup-firewall.sh
44
#
5-
# Allows: HTTP (80), HTTPS (443), SSH (22), DNS (53), localhost
6-
# Blocks: everything else (reverse shells, raw sockets, non-standard ports)
5+
# OUTBOUND (internet):
6+
# Allows: HTTP (80), HTTPS (443), SSH (22), DNS (53)
7+
# Blocks: everything else (reverse shells, raw sockets, non-standard ports)
78
#
8-
# Web browsing and all HTTPS APIs still work. The agent cannot:
9+
# LOCALHOST:
10+
# Allows: Slack bridge (7890), Ollama (11434), DNS (53)
11+
# Blocks: everything else (Steam, CUPS, Tailscale admin, unknown services)
12+
#
13+
# The agent cannot:
914
# - Open reverse shells on non-standard ports
10-
# - Use raw/ICMP sockets for covert channels
15+
# - Talk to localhost services it doesn't need (Steam, CUPS, Tailscale UI)
1116
# - Bind to ports (no inbound listeners/backdoors)
1217
# - Do DNS tunneling over non-53 UDP
1318

@@ -36,8 +41,26 @@ iptables -X "$CHAIN" 2>/dev/null || true
3641
# Create a dedicated chain for hornet_agent
3742
iptables -N "$CHAIN"
3843

39-
# Allow localhost (bridge API, postgres, ollama, pi sockets)
40-
iptables -A "$CHAIN" -o lo -j ACCEPT
44+
# ── Localhost: allow only specific services ──────────────────────────────────
45+
46+
# Allow Slack bridge (outbound API)
47+
iptables -A "$CHAIN" -o lo -p tcp --dport 7890 -j ACCEPT
48+
49+
# Allow Ollama (local LLM inference)
50+
iptables -A "$CHAIN" -o lo -p tcp --dport 11434 -j ACCEPT
51+
52+
# Allow DNS on localhost
53+
iptables -A "$CHAIN" -o lo -p udp --dport 53 -j ACCEPT
54+
iptables -A "$CHAIN" -o lo -p tcp --dport 53 -j ACCEPT
55+
56+
# Allow localhost responses (established connections back to us)
57+
iptables -A "$CHAIN" -o lo -m state --state ESTABLISHED,RELATED -j ACCEPT
58+
59+
# Block everything else on localhost
60+
iptables -A "$CHAIN" -o lo -j LOG --log-prefix "HORNET_LOCAL_BLOCKED: " --log-level 4
61+
iptables -A "$CHAIN" -o lo -j DROP
62+
63+
# ── Internet: allow only standard ports ──────────────────────────────────────
4164

4265
# Allow DNS (UDP + TCP)
4366
iptables -A "$CHAIN" -p udp --dport 53 -j ACCEPT
@@ -64,6 +87,10 @@ echo "βœ… Firewall active. Rules:"
6487
echo ""
6588
iptables -L "$CHAIN" -n -v --line-numbers
6689
echo ""
90+
echo "Localhost allowed: 7890 (bridge), 11434 (ollama), 53 (dns)"
91+
echo "Internet allowed: 80, 443, 22, 53"
92+
echo "Everything else: BLOCKED + LOGGED"
93+
echo ""
6794
echo "To remove: sudo iptables -D OUTPUT -m owner --uid-owner $UID_HORNET -j $CHAIN && sudo iptables -F $CHAIN && sudo iptables -X $CHAIN"
6895
echo ""
6996
echo "⚠️ These rules are NOT persistent across reboots."

0 commit comments

Comments
Β (0)