Docker: Chain egress proxy through upstream HTTP(S)_PROXY - #2142
Open
SohamKukreti wants to merge 1 commit into
Open
Docker: Chain egress proxy through upstream HTTP(S)_PROXY#2142SohamKukreti wants to merge 1 commit into
SohamKukreti wants to merge 1 commit into
Conversation
Dial via the corporate proxy by CONNECT-to-the-pinned-IP when proxy env vars are set, restoring crawls on proxy-only hosts (discussion #2041) without weakening SSRF/rebinding guarantees.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Since 0.9.0, the Docker server's egress pinning proxy dials target IPs directly (
asyncio.open_connection), ignoringHTTP_PROXY/HTTPS_PROXY. On hosts that can only reach the internet through a corporate proxy, every crawl fails withPage.goto: net::ERR_TIMED_OUT— this worked in 0.8.x. Reported in discussion #2041.This PR teaches the pinning proxy to chain through the upstream proxy without weakening the SSRF/rebinding guarantees: validation (
resolve_and_pin) still runs locally before the upstream is ever contacted, and the upstream is asked toCONNECT <pinned-ip>:<port>— never a hostname — so it performs no DNS resolution of its own and the pin holds.Behavior:
HTTP_PROXY/HTTPS_PROXY/NO_PROXY(both cases; scheme-aware selection with fallback);CRAWL4AI_UPSTREAM_PROXYoverrides them.NO_PROXYsupports domain-suffix (.corp.lan) and IP/CIDR (192.168.0.0/16) entries — internal targets should be listed there to dial direct.http://user:pass@proxy:port(percent-decoded, UTF-8) sent preemptively; a407/non-200from the upstream fails fast with the existing opaque403and a server-side log line.Connection: closeforced, so a reused client connection cannot smuggle unvalidated requests past the pin.Known limitations (documented in the README):
cntlm,px) and pointCRAWL4AI_UPSTREAM_PROXYat it.List of files changed and why
deploy/docker/egress_proxy.py— upstream detection (upstream_proxy(),_no_proxy_match(),_use_upstream()), the chained_dial()(CONNECT-to-pinned-IP, auth, header drain so upstream headers never leak into the tunnel), absolute-form +Connection: closefor chained plain HTTP, startup/refusal log lines.deploy/docker/tests/test_security_egress_proxy.py— 3 new tests covering the security contract: chained CONNECT carries only the pinned IP and blocked targets produce zero upstream traffic; plain-HTTP absolute-form + anti-smuggling; env parsing (precedence, scheme selection, credentials,NO_PROXYrouting). Plus an autouse fixture clearing proxy env vars so the suite is deterministic on dev machines behind proxies.deploy/docker/README.md— "Behind a corporate proxy" note in the Run the Container section (env vars, auth support, limitations).How Has This Been Tested?
tests/regression/, non-network): 293 passed; the single failure (test_cosine_basic, missing optionaltransformers) was verified pre-existing by re-running on the unmodified tree.NO_PROXYmatching (anchored suffixes, CIDR, the exact list from [Feature Request]: Support for docker proxy #2041), dead/407/garbage upstreams (fast opaque 403, no hang), IPv6 pin bracketing, 8 concurrent tunnels with no cross-talk, and the smuggling regression.Checklist: