From d61dfa508b2afbe5d91fdb7891ee21e366777ba2 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 9 Jul 2026 02:40:13 +0000 Subject: [PATCH 1/3] Initial plan From 0e4a51d4e8e0a42d1ec3d4831b0698c1baa3ee83 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 9 Jul 2026 02:48:45 +0000 Subject: [PATCH 2/3] refactor: consolidate port-spec parsing into shared parse_port_specs() shell function - Add parse_port_specs() to setup-iptables.sh mirroring TypeScript parseValidPortSpecs() in src/host-iptables-validation.ts: takes a comma-separated input + label, validates each entry via is_valid_port_spec(), warns and skips invalid ones, populates a caller nameref array (bash 4.3+). - Refactor allow_service_ports_to_ip(): remove the duplicated inline regex validator since HSP_PORTS is now pre-validated by parse_port_specs(). - Refactor allow_host_access_to_gateway(): replace the inline IFS=',' read + trim + is_valid_port_spec loop with parse_port_specs. - Refactor configure_http_dnat(): replace the inline IFS=',' read + trim + is_valid_port_spec loop and the dead range/single-port if/else with parse_port_specs. - Refactor configure_host_access_rules(): replace the bare IFS=',' read for AWF_HOST_SERVICE_PORTS with parse_port_specs so validation happens at parse time. - Extend tests/setup-iptables-port-spec.test.sh: add 9 new test cases for parse_port_specs (empty input, single port, multiple ports, whitespace trimming, port ranges, invalid-spec filtering, warning emission, all-invalid input), 62 total. Closes #6015 --- containers/agent/setup-iptables.sh | 91 +++++++-------- tests/setup-iptables-port-spec.test.sh | 154 ++++++++++++++++++++++--- 2 files changed, 182 insertions(+), 63 deletions(-) diff --git a/containers/agent/setup-iptables.sh b/containers/agent/setup-iptables.sh index e5ed5ad92..8c63f38d5 100644 --- a/containers/agent/setup-iptables.sh +++ b/containers/agent/setup-iptables.sh @@ -40,25 +40,48 @@ is_valid_port_spec() { fi } -# Allow AWF_HOST_SERVICE_PORTS entries to a destination IP. -# Port validation is intentionally strict to prevent malformed iptables rules. +# Parse a comma-separated port spec string, validating each entry. +# Mirrors TypeScript parseValidPortSpecs() in src/host-iptables-validation.ts. +# Usage: parse_port_specs