You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Pattern: Host-access port parsing and validation is implemented separately in TypeScript host firewall rules and the agent iptables shell script.
Locations: src/host-iptables-validation.ts lines 7-17 and 38-57; containers/agent/setup-iptables.sh lines 26-41, 45-63, 269-281, and 374-399.
Impact: Consolidates security-critical port-spec semantics and reduces the chance that host-level DOCKER-USER rules and in-container NAT/filter rules drift.
Related prior issue: #5500 was marked completed, but the duplication still reproduces in the current tree.
Evidence
src/host-iptables-validation.ts validates single ports/ranges, trims comma-delimited lists, warns, and skips invalid specs:
Generate the shell validator and parser from a single shared source of truth, or add a small build-time checked fixture that exports both:
TypeScript isValidPortSpec / parseValidPortSpecs for host firewall rules.
Shell is_valid_port_spec / parse_port_specs emitted into setup-iptables.sh or sourced from a generated helper.
Then use the shared shell parser for AWF_ALLOW_HOST_PORTS and AWF_HOST_SERVICE_PORTS so all agent-side port consumers receive the same normalized list.
Duplicate Code Opportunity
Summary
src/host-iptables-validation.tslines 7-17 and 38-57;containers/agent/setup-iptables.shlines 26-41, 45-63, 269-281, and 374-399.DOCKER-USERrules and in-container NAT/filter rules drift.Related prior issue: #5500 was marked completed, but the duplication still reproduces in the current tree.
Evidence
src/host-iptables-validation.tsvalidates single ports/ranges, trims comma-delimited lists, warns, and skips invalid specs:containers/agent/setup-iptables.shrepeats the validation grammar and skip-on-invalid behavior for both host-access bypasses and DNAT redirects:Suggested Refactoring
Generate the shell validator and parser from a single shared source of truth, or add a small build-time checked fixture that exports both:
isValidPortSpec/parseValidPortSpecsfor host firewall rules.is_valid_port_spec/parse_port_specsemitted intosetup-iptables.shor sourced from a generated helper.Then use the shared shell parser for
AWF_ALLOW_HOST_PORTSandAWF_HOST_SERVICE_PORTSso all agent-side port consumers receive the same normalized list.Affected Files
src/host-iptables-validation.ts— lines 7-17, 38-57src/host-iptables-rules.ts— lines 200-205containers/agent/setup-iptables.sh— lines 26-41, 45-63, 269-281, 374-399Effort Estimate
Medium
Detected by Duplicate Code Detector workflow. Run date: 2026-07-08
Warning
Firewall blocked 1 domain
The following domain was blocked by the firewall during workflow execution:
awmgmcpgSee Network Configuration for more information.