Commit ddb2172
fix: critical firewall bypass via non-standard ports (CVSS 8.2) (#213)
* fix: critical firewall bypass via non-standard ports (CVSS 8.2)
Fixes a critical security vulnerability where agents could bypass domain
filtering by accessing host services on non-standard ports when using
--enable-host-access flag.
Vulnerability Details:
- CVSS Score: 8.2 HIGH
- Impact: Complete bypass of domain allowlist on ports other than 80/443
- Root Cause: iptables only redirected ports 80 and 443 to Squid proxy
- Attack Vector: curl http://host.docker.internal:5432/ bypassed filtering
Security Fix - Defense-in-Depth Architecture:
This fix implements a two-layer security model where each layer provides
independent protection:
Layer 1 (iptables - Network Layer):
- Enforces PORT policy: only allowed ports are redirected to Squid
- Default deny: all other TCP traffic is dropped
- Redirects: ports 80, 443, + user-specified ports (via --allow-host-ports)
Layer 2 (Squid - Application Layer):
- Enforces DOMAIN policy: filters domains for all redirected traffic
- Applies Safe_ports ACLs
- Validates both domain AND port for all requests
Key Principle: If either layer fails or is bypassed, the other still
provides protection (no single point of failure).
Changes Implemented:
1. Dangerous Ports Blocklist (src/squid-config.ts)
- Hard-coded list of 15 dangerous ports that cannot be allowed
- SSH (22), Telnet (23), MySQL (3306), PostgreSQL (5432), Redis (6379)
- MongoDB (27017), RDP (3389), SMB (445), databases, mail servers
- Port validation rejects dangerous ports with clear error messages
- Port ranges containing dangerous ports are also rejected
2. Targeted Port Redirection (containers/agent/setup-iptables.sh)
- Only redirect explicitly allowed ports to Squid
- Default: ports 80 and 443 only
- Optional: user-specified ports via --allow-host-ports flag
- Support both single ports (3000) and ranges (8000-8090)
- Default DROP policy for all other TCP traffic
3. --allow-host-ports Flag (src/cli.ts)
- New CLI flag for explicit port control
- Accepts comma-separated list: --allow-host-ports 3000,8080,9000
- Supports port ranges: --allow-host-ports 8000-8090
- Comprehensive input validation with helpful error messages
4. Environment Variable Passing (src/docker-manager.ts)
- Pass AWF_ALLOW_HOST_PORTS to agent container
- Enables iptables to configure port-specific rules
5. Comprehensive Testing (src/squid-config.test.ts)
- Added 12 new tests for dangerous ports blocking
- Tests for single ports, port ranges, and mixed scenarios
- All 550 unit tests pass with no regressions
Security Guarantees:
✓ Defense-in-Depth: Two independent security layers (iptables + Squid)
✓ Dangerous Ports Blocked: SSH, databases cannot be allowed
✓ Explicit Allow Model: User must specify additional ports
✓ Default Deny: All non-allowed ports are dropped
✓ Clear Error Messages: Helpful feedback for security violations
Usage Examples:
# Default: only ports 80, 443 allowed
awf --allow-domains github.com -- curl https://api.github.com
# Allow MCP Gateway on port 3000
awf --enable-host-access --allow-host-ports 3000 \
--allow-domains host.docker.internal -- \
curl http://host.docker.internal:3000/health
# Dangerous port rejected
awf --enable-host-access --allow-host-ports 22 \
--allow-domains host.docker.internal -- echo "test"
# Error: Port 22 is blocked for security reasons
Test Results:
- 550 unit tests pass (18 test suites)
- 12 new dangerous ports tests
- No regressions in existing functionality
- Build successful
Files Modified:
- src/squid-config.ts: Dangerous ports blocklist and validation
- containers/agent/setup-iptables.sh: Targeted port redirection
- src/docker-manager.ts: Environment variable passing
- src/cli.ts: --allow-host-ports flag
- src/types.ts: Type definitions for allowHostPorts
- src/squid-config.test.ts: Comprehensive test coverage
- SECURITY-FIX-STATUS.md: Security fix documentation
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
* fix: add OUTPUT filter chain ACCEPT rules for allowed traffic
Fixes CI failure where npm install was timing out (ETIMEDOUT 172.30.0.10:3128).
Root Cause:
The default DROP rule in the OUTPUT filter chain was blocking all TCP traffic,
including traffic to Squid proxy, DNS servers, and localhost. While NAT rules
redirected traffic correctly, the OUTPUT filter chain DROP rule prevented the
actual connections from completing.
Fix:
Added explicit ACCEPT rules in the OUTPUT filter chain (applied AFTER NAT) for:
- Localhost traffic (loopback interface)
- DNS queries to trusted DNS servers (UDP/TCP port 53)
- DNS queries to Docker embedded DNS (127.0.0.11)
- Traffic to Squid proxy (172.30.0.10)
These ACCEPT rules must come BEFORE the DROP rule to allow essential traffic.
Defense-in-Depth:
This maintains the two-layer security model:
- NAT rules: Redirect only allowed ports to Squid
- OUTPUT filter rules: Allow only essential traffic (localhost, DNS, Squid)
- Default DROP: Block everything else
Test Results:
- All 550 unit tests pass
- Local build successful
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
---------
Co-authored-by: Claude Sonnet 4.5 <noreply@anthropic.com>1 parent 35ea79f commit ddb2172
7 files changed
Lines changed: 705 additions & 22 deletions
File tree
- containers/agent
- src
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
116 | 116 | | |
117 | 117 | | |
118 | 118 | | |
119 | | - | |
| 119 | + | |
120 | 120 | | |
121 | 121 | | |
122 | 122 | | |
123 | | - | |
124 | | - | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
125 | 126 | | |
126 | | - | |
127 | | - | |
128 | | - | |
129 | 127 | | |
130 | 128 | | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
131 | 179 | | |
132 | 180 | | |
133 | 181 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
391 | 391 | | |
392 | 392 | | |
393 | 393 | | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
394 | 400 | | |
395 | 401 | | |
396 | 402 | | |
| |||
620 | 626 | | |
621 | 627 | | |
622 | 628 | | |
| 629 | + | |
623 | 630 | | |
624 | 631 | | |
625 | 632 | | |
| |||
630 | 637 | | |
631 | 638 | | |
632 | 639 | | |
| 640 | + | |
| 641 | + | |
| 642 | + | |
| 643 | + | |
| 644 | + | |
| 645 | + | |
633 | 646 | | |
634 | 647 | | |
635 | 648 | | |
| |||
0 commit comments