-
Notifications
You must be signed in to change notification settings - Fork 6
fix: bypass Squid intercept for host.docker.internal traffic #540
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
When --enable-host-access is used, MCP gateway HTTP traffic to host.docker.internal gets DNAT'd to Squid's intercept port via iptables. Squid's ORIGINAL_DST lookup fails because the NAT translation happens in a different network namespace, causing Squid crashes under heavy MCP load (~13,000 requests) with assertion failures in comm.cc. Add iptables RETURN rule for the host gateway IP when AWF_ENABLE_HOST_ACCESS is set, so traffic to host.docker.internal bypasses Squid entirely. Also add a corresponding ACCEPT rule in the OUTPUT filter chain. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
Chroot tests passed! Smoke Chroot - All security and functionality tests succeeded. |
|
🎬 THE END — Smoke Claude MISSION: ACCOMPLISHED! The hero saves the day! ✨ |
|
📰 VERDICT: Smoke Copilot has concluded. All systems operational. This is a developing story. 🎤 |
✅ Coverage Check PassedOverall Coverage
📁 Per-file Coverage Changes (1 files)
Coverage comparison generated by |
|
Smoke Test Results: Claude Last 2 PRs: #5 (mossaka/log filtering), #1 (Improve links in readme) Status: PASS
|
Security Review FindingsI've identified a security concern with this PR that significantly extends the firewall's security boundary. Issue: Complete Bypass of L7 Filtering for Host TrafficLocation: Code: if [ -n "$AWF_ENABLE_HOST_ACCESS" ]; then
HOST_GATEWAY_IP=$(getent hosts host.docker.internal | awk 'NR==1 { print $1 }')
if [ -n "$HOST_GATEWAY_IP" ]; then
echo "[iptables] Allow direct traffic to host gateway (${HOST_GATEWAY_IP}) - bypassing Squid intercept..."
iptables -t nat -A OUTPUT -d "$HOST_GATEWAY_IP" -j RETURN
iptables -A OUTPUT -d "$HOST_GATEWAY_IP" -j ACCEPT
fi
fiSecurity Impact:
Example Attack Scenario: # User enables host access for legitimate MCP gateway on port 8080
awf --enable-host-access --allow-domains github.com 'curl (host.docker.internal/redacted)
# But the agent can now access ANY service on the host
awf --enable-host-access --allow-domains github.com 'curl (host.docker.internal/redacted) # PostgreSQL
awf --enable-host-access --allow-domains github.com 'curl (host.docker.internal/redacted) # RedisSuggested Mitigations
DecisionThis is a defense-in-depth trade-off. While the change solves the Squid crash issue under load, it significantly weakens the security boundary for users who enable host access. The team should evaluate whether:
I recommend at minimum implementing suggestion #1 (port-specific bypass) to limit the exposure to only the intended ports.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR fixes Squid proxy crashes that occur when using --enable-host-access with MCP gateway traffic to host.docker.internal. The crashes happen because iptables redirects this traffic to Squid's intercept port, where ORIGINAL_DST lookup fails due to network namespace differences, causing instability under heavy load (~13,000 requests). The fix adds iptables rules to bypass Squid intercept for host gateway traffic entirely.
Changes:
- Passes
AWF_ENABLE_HOST_ACCESSenvironment variable to the agent container whenenableHostAccessis enabled - Adds iptables NAT and OUTPUT rules to bypass Squid proxy for traffic destined to the host gateway IP
- Includes comprehensive test coverage for the new environment variable behavior
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/docker-manager.ts | Sets AWF_ENABLE_HOST_ACCESS environment variable when enableHostAccess is true |
| src/docker-manager.test.ts | Adds 3 tests verifying AWF_ENABLE_HOST_ACCESS is set/unset correctly based on enableHostAccess config |
| containers/agent/setup-iptables.sh | Resolves host.docker.internal and adds iptables rules to bypass Squid intercept for that IP when AWF_ENABLE_HOST_ACCESS is set |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| // Enable host.docker.internal for agent when --enable-host-access is set | ||
| if (config.enableHostAccess) { | ||
| agentService.extra_hosts = ['host.docker.internal:host-gateway']; | ||
| environment.AWF_ENABLE_HOST_ACCESS = '1'; |
Copilot
AI
Feb 6, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For consistency with other boolean AWF environment variables (AWF_CHROOT_ENABLED and AWF_SSL_BUMP_ENABLED), this should use 'true' instead of '1'. While the shell script's test [ -n "$AWF_ENABLE_HOST_ACCESS" ] works with either value, maintaining consistency with existing patterns improves code maintainability.
| if [ -n "$HOST_GATEWAY_IP" ]; then | ||
| echo "[iptables] Allow direct traffic to host gateway (${HOST_GATEWAY_IP}) - bypassing Squid intercept..." | ||
| iptables -t nat -A OUTPUT -d "$HOST_GATEWAY_IP" -j RETURN | ||
| iptables -A OUTPUT -d "$HOST_GATEWAY_IP" -j ACCEPT |
Copilot
AI
Feb 6, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This OUTPUT filter chain rule is placed in the NAT configuration section. While it will function correctly, it should be moved to the OUTPUT filter chain rules section (after line 227, before the DROP rule at line 232) for better code organization and maintainability. The NAT section should only contain NAT table rules (lines 56-207), and the OUTPUT filter section should contain all OUTPUT filter rules (lines 209-232).
Summary
--enable-host-accessis used, MCP gateway HTTP traffic tohost.docker.internalgets DNAT'd to Squid's intercept port via iptables, whereORIGINAL_DSTlookup fails (different network namespace), causing Squid crashes under heavy MCP load (~13,000 requests)AWF_ENABLE_HOST_ACCESSenv var is set, so traffic tohost.docker.internalbypasses Squid entirelyAWF_ENABLE_HOST_ACCESS=1fromdocker-manager.tsto the agent container whenenableHostAccessis trueChanges
containers/agent/setup-iptables.sh: After the Squid proxy bypass rule, resolveshost.docker.internaland addsiptables -t nat RETURN+iptables OUTPUT ACCEPTrules for that IPsrc/docker-manager.ts: SetsAWF_ENABLE_HOST_ACCESS=1env var in the agent container whenconfig.enableHostAccessis truesrc/docker-manager.test.ts: 3 new tests verifying the env var is set/unset correctlyTest plan
npm run buildsucceedsnpm test— all 736 tests pass (including 3 new)🤖 Generated with Claude Code