From 4304674ef78f6f8859bf83bc272097d6b14c27b0 Mon Sep 17 00:00:00 2001 From: David Bowman Date: Mon, 14 Sep 2026 19:25:26 -0400 Subject: [PATCH 1/4] plans: add proxy route pinning handoff program --- ...ing-and-egress-interoperability-program.md | 215 ++++++++++++++++++ 1 file changed, 215 insertions(+) create mode 100644 plans/proxy-route-pinning-and-egress-interoperability-program.md diff --git a/plans/proxy-route-pinning-and-egress-interoperability-program.md b/plans/proxy-route-pinning-and-egress-interoperability-program.md new file mode 100644 index 00000000..170675cf --- /dev/null +++ b/plans/proxy-route-pinning-and-egress-interoperability-program.md @@ -0,0 +1,215 @@ +# Proxy Route Pinning and Egress Interoperability Program + +Status: Ready for handoff + +Date: 2026-09-14 + +Eggfetch baseline: `d681da848e36199846604b71f2162a1054d24aa6` + +Egress research baseline: `eggstack/eggress@c82649d3992fb9757de94fed945f6710bbfef61d` + +Motivating downstream evidence: EggSec's scope-aware transport work. The requirements are intentionally generalized; no EggSec type, policy object, feature flag, or adapter belongs in Eggfetch. + +## Purpose + +Close the remaining physical-route control gap in Eggfetch's native proxy transport without weakening the existing `ResolvedTarget` contract, importing a second routing policy engine, or specializing the HTTP client for one downstream. + +Eggfetch already has first-class caller-supplied destination routing for direct requests through `ResolvedTarget` / `RequestBuilder::resolved_addresses()`. That path correctly keeps the logical URL authoritative for HTTP identity, TLS SNI/certificate verification, redirects, cookies, and auth while using caller-supplied `SocketAddr` values for the physical connection. It deliberately rejects proxy, UDS, and HTTP/3 combinations. + +The proxy subsystem does not yet provide the corresponding physical-route controls. The proxy endpoint is still resolved internally in the proxy transport, and CONNECT/SOCKS routes may also delegate ultimate-target resolution below a caller that wants to validate physical destinations before I/O. This is the remaining generic blocker for security-sensitive embedders that need both an explicit proxy and a proof that no independent DNS decision occurs after caller policy. + +The program adds two orthogonal controls in order: + +1. pin the physical proxy peer while preserving the proxy's logical URI/TLS identity; +2. where the proxy protocol can represent it safely, pin the physical ultimate destination of a proxied tunnel while preserving the origin's logical HTTP/TLS identity. + +The existing direct `resolved_addresses()` behavior remains unchanged and fail-closed with proxies. + +## Confirmed current architecture + +At the Eggfetch baseline: + +- `ResolvedTarget` is request-scoped direct routing. Static mode performs no second DNS lookup, retries preserve the snapshot, same-origin redirects may retain it, cross-origin redirects fail closed, and proxy/UDS/H3 combinations are rejected. +- `Proxy` is the public native proxy configuration; `ProxyConfig` is the resolved internal configuration passed into transport selection. +- `transport/proxy.rs::connect_to_proxy()` owns proxy endpoint DNS via `tokio::net::lookup_host`, candidate dialing, proxy TLS setup, CONNECT, origin TLS, timeout budgeting, and proxy transport metrics. +- HTTPS proxy TLS already distinguishes logical proxy identity from the selected physical socket address. This is the correct seam for caller-pinned proxy peers. +- SOCKS5 and SOCKS5H remain semantically distinct in the native API: local-resolution SOCKS5 and proxy-resolution SOCKS5H must not be collapsed by the new native routing controls. +- `ClientBuilder::dialer()` is already a generic external raw-stream seam for callers that own an entire route. It intentionally conflicts with Eggfetch's built-in proxy route rather than creating two routing authorities. +- `TransportHints` is a public native type and has already grown fields during 0.1.x. New proxy route controls must not require downstream callers to exhaustively construct another expanded public struct literal. + +## Why one physical address control is not enough + +A proxied request has at least four distinct identities/locations: + +```text +logical origin service.example:443 +physical origin target 203.0.113.10:443 +logical proxy proxy.example:8443 +physical proxy peer 198.51.100.20:8443 +``` + +For an HTTPS CONNECT route, TCP first connects to the physical proxy peer while proxy TLS (when the proxy is HTTPS) authenticates `proxy.example`. The proxy then receives a CONNECT target. After the tunnel is established, destination TLS authenticates `service.example`. + +A security-sensitive embedder may need to validate both physical addresses independently. Pinning only the proxy peer still leaves the proxy free to resolve the CONNECT hostname. Pinning only the origin target does not prove which proxy socket Eggfetch connected to. The API and tests therefore must model these as separate optional constraints rather than overloading one `resolved_addresses()` value. + +## Egress reuse decision + +### `eggress-routing`: do not depend on it from Eggfetch + +`eggress-routing` is a policy/scheduler layer, not a neutral socket-address primitive. It brings route rules, direct/upstream/reject actions, regex/CIDR matching, upstream groups, health state, leases, Tokio state, and Egress-specific models. Importing it into `eggfetch-core` would give Eggfetch a second routing-policy language and invert the desired ownership boundary. + +Eggfetch should remain an HTTP engine that executes an explicit route supplied by its caller. Egress may decide a route outside Eggfetch, but Eggfetch must not import Egress policy to decide whether a route is authorized or preferred. + +### `eggress-uri`: do not adopt for this work + +`eggress-uri` is lightweight, but it deliberately parses a much broader proxy/protocol vocabulary than Eggfetch needs (HTTP/SOCKS plus SSH, FTP, LDAP, SMTP, IMAP, POP3, custom schemes and chain-oriented metadata). Replacing Eggfetch's current proxy URL model with it would couple HTTP client semantics to Egress's cross-protocol grammar without deleting the transport work this program needs. + +Re-evaluate only if a later measured change shows substantial duplicated parser/model code can actually be removed without broadening Eggfetch's accepted schemes or public API. + +### `eggress-protocol-socks`: technically reusable, not useful for this program + +The Egress SOCKS crate exposes a clean stream-level SOCKS4/5 implementation, but replacing Eggfetch's existing SOCKS handshake does not solve the route-pinning gap. Eggfetch would still own proxy TCP dialing, candidate fallback, shared deadlines, local bind/socket options, metrics, logical origin TLS, retry behavior, pool identity, and request error provenance. Adopting the crate now would add `eggress-core` and related dependencies while moving only handshake bytes. + +Do not combine a SOCKS implementation swap with proxy route pinning. If a future independent maintenance audit demonstrates real code/dependency deletion, evaluate it as a separate project with before/after graph measurements. + +### Supported relationship: Egress above Eggfetch + +The existing Eggfetch `Dialer` seam is the correct composition point when a consumer wants Egress to own an entire route or proxy chain. Egress can establish a stream according to its own policy and hand that stream to Eggfetch; Eggfetch then owns HTTP and destination TLS according to the dialer contract. No dependency edge from Eggfetch to Egress is required. + +This program must preserve that direction: + +```text +application policy / optional Egress routing + | + v + explicit route choice + | + +--------+--------+ + | | + v v + Eggfetch built-in Eggfetch Dialer + proxy route (external stream) + | + v + HTTP / TLS engine +``` + +Do not add Egress-specific examples, feature flags, public types, or optional dependencies to `eggfetch-core` merely to prove this composition. + +## Public API direction + +The exact names may be adjusted during implementation, but the API must preserve these separations. + +### Proxy peer pinning + +Preferred native shape: extend the existing public `Proxy` builder with a caller-supplied resolved-address option, conceptually: + +```rust +let proxy = Proxy::all("https://proxy.example:8443")? + .resolved_addresses(["198.51.100.20:8443".parse()?])?; +``` + +The proxy URL remains logical identity. The supplied addresses control only the physical socket opened to the proxy. + +Reuse the existing validated resolved-address representation internally where doing so does not make its public documentation false. If necessary, broaden `ResolvedTarget` documentation from "HTTP origin" to "logical endpoint" without changing its existing behavior, or introduce a private shared validated-address type beneath the public wrappers. Do not create two independent candidate-loop implementations. + +Do not add a new required public `TransportHints` field for proxy-peer routing. `Proxy` fields are private and are the safer compatibility boundary. + +### Proxied ultimate-destination pinning + +This must be an explicit request-level opt-in separate from direct `resolved_addresses()`. The existing direct method currently fails closed when a proxy is effective; changing its meaning to silently become a CONNECT/SOCKS target would weaken an established security contract. + +The implementation plan may select a concise native name such as `proxy_target_addresses(...)`, `proxied_addresses(...)`, or a small typed proxy-route hint, but the semantics must be unambiguous: these addresses describe the ultimate proxied target, not the proxy peer. + +Avoid adding another publicly exhaustible bag-of-options struct. Prefer a fluent request builder or an opaque/validated type with accessor methods. + +## Protocol support matrix + +The initial support contract is intentionally conservative. + +| Route | Pinned proxy peer | Pinned ultimate target | Required behavior | +|---|---|---|---| +| HTTP proxy, HTTP origin (forward proxy) | yes | not in v1 | Forward proxy resolves/forwards the absolute logical URL; fail closed if an ultimate pin is requested unless an explicit CONNECT-for-HTTP design is separately justified | +| HTTP proxy, HTTPS origin (CONNECT) | yes | yes | CONNECT may use the approved physical destination while origin Host/SNI/certificate identity stays logical | +| HTTPS proxy, HTTPS origin (TLS-to-proxy + CONNECT) | yes | yes | Proxy TLS identity stays logical proxy host; destination TLS identity stays logical origin host | +| SOCKS5 | yes | yes | Send an approved IP target without a second destination DNS lookup; preserve existing timeout/candidate semantics | +| SOCKS5H | yes | no | Remote DNS is the protocol contract; explicit ultimate-target pinning must fail closed rather than claim local validation | +| HTTP/3 | n/a | n/a | Built-in proxy route remains incompatible; no H3/MASQUE work in this program | +| UDS/custom dialer | n/a | n/a | Remain separate routing authorities; do not merge with built-in proxy pinning | + +If implementation evidence shows a row cannot preserve the stated invariants cleanly, reject that row before I/O and document it rather than creating a weaker fallback. + +## Security invariants + +1. Caller-supplied physical routes never silently fall back to system DNS. +2. Logical proxy identity and physical proxy destination remain separate. +3. Logical origin identity and physical origin destination remain separate. +4. HTTPS proxy certificate verification/SNI use the logical proxy hostname unless the caller explicitly uses existing proxy TLS overrides. +5. Destination TLS certificate verification/SNI and HTTP Host use the logical origin hostname unless an existing explicit override applies. +6. A supplied address set is immutable for the logical attempt/retry snapshot; retry cannot silently re-resolve. +7. Pool/client reuse may not cross incompatible physical-route constraints. +8. Redirects may not carry a destination-specific physical route to a different origin. Same-origin retention is allowed only when the effective proxy and ports remain compatible. +9. SOCKS5H is never presented as locally destination-pinned. +10. Proxy credentials remain proxy-leg-only and retain existing redaction guarantees. +11. Existing requests that do not opt into route pinning behave exactly as before. +12. The feature adds no authorization, CIDR, SSRF, allow/deny, or downstream policy engine to Eggfetch; validation remains the caller's responsibility. + +## Execution order + +1. [`pinned-proxy-peer-routing.md`](pinned-proxy-peer-routing.md) — add caller-pinned physical proxy endpoints to the existing proxy transport and prove DNS-free proxy dialing, identity preservation, candidate fallback, retry behavior, and route-aware reuse. +2. [`pinned-proxy-destination-routing.md`](pinned-proxy-destination-routing.md) — add explicit physical ultimate-target pinning only to proxy protocols where Eggfetch can enforce it end-to-end without weakening logical Host/TLS semantics. +3. [`post-proxy-route-pinning-qualification-and-closure.md`](post-proxy-route-pinning-qualification-and-closure.md) — audit the final API/dependency boundary, run the repository's current validation tiers and proxy security regressions, re-check compatibility evidence where required, and record the Egress non-dependency disposition. + +Plan 2 depends on Plan 1 because an end-to-end scope-controlled proxy route is incomplete if Eggfetch can still independently resolve the proxy peer. Plan 3 is last. + +## Dependency policy + +Expected production dependency delta for `eggfetch-core`: **zero**. + +The existing proxy transport already has the networking/TLS primitives required. Prefer extending the current candidate-dial and proxy handshake paths rather than importing Egress, Tower routing, another resolver, or a second proxy client. + +At closure record: + +```text +cargo tree -p eggfetch-core --no-default-features --features http1,tls-rustls +cargo tree -p eggfetch-core --no-default-features --features http1,tls-rustls,proxy +cargo tree -p eggfetch-core -d +``` + +The minimal non-proxy graph must remain unaffected by this program. Any new dependency requires a written explanation and before/after graph evidence; an Egress dependency is not expected or approved by this plan. + +## Compatibility policy + +This is additive native-Rust behavior. Existing Python, CLI, HTTPX, HTTPX2, direct resolved routing, custom dialer, UDS, proxy, TLS, redirect, retry, and error surfaces retain their current semantics unless a documented bug is found. + +Do not expose the new native route pinning through Python/HTTPX compatibility APIs merely for symmetry. Those facades should change only when their reference APIs require a corresponding capability. + +Do not make `TransportHints` more source-fragile during 0.1.x. Downstream exhaustive struct literals already make public-field growth costly. Prefer fluent methods/private fields for this program; consider an opaque or deliberately `#[non_exhaustive]` transport-hints boundary only as a separately reviewed compatibility change. + +## Non-goals + +- No EggSec, CodeGG, Synvoid, Eggpool, Egress, or other downstream adapter. +- No built-in SSRF validator, CIDR blocklist, scope engine, authorization callback, or DNS policy trait. +- No automatic proxy-chain selection. +- No migration of Eggfetch's SOCKS implementation to Egress. +- No Egress dependency in Eggfetch. +- No change to `RequestBuilder::resolved_addresses()` direct-only fail-closed semantics. +- No SOCKS5H local-validation claim. +- No CONNECT-UDP, MASQUE, HTTP/3 proxying, WebTransport, or QUIC proxy work. +- No forced CONNECT-for-plaintext-HTTP behavior without a separate protocol/design justification. +- No binary-size claim. The retained embedded evidence classifies Eggfetch as larger than aligned minimal Reqwest profiles; this program is about route control and ownership. + +## Program exit criteria + +The program closes only when all are true: + +1. Native callers can pin the physical proxy peer without system DNS fallback while preserving logical proxy TLS identity. +2. Native callers can pin the physical ultimate destination for HTTPS CONNECT and local-resolution SOCKS5 without corrupting logical origin Host/SNI/certificate semantics. +3. Unsupported combinations, including SOCKS5H ultimate pinning and plaintext forward-proxy ultimate pinning, fail before network I/O. +4. Retry, redirect, timeout, candidate fallback, proxy auth, proxy TLS, destination TLS, and structured failure semantics are tested under pinned routes. +5. Physical connection reuse cannot cross incompatible pinned route snapshots. +6. Ordinary unpinned proxy behavior and existing direct `resolved_addresses()` behavior remain unchanged. +7. Minimal non-proxy feature/dependency graphs do not grow. +8. `eggfetch-core` has no Egress dependency; the retained decision explains why Egress remains an external policy/dialer layer. +9. Current repository verification and compatibility obligations are green on the final executable tree. +10. Documentation clearly distinguishes proxy peer, ultimate target, logical proxy identity, logical origin identity, SOCKS5, and SOCKS5H semantics. From a498c5ed9e007b0b70aa892bdb183a65cac78178 Mon Sep 17 00:00:00 2001 From: David Bowman Date: Mon, 14 Sep 2026 19:26:09 -0400 Subject: [PATCH 2/4] plans: add pinned proxy peer routing plan --- plans/pinned-proxy-peer-routing.md | 272 +++++++++++++++++++++++++++++ 1 file changed, 272 insertions(+) create mode 100644 plans/pinned-proxy-peer-routing.md diff --git a/plans/pinned-proxy-peer-routing.md b/plans/pinned-proxy-peer-routing.md new file mode 100644 index 00000000..32c280e6 --- /dev/null +++ b/plans/pinned-proxy-peer-routing.md @@ -0,0 +1,272 @@ +# Pinned Proxy Peer Routing + +Status: Ready for handoff + +Date: 2026-09-14 + +Parent: [`proxy-route-pinning-and-egress-interoperability-program.md`](proxy-route-pinning-and-egress-interoperability-program.md) + +Depends on: current native proxy subsystem and completed direct `ResolvedTarget` work + +Baseline: `d681da848e36199846604b71f2162a1054d24aa6` + +## Objective + +Add a native, typed way for a caller to supply the already-resolved physical `SocketAddr` candidates for a configured proxy endpoint and require Eggfetch to connect only to those addresses, while preserving the proxy URL as the logical identity for proxy matching, authentication, HTTPS-proxy TLS SNI/certificate verification, error reporting, and user-visible configuration. + +This is the proxy-peer analogue of direct `RequestBuilder::resolved_addresses()`. It is not a proxy policy engine and does not pin the ultimate origin; the second child plan owns that separate problem. + +## Problem statement + +Today `Proxy` / `ProxyConfig` carries the logical proxy URI, auth, proxy-only headers, routing rule, and optional proxy TLS configuration. The proxy transport then resolves the proxy host internally with `tokio::net::lookup_host` before dialing candidates. + +That means a caller can pre-resolve and validate a direct origin, but cannot do the same for the first hop of a built-in proxy route. A security-sensitive caller can authorize `proxy.example:8443` as a hostname yet still has no API-level guarantee that the socket Eggfetch opens is one of the addresses it validated. + +The desired invariant is: + +```text +logical proxy URI: https://proxy.example:8443 +caller-approved peers: [198.51.100.20:8443, 198.51.100.21:8443] +TCP remote: one of the supplied peers only +proxy TLS SNI: proxy.example +proxy cert validation: proxy.example +proxy auth/rule identity: unchanged +DNS fallback: forbidden while the pin is present +``` + +## API design + +Prefer extending the existing public `Proxy` builder rather than adding a request `TransportHints` field. + +Conceptual API: + +```rust +let proxy = Proxy::all("https://proxy.example:8443")? + .resolved_addresses([ + "198.51.100.20:8443".parse()?, + "198.51.100.21:8443".parse()?, + ])?; + +let client = Client::builder() + .proxy(proxy) + .build(); +``` + +Exact naming may change if another name is clearer (`proxy_addresses`, `resolved_proxy_addresses`), but it must be obvious that the addresses belong to the proxy endpoint rather than the origin. + +### Validated address representation + +Do not copy the direct connector's validation/candidate logic into a second independent model. + +Preferred options, in order: + +1. reuse the existing `ResolvedTarget` internally after broadening its documentation so it truthfully describes a validated physical destination set for one logical endpoint; or +2. extract a private `ResolvedEndpoint` / `StaticDestinations` representation shared by direct `ResolvedTarget` and the proxy model, retaining the public direct type unchanged. + +Do not rename the public `ResolvedTarget` in 0.1.x merely for taxonomy. Do not add public fields. + +### Construction errors + +Reject before I/O: + +- an empty supplied set; +- a `SocketAddr` whose port differs from the logical proxy URI's effective port; +- a proxy URI with no usable host/port; +- any unsupported scheme already rejected by normal proxy construction. + +Preserve candidate order. A caller may intentionally order IPv6/IPv4 or service-discovery results. + +## Internal state ownership + +Add the pinned peer snapshot to `Proxy` and carry it into `ProxyConfig::config()` as private/internal state. + +The snapshot must survive: + +- client-level proxy configuration; +- per-request `ProxyOverride::Override` cloning; +- retry reconstruction; +- redirect hops when the same effective proxy still applies; +- proxy matching/routing rule evaluation. + +It must not survive into a different proxy selected by another rule. It must not affect a request that matches `NO_PROXY` and takes the direct route. + +`Debug` should report at most a count/presence summary, matching `ResolvedTarget`'s existing privacy posture. Socket addresses are not credentials, but there is no need to dump private topology into routine debug output. + +## Connector implementation + +Refactor `transport/proxy.rs::connect_to_proxy()` so candidate acquisition is one explicit step: + +```text +if proxy has caller-supplied peers: + candidates = exact snapshot +else: + candidates = current lookup_host(proxy_host, proxy_port) + +for candidate under the existing connect budget: + apply current local-bind/socket behavior + connect + record existing metrics/failure provenance +``` + +The candidate loop, timeout budgeting, metrics, and failure handling should remain one implementation for pinned and system-resolved peers. + +Do not implement pinning by rewriting the proxy URL host to an IP literal. That would corrupt HTTPS-proxy TLS identity and configuration semantics. + +### HTTPS proxy identity + +The physical socket and TLS server name must remain distinct: + +```text +connect(198.51.100.20:8443) +TLS server name = proxy.example +certificate policy = proxy TLS config / existing roots +``` + +Existing `proxy_tls_config` replacement/augmentation semantics must be unchanged. Client identity and custom CA handling must continue to target the proxy TLS leg only. + +## Timeouts and candidate fallback + +All supplied peers share the existing proxy-connect phase budget. Do not give every candidate a fresh full connect timeout. + +If the first candidate fails and the second succeeds, the request succeeds under one aggregate budget exactly as ordinary multi-address proxy DNS does today. + +If all supplied candidates fail, return the ordinary proxy connection failure with the best available structured terminal provenance. Never fall back to DNS afterward. + +## Retry semantics + +Retries preserve the exact proxy-peer snapshot. A retry is another attempt under the same caller routing decision, not permission to re-resolve the proxy. + +Regression test this directly: make the proxy hostname unresolvable or changeable, provide a working pinned local proxy listener, force a retry, and prove both attempts use the supplied peer without consulting DNS. + +The program must not add automatic refreshing of caller-supplied peers. Callers that want new service-discovery results construct a new proxy/request. + +## Redirect semantics + +Proxy peer state belongs to the effective proxy, not the origin. Therefore a redirect may retain the peer snapshot only if the same `Proxy` remains effective for the redirected URL. + +Required cases: + +- same effective proxy: retain the pinned peer snapshot; +- `NO_PROXY` begins matching after redirect: drop the proxy route entirely and use normal direct semantics; +- another proxy rule selects a different proxy: use only that proxy's own peer snapshot; +- no effective proxy: never apply stale proxy peers to a direct connection. + +Do not treat a redirect as permission to mutate a configured proxy object's physical route. + +## Pool/client reuse and route identity + +Audit every cached client/connection path used by HTTP, HTTPS CONNECT, and SOCKS proxies. + +A request constrained to a supplied proxy-peer set must not reuse a pooled transport that was established to the same logical proxy through ordinary DNS or through a different supplied set unless the cache key proves physical-route equivalence. + +If the current proxy paths do not retain reusable physical connections across requests, document and test that fact rather than adding unnecessary route-key machinery. If any path does cache by logical proxy only, extend the key with a stable physical-route identity derived from the ordered address snapshot. + +Do not key logical request-concurrency policy solely by raw socket address; logical proxy identity and physical route identity are separate concerns. + +## SOCKS interaction + +Pinned proxy-peer routing applies equally to SOCKS5 and SOCKS5H because it controls the TCP connection **to the SOCKS server**, not the SOCKS target address. + +Keep target-resolution semantics unchanged in this plan: + +- SOCKS5 continues its existing local-target-resolution behavior; +- SOCKS5H continues delegating target resolution to the proxy. + +The next child plan adds an explicit ultimate-target pin for SOCKS5 where enforceable. + +Do not adopt `eggress-protocol-socks` as part of this change. The existing Eggfetch SOCKS path already integrates shared deadlines, metrics, connection metadata, local binding/socket options, and error handling. Swapping only the handshake is orthogonal and would obscure whether route pinning itself is correct. + +## Custom Dialer and Egress interaction + +A configured built-in proxy route and `ClientBuilder::dialer()` remain separate routing authorities. Do not make the dialer secretly implement or override proxy-peer pinning. + +Applications that want Egress to own the whole chain should continue using the dialer path. Applications that want Eggfetch's native HTTP/SOCKS proxy implementation use this new built-in pinning control. There is no dependency or callback between them. + +## Error classification + +Use current `Error` and `send_detailed()` compatibility rules. + +Where the proxy path exposes typed evidence, preserve route provenance so callers can distinguish at least: + +- invalid pinned proxy configuration (pre-I/O validation); +- proxy peer DNS failure when no pin exists; +- proxy peer connection refusal/connect failure; +- proxy TLS failure; +- CONNECT/SOCKS/origin failure after the proxy peer was established. + +Do not parse error strings. Do not change existing `Error::kind()` tokens unless a separately justified compatibility change is required. + +## Tests + +Add deterministic local tests covering at minimum: + +1. proxy hostname has no DNS answer, supplied local proxy `SocketAddr` succeeds; +2. instrumented resolver/system-DNS failure proves static proxy-peer mode does not fall back to DNS; +3. empty peer set fails before I/O; +4. peer port mismatch fails before I/O; +5. first peer fails and second succeeds under one connect budget; +6. every peer fails -> connection error, no DNS fallback; +7. HTTP proxy peer pin works for an HTTP origin; +8. HTTP proxy peer pin works for HTTPS CONNECT; +9. HTTPS proxy connects to supplied IP while SNI/cert verification uses logical proxy hostname; +10. custom proxy CA / proxy TLS config behavior remains correct; +11. SOCKS5 server peer pin works; +12. SOCKS5H server peer pin works while target DNS remains remote; +13. retry preserves the same peer snapshot; +14. same-proxy redirect preserves the snapshot; +15. redirect into `NO_PROXY` does not apply stale proxy peers to the direct route; +16. two different peer snapshots for one logical proxy cannot cross-reuse an incompatible pooled transport; +17. unpinned proxy behavior remains unchanged; +18. `Debug`/error output does not expose credentials and does not gratuitously dump route topology. + +Prefer local listeners and deterministic fixtures. Do not depend on public DNS or an external proxy service. + +## Expected files + +Likely implementation surface: + +```text +crates/eggfetch-core/src/proxy.rs +crates/eggfetch-core/src/transport/proxy.rs +crates/eggfetch-core/src/pipeline.rs # only if route persistence/keying needs it +crates/eggfetch-core/src/client.rs # only if proxy client cache identity lives here +crates/eggfetch-core/src/error.rs # only if typed pre-I/O validation needs an existing-compatible variant +crates/eggfetch-core/tests/*proxy* +docs/architecture/core-tls-proxy-protocols.md +docs/rust/guide.md +``` + +Do not touch Python/CLI compatibility code unless an existing shared construction path mechanically requires carrying the native field without exposing it. + +## Required validation + +Focused first: + +```sh +cargo fmt --all -- --check +cargo test -p eggfetch-core --features proxy +cargo clippy -p eggfetch-core --all-targets --features proxy -- -D warnings +cargo tree -p eggfetch-core --no-default-features --features http1,tls-rustls,proxy +``` + +Then the repository's normative Tier 1 check: + +```sh +./scripts/check.sh +``` + +Before marking the child plan complete, also run affected proxy, TLS, retry, redirect, detailed-error, direct-static-routing, and custom-dialer regressions explicitly. + +## Acceptance criteria + +- [ ] A native caller can pin one or more physical proxy peers without changing the logical proxy URI. +- [ ] Pinned mode performs no proxy-host DNS lookup and never falls back to one. +- [ ] HTTP, HTTPS CONNECT, HTTPS-proxy TLS, SOCKS5, and SOCKS5H proxy-server connections use the supplied peer snapshot where applicable. +- [ ] HTTPS proxy SNI/certificate verification remains logical-host based. +- [ ] Candidate fallback shares the existing connect budget. +- [ ] Retry preserves the exact snapshot. +- [ ] Redirect/proxy-rule transitions cannot leak a stale peer constraint into a different route. +- [ ] Pool/client reuse cannot violate the physical route constraint. +- [ ] Existing unpinned proxy and direct `resolved_addresses()` behavior is unchanged. +- [ ] No new production dependency is introduced. +- [ ] No Egress dependency or EggSec-specific policy surface is introduced. From ed59f875dd1aa66cf3e4a1c4d601d2006db0b887 Mon Sep 17 00:00:00 2001 From: David Bowman Date: Mon, 14 Sep 2026 19:27:01 -0400 Subject: [PATCH 3/4] plans: add pinned proxied destination routing plan --- plans/pinned-proxy-destination-routing.md | 330 ++++++++++++++++++++++ 1 file changed, 330 insertions(+) create mode 100644 plans/pinned-proxy-destination-routing.md diff --git a/plans/pinned-proxy-destination-routing.md b/plans/pinned-proxy-destination-routing.md new file mode 100644 index 00000000..925efed6 --- /dev/null +++ b/plans/pinned-proxy-destination-routing.md @@ -0,0 +1,330 @@ +# Pinned Proxied Destination Routing + +Status: Ready for handoff + +Date: 2026-09-14 + +Parent: [`proxy-route-pinning-and-egress-interoperability-program.md`](proxy-route-pinning-and-egress-interoperability-program.md) + +Depends on: [`pinned-proxy-peer-routing.md`](pinned-proxy-peer-routing.md) + +Baseline: `d681da848e36199846604b71f2162a1054d24aa6` + +## Objective + +Add an explicit native request-level mechanism for a caller to pin the physical **ultimate destination** of a proxied request where Eggfetch can enforce that choice end to end, without changing the existing direct `RequestBuilder::resolved_addresses()` contract and without conflating the ultimate destination with the physical proxy peer. + +The feature must preserve logical origin semantics: + +```text +logical origin: https://service.example/api +approved origin socket: 203.0.113.10:443 +logical proxy: https://proxy.example:8443 +approved proxy socket: 198.51.100.20:8443 + +TCP #1: 198.51.100.20:8443 +proxy TLS identity: proxy.example +CONNECT / SOCKS target: 203.0.113.10:443 +origin TLS identity: service.example +HTTP Host / URL: service.example / logical URL +``` + +This lets callers that already own DNS/service-discovery/authorization decisions prove that neither Eggfetch nor the selected proxy route silently substitutes a different destination. + +## Why this must be a distinct API + +`RequestBuilder::resolved_addresses()` has an established security contract: it is direct-only and rejects effective proxy routes. Reinterpreting that existing option as a proxy tunnel target would silently broaden an API that currently fails closed. + +The new control must therefore be explicitly proxy-oriented. Conceptual native shapes include: + +```rust +client + .get("https://service.example/api")? + .proxy_target_addresses(["203.0.113.10:443".parse()?]) + .send() + .await?; +``` + +or an opaque validated proxy-route hint carried through a fluent request builder. + +Exact naming may change, but it must make the two address sets impossible to confuse: + +- proxy peer addresses belong to `Proxy`; +- proxied target addresses belong to the request/logical origin. + +Do not add another required field to the publicly constructible `TransportHints` struct. Prefer a builder method backed by private request state or an opaque validated type. If implementation reuses internal `TransportHints`, expose construction through methods and preserve source compatibility. + +## Core semantics + +The caller-supplied target snapshot controls only the physical target communicated to a proxy protocol. It does **not** replace: + +- the request URL; +- origin comparison for redirects/auth/cookies; +- HTTP Host; +- destination TLS SNI; +- destination certificate verification; +- response URL/history; +- proxy selection; +- proxy peer pinning. + +Empty sets and port mismatches fail before I/O. The effective target port must match the logical origin's effective port for v1. + +Retries preserve the exact snapshot. Same-origin redirects may preserve it. Cross-origin redirects must fail closed or clear it only into an explicitly unpinned behavior chosen by the caller; the preferred v1 behavior is fail closed, matching direct static routing. + +## HTTP CONNECT implementation + +### HTTPS origin through HTTP/HTTPS proxy + +For HTTPS origins, the proxy transport already establishes a CONNECT tunnel before destination TLS. This is the cleanest enforceable path. + +Without a pin, keep existing behavior: + +```text +CONNECT service.example:443 +``` + +With an explicit proxied target pin, the wire CONNECT authority may use the approved physical address: + +```text +CONNECT 203.0.113.10:443 +``` + +After the tunnel is established, destination TLS must still use the logical origin host (`service.example`) for SNI and certificate validation, and HTTP inside the tunnel must retain the logical Host/URL. + +For IPv6, use correct bracketed CONNECT authority syntax and test it directly. + +### Multiple approved target candidates + +A multi-address target set requires explicit retry/fallback semantics because an HTTP CONNECT proxy receives one authority per tunnel attempt. + +Use the existing shared connect/total deadline. For each approved candidate, Eggfetch may establish/reuse the proxy leg as safe and attempt CONNECT to that candidate. A failed CONNECT to one approved target may move to the next candidate only while the common budget remains. + +Do not perform a fresh origin DNS lookup after all supplied candidates fail. + +Be careful with HTTP status semantics. Proxy CONNECT rejection (for example 403/407/502) is not always evidence that trying another physical destination is appropriate. Define a conservative retry/fallback table from typed conditions rather than blindly cycling candidates on every non-2xx CONNECT response. + +Suggested initial rule: + +- connection-level failure specifically attributable to the requested tunnel target: candidate fallback may continue; +- proxy authentication/policy response: stop, because the result is proxy-wide rather than address-specific; +- malformed/protocol/TLS failure on the proxy leg: stop; +- ambiguous CONNECT status: stop unless existing typed evidence proves candidate-specific failure. + +## Plain HTTP forward-proxy limitation + +For a normal HTTP origin through an HTTP forward proxy, Eggfetch sends an absolute-form logical URL and the proxy itself performs the origin connection. Standard forwarding does not provide a separate wire field where Eggfetch can safely tell an arbitrary proxy "connect this logical host to this exact IP" while preserving ordinary proxy semantics. + +Therefore v1 must reject: + +```text +HTTP origin + forward proxy + explicit proxied target pin +``` + +before network I/O. + +Do not silently rewrite the absolute URI host to an IP and restore only the Host header: proxies may route/cache/authenticate based on the absolute URI authority, so that would alter logical origin semantics. + +If a future concrete consumer needs pinned plaintext HTTP through a proxy, evaluate an explicit CONNECT-for-HTTP mode as a separate design. Do not smuggle it into this plan. + +## SOCKS5 implementation + +Native `socks5://` represents local target resolution semantics. With an explicit proxied target snapshot, skip local DNS and issue the SOCKS5 CONNECT command using one of the supplied IP addresses. + +Required properties: + +- no origin DNS lookup in pinned mode; +- destination port must match the logical origin effective port; +- candidate order preserved; +- fallback attempts share one request/connect budget; +- destination TLS, if the logical origin is HTTPS, uses the logical origin hostname after SOCKS connection establishment; +- HTTP Host remains logical. + +The existing Eggfetch SOCKS client may be extended to accept an already-resolved target rather than being replaced. Keep timeout, metrics, connection metadata, local bind/socket options, and error taxonomy in one authoritative implementation. + +## SOCKS5H limitation + +Native `socks5h://` means the proxy resolves the target hostname. An explicit local physical target constraint conflicts with that contract. + +For v1: + +```text +SOCKS5H + explicit proxied target pin => pre-I/O error +``` + +Do not downgrade SOCKS5H to SOCKS5 silently. Do not send the IP while continuing to report remote-resolution semantics. Do not claim that authorizing a hostname proves the address selected by a remote resolver. + +Callers that require local destination validation use SOCKS5 plus this feature, or own the entire route through an external dialer. + +## Proxy peer pinning is independently required + +An ultimate target pin does not imply a trusted proxy socket. If the effective `Proxy` has no pinned peer, Eggfetch may still resolve the proxy endpoint normally. That is legitimate general client behavior, but callers that require complete physical-route control must configure both: + +```text +Proxy::... + pinned proxy peer addresses +RequestBuilder::... + pinned proxied target addresses +``` + +Document this explicitly. Do not make ultimate-target pinning automatically require proxy-peer pinning for ordinary users; instead expose enough connection metadata/diagnostics that security-sensitive callers can verify their configuration. A stricter combined convenience constructor may be considered only if it stays generic and does not create policy concepts. + +## Redirect semantics + +The proxied target snapshot is origin-specific. + +Required v1 behavior: + +- same `(scheme, host, effective port)` redirect under the same effective proxy may preserve the snapshot; +- a redirect changing host, scheme, or effective port must not reuse it; +- a cross-origin redirect from a pinned proxied request should fail closed before dispatch unless the caller explicitly supplied a new route for the new origin through a future API; +- a redirect that changes proxy selection must re-evaluate both proxy-peer and target routing state; +- auth/cookie/proxy-auth stripping rules remain unchanged and operate on logical origins, not physical IPs. + +Avoid building a general per-origin route map in v1. + +## Retry semantics + +Retry reconstructs the same logical request with the same immutable target snapshot and the same proxy configuration snapshot. No origin DNS lookup is introduced on later attempts. + +If the request body is not replayable, existing retry rules remain authoritative. Route pinning does not make a body replayable. + +Total timeout continues shrinking across retries/redirects; address fallback does not restart it. + +## Pool and route identity + +Audit connection reuse particularly carefully for CONNECT and SOCKS tunnels. + +A request for logical `service.example:443` pinned to `203.0.113.10:443` must not reuse a tunnel/connection that was established for the same logical origin through ordinary proxy DNS or through `203.0.113.11:443` unless route equivalence is proven by the cache key. + +At minimum the physical route identity for a reusable proxied connection must distinguish: + +```text +logical proxy identity +physical proxy peer snapshot (if supplied) +logical origin identity +physical proxied target snapshot (if supplied) +proxy protocol / resolution mode +relevant TLS route state +``` + +Do not over-key logical concurrency permits if the current pool intentionally limits by origin; physical connection compatibility and logical request admission are separate concerns. + +If the current proxy path does not pool tunnels, retain that simpler behavior and document/test it instead of introducing a new pool solely for this feature. + +## SNI, Host, and explicit override interaction + +The feature must compose with existing logical identity behavior. + +Default: + +```text +physical CONNECT/SOCKS target = caller-supplied IP +TLS SNI/cert name = logical origin hostname +HTTP Host = logical origin authority +``` + +If Eggfetch already supports an explicit SNI override on this route, that explicit override remains authoritative; route pinning does not invent or overwrite it. + +Host/request-target overrides must not be inferred from the physical IP. Any existing override incompatibility should fail using current rules rather than being silently normalized. + +## Error and observability behavior + +Use existing native detailed failure introspection where typed evidence exists. Route-sensitive diagnostics should distinguish the stage of failure without exposing downstream policy concepts: + +- proxy peer connect/TLS; +- proxy auth/CONNECT protocol; +- specific pinned tunnel target attempt; +- SOCKS negotiation/target refusal; +- destination TLS; +- request/response I/O. + +Do not add an EggSec-style authorization checkpoint enum. Do not make transient failed candidates survive as the terminal `RequestFailure` classification after a later candidate succeeds. + +Connection metadata should continue reporting truthful logical/wire state. If the existing response metadata cannot expose the physical ultimate peer for proxied tunnels, document that limitation rather than fabricating it; adding an optional generic physical-route snapshot may be considered if it is useful to more than this feature and does not leak credentials. + +## Egress interaction + +Do not import Egress for this work. + +`eggress-routing` can decide which route should be used at the application layer, but its rule/upstream/health model must not become Eggfetch request state. `eggress-protocol-socks` can establish SOCKS streams, but adopting it does not remove the need for Eggfetch's proxy-peer/tunnel identity, timeout, retry, TLS, and pool integration. + +When an application already wants Egress to own the complete tunnel or chain, it can use Eggfetch's custom `Dialer` seam instead of the built-in proxy path. This plan improves Eggfetch's own proxy route for callers that want Eggfetch to own proxy HTTP/SOCKS semantics. + +## Tests + +Add deterministic local coverage for at least: + +1. HTTPS CONNECT to an unresolvable logical origin succeeds through a local proxy when a pinned target IP is supplied; +2. proxy observes CONNECT to the supplied IP/port rather than the logical hostname; +3. TLS inside the tunnel uses logical origin SNI and validates the logical certificate name; +4. HTTP Host and `Response::url()` remain logical; +5. empty target set fails before I/O; +6. target port mismatch fails before I/O; +7. IPv6 CONNECT authority formatting is correct; +8. first target fails and second succeeds only for typed candidate-specific failures under one budget; +9. no origin DNS fallback after all pinned CONNECT candidates fail; +10. HTTPS-proxy + pinned proxy peer + pinned CONNECT target preserves both independent TLS identities; +11. SOCKS5 uses supplied target IP without origin DNS; +12. SOCKS5 multiple-target fallback follows one deadline; +13. SOCKS5H + target pin fails before I/O; +14. HTTP forward-proxy + HTTP origin + target pin fails before I/O; +15. same-origin redirect preserves the target snapshot; +16. cross-origin redirect fails before dispatch rather than using stale target state; +17. retry preserves the exact target snapshot; +18. incompatible target snapshots cannot cross-reuse a tunnel/connection; +19. ordinary unpinned HTTP proxy, CONNECT, SOCKS5, and SOCKS5H behavior remains unchanged; +20. direct `RequestBuilder::resolved_addresses()` continues rejecting effective proxy combinations exactly as before. + +Where practical, instrument local proxy fixtures to record the exact CONNECT/SOCKS destination. Do not infer physical binding solely from a successful response. + +## Expected files + +Likely implementation surface: + +```text +crates/eggfetch-core/src/request.rs +crates/eggfetch-core/src/proxy.rs +crates/eggfetch-core/src/pipeline.rs +crates/eggfetch-core/src/transport/proxy.rs +crates/eggfetch-core/src/transport/socks.rs +crates/eggfetch-core/src/client.rs # only if cache/route identity requires it +crates/eggfetch-core/src/error.rs # only for compatible typed validation/provenance +crates/eggfetch-core/tests/*proxy* +crates/eggfetch-core/tests/*socks* +docs/architecture/core-tls-proxy-protocols.md +docs/rust/guide.md +docs/reference/errors.md # if structured failure docs change +``` + +Avoid Python/CLI/HTTPX changes unless shared native plumbing requires internal propagation with no public exposure. + +## Required validation + +Focused checks: + +```sh +cargo fmt --all -- --check +cargo test -p eggfetch-core --features proxy +cargo clippy -p eggfetch-core --all-targets --features proxy -- -D warnings +cargo tree -p eggfetch-core --no-default-features --features http1,tls-rustls,proxy +``` + +Then: + +```sh +./scripts/check.sh +``` + +Before child-plan completion, also run all existing direct resolved-target, custom dialer, proxy TLS, SOCKS, retry, redirect, timeout, detailed-error, and connection-reuse tests affected by the route selection changes. + +## Acceptance criteria + +- [ ] A native caller can explicitly pin the physical ultimate target of an HTTPS CONNECT request while preserving the logical origin URL/Host/TLS identity. +- [ ] A native caller can explicitly pin the physical ultimate target of a SOCKS5 request without origin DNS fallback. +- [ ] Existing direct `resolved_addresses()` remains direct-only and unchanged. +- [ ] SOCKS5H ultimate-target pinning fails closed before I/O. +- [ ] Plain HTTP forward-proxy ultimate-target pinning fails closed before I/O in v1. +- [ ] Multiple supplied targets use a conservative typed fallback policy under one shared deadline. +- [ ] Retry and same-origin redirects preserve the target snapshot; cross-origin redirects cannot reuse it. +- [ ] Pool/tunnel reuse cannot violate physical route constraints. +- [ ] Proxy and destination TLS identities remain logically correct when both proxy peer and ultimate target are pinned. +- [ ] Existing unpinned proxy/SOCKS behavior and compatibility facades are unchanged. +- [ ] No new production dependency and no Egress dependency is introduced. From 6a76f5757b0228489f57a01fdaceaef47902a467 Mon Sep 17 00:00:00 2001 From: David Bowman Date: Mon, 14 Sep 2026 19:27:42 -0400 Subject: [PATCH 4/4] plans: add proxy route pinning closure plan --- ...route-pinning-qualification-and-closure.md | 290 ++++++++++++++++++ 1 file changed, 290 insertions(+) create mode 100644 plans/post-proxy-route-pinning-qualification-and-closure.md diff --git a/plans/post-proxy-route-pinning-qualification-and-closure.md b/plans/post-proxy-route-pinning-qualification-and-closure.md new file mode 100644 index 00000000..4f211f8f --- /dev/null +++ b/plans/post-proxy-route-pinning-qualification-and-closure.md @@ -0,0 +1,290 @@ +# Post-Proxy Route Pinning Qualification and Closure + +Status: Ready for handoff + +Date: 2026-09-14 + +Parent: [`proxy-route-pinning-and-egress-interoperability-program.md`](proxy-route-pinning-and-egress-interoperability-program.md) + +Depends on: + +- [`pinned-proxy-peer-routing.md`](pinned-proxy-peer-routing.md) +- [`pinned-proxy-destination-routing.md`](pinned-proxy-destination-routing.md) + +Baseline: `d681da848e36199846604b71f2162a1054d24aa6` + +## Purpose + +Close the proxy route-pinning program with evidence that the new native controls are bounded, fail closed, dependency-neutral, compatible with existing direct/proxy behavior, and suitable for unrelated embedders without turning Eggfetch into a routing-policy framework. + +This phase should introduce no new architecture except corrections exposed by qualification. + +## 1. Freeze the executable surface + +After both implementation child plans satisfy their focused tests, identify one executable/test/fixture SHA for qualification. Record: + +```text +baseline SHA +implementation/freeze SHA +files changed +public API additions +production dependency delta +feature delta +``` + +Do not mix unrelated HTTP/3, compatibility-facade, binding, or dependency work into the freeze. If unrelated executable changes land first, rebase/reconcile and establish a new freeze rather than claiming evidence from the earlier tree. + +Documentation-only descendants may be used for closure records after the executable freeze, consistent with current repository practice. + +## 2. Audit the public API boundary + +Verify that the final API preserves the intended model: + +```text +Proxy object + logical proxy URI + optional physical proxy-peer snapshot + +Request + logical origin URL + optional physical proxied-target snapshot + +existing Request::resolved_target + direct route only +``` + +Required findings: + +- proxy peer and proxied target cannot be confused by the API or debug output; +- direct `resolved_addresses()` still rejects an effective proxy; +- no new public field is required on `TransportHints` merely to add proxy pinning; +- ordinary callers need no changes; +- Python/CLI/HTTPX facades do not expose unsupported invented reference behavior; +- no downstream-specific policy concept appears in the public API; +- caller responsibility for validating supplied addresses is documented explicitly. + +If implementation broadened `ResolvedTarget` documentation or extracted a private shared static-destination representation, verify that source compatibility and existing semantics remain intact. + +## 3. End-to-end route-binding matrix + +Run deterministic local fixtures that prove actual wire destinations, not merely builder state. + +Minimum matrix: + +| Proxy route | Proxy peer | Ultimate target | Expected result | +|---|---|---|---| +| HTTP proxy -> HTTP origin | pinned | unpinned | succeeds; proxy TCP peer is pinned | +| HTTP proxy -> HTTP origin | pinned | pinned | rejected before I/O in v1 | +| HTTP proxy -> HTTPS origin | pinned | pinned | CONNECT uses supplied target; destination TLS/Host stay logical | +| HTTPS proxy -> HTTPS origin | pinned | pinned | proxy TLS authenticates proxy host; destination TLS authenticates origin host | +| SOCKS5 -> HTTP origin | pinned | pinned | SOCKS server peer and target IP both pinned | +| SOCKS5 -> HTTPS origin | pinned | pinned | destination TLS identity remains logical | +| SOCKS5H | pinned | unpinned | existing remote-DNS behavior succeeds | +| SOCKS5H | pinned | pinned | rejected before I/O | +| no proxy | n/a | direct `resolved_addresses()` | existing direct static routing unchanged | + +For successful pinned cases, assert the peer/destination seen by the local fixture. For rejected cases, assert the listener observes no connection when the incompatibility is detectable before proxy I/O. + +## 4. DNS non-fallback proof + +Add/retain tests that make logical proxy/origin hostnames intentionally unresolvable while supplied local `SocketAddr` values work. + +Prove separately: + +- pinned proxy peer performs no proxy-host DNS; +- pinned CONNECT target performs no origin DNS before CONNECT; +- pinned SOCKS5 target performs no origin DNS; +- retries do not introduce DNS; +- same-origin redirects do not introduce DNS; +- unsupported pinned SOCKS5H never silently becomes local DNS or SOCKS5; +- exhausted supplied candidates never fall back to system DNS. + +Use counters/test seams where available. Success alone is weaker evidence than an explicit no-resolution assertion. + +## 5. Identity and TLS proof + +Use local certificates/fixtures to prove the four-way separation: + +```text +physical proxy peer != logical proxy host +physical origin target != logical origin host +``` + +Assertions: + +- HTTPS proxy SNI and certificate verification use logical proxy host; +- origin TLS inside CONNECT/SOCKS uses logical origin host; +- HTTP Host uses logical origin authority; +- response URL/history remain logical; +- proxy authentication is sent only on proxy leg; +- cross-origin auth/cookie stripping continues to use logical origins; +- explicit existing SNI/proxy-TLS overrides keep their current precedence. + +A test that only disables certificate validation is insufficient evidence for identity preservation. + +## 6. Retry, redirect, timeout, and fallback proof + +Verify that all physical route snapshots participate correctly in request reconstruction. + +### Retry + +- same proxy-peer and target snapshots are reused; +- total deadline shrinks across attempts; +- non-replayable bodies retain existing retry rejection; +- terminal `RequestFailure` reflects the final typed failure rather than a stale transient candidate. + +### Redirect + +- same-origin + same effective proxy may preserve destination state; +- cross-origin pin reuse fails closed; +- redirect into `NO_PROXY` cannot apply proxy peer state to direct transport; +- redirect selecting a different proxy cannot inherit old proxy peers; +- credentials retain current stripping/redaction behavior. + +### Candidate fallback + +- proxy peer candidates share one proxy-connect budget; +- ultimate CONNECT/SOCKS candidates share the appropriate remaining request/connect budget; +- candidate cycling occurs only for failures classified as safe/address-specific by the implementation; +- no fresh full timeout is granted per candidate. + +## 7. Pool/reuse audit + +Inspect the exact cache/client/pool keys used by all affected routes and record a disposition for: + +```text +HTTP forward proxy +HTTPS CONNECT +HTTPS proxy +SOCKS5 +SOCKS5H +``` + +For every reusable connection/tunnel, either: + +1. prove the physical route snapshot participates in compatibility/keying; or +2. prove the route does not reuse such physical connections and therefore cannot cross constraints. + +Required adversarial test: issue two requests for the same logical proxy/origin with different pinned address sets and prove the second cannot ride an incompatible connection established by the first. + +Do not introduce a new connection cache only to satisfy this audit. + +## 8. Error and observability audit + +Exercise ordinary `send()` and native `send_detailed()` where applicable. + +Check that: + +- pre-I/O invalid pinned configuration has a stable typed/error-kind disposition; +- proxy-host DNS classification still occurs only when system resolution was actually attempted; +- proxy-peer connection refusal/connect failure retains typed provenance where supported; +- CONNECT/SOCKS target failure is not mislabeled as proxy DNS; +- proxy TLS and origin TLS failures remain distinguishable through the existing error/source model; +- transient candidate failures do not leak as terminal detailed classification after success/fallback; +- no implementation matches error `Display`/`Debug` strings. + +Do not expand the public error enum merely for prettier diagnostics unless a concrete unrepresentable failure requires it and compatibility impact is separately reviewed. + +## 9. Egress dependency/reuse closure + +Re-run the Egress decision against the implementation rather than copying the planning conclusion blindly. + +Expected disposition: **no Eggfetch -> Egress dependency**. + +Record the exact Egress SHA reviewed and confirm: + +- `eggress-routing` remains a policy/scheduler layer above the HTTP engine rather than a neutral dependency; +- `eggress-uri` would broaden protocol grammar without deleting enough Eggfetch code to justify coupling; +- `eggress-protocol-socks` remains orthogonal to route pinning and would not remove Eggfetch's timeout/metrics/TLS/pool integration burden; +- Eggfetch `Dialer` remains the generic external composition seam for applications that want Egress to own the entire route. + +If the implementation unexpectedly duplicates a small neutral primitive that exists in Egress, measure the actual dependency/code delta before revising this disposition. Do not add an umbrella Egress dependency as a convenience. + +## 10. Dependency and feature audit + +Expected production dependency delta: zero. + +Record before/after output for: + +```sh +cargo tree -p eggfetch-core --no-default-features --features http1,tls-rustls +cargo tree -p eggfetch-core --no-default-features --features http1,tls-rustls,proxy +cargo tree -p eggfetch-core -e features +cargo tree -p eggfetch-core -d +``` + +Acceptance: + +- minimal non-proxy profile is unchanged by proxy-only implementation; +- no `eggress-*` package appears; +- no second resolver, proxy client, routing framework, or TLS stack appears; +- feature ownership remains truthful; +- proxy pinning stays behind the existing `proxy` feature except for any zero-cost shared address type already required by direct routing. + +Do not claim binary slimming. If artifact size is measured, report it as supporting evidence only and compare equivalent feature profiles. + +## 11. Repository validation + +The normative policy is `docs/verification-policy.md`. + +Run Tier 1 on every implementation increment: + +```sh +./scripts/check.sh +``` + +Before program closure, run: + +```sh +./scripts/check.sh extended +./scripts/check.sh package +``` + +Optional prerequisite skips in extended validation must be recorded as skips, not converted into passes. + +Because this program changes executable transport behavior, also run the current full compatibility qualification required by the live HTTPX/HTTPX2 profile status. If the repository's exact-SHA Stage C ledger is still active at implementation time, renew it on the frozen executable SHA using the current profile procedure and record the results. Do not cargo-cult historical run counts if the normative compatibility procedure has changed; follow the live profile/status files. + +Hosted CI should run through the repository's single normal workflow. Do not add a proxy-route matrix, external proxy service, automatic evidence workflow, or extra CI job; deterministic local fixtures belong in existing tests. + +## 12. Documentation closure + +Update, as applicable: + +```text +docs/architecture/core-tls-proxy-protocols.md +docs/architecture/core-engine.md +docs/rust/guide.md +docs/reference/errors.md +README.md / feature matrix only if public capability summaries need it +plans/README.md +plans/ROADMAP.md only if the live roadmap needs a current-position note +``` + +Documentation must state clearly: + +- physical proxy peer versus logical proxy URI; +- physical proxied target versus logical origin URL; +- direct `resolved_addresses()` remains a separate direct-only API; +- supported CONNECT/SOCKS5 combinations; +- SOCKS5H remote-resolution limitation; +- plaintext HTTP forward-proxy limitation; +- retry/redirect snapshot semantics; +- no-DNS-fallback guarantees; +- pool/reuse constraints; +- caller responsibility for validating supplied addresses; +- Egress relationship: external routing/dialer composition, not a core dependency. + +Mark the parent/child plans complete only after the final executable evidence is bound to a specific SHA. Preserve them as historical implementation records afterward. + +## Final acceptance criteria + +- [ ] Both child plans' acceptance criteria are satisfied or any unsupported row is explicitly narrowed/fail-closed. +- [ ] Wire fixtures prove proxy-peer and supported ultimate-target physical destinations. +- [ ] DNS non-fallback is directly tested for pinned proxy peers and supported pinned targets. +- [ ] Proxy and origin logical TLS/HTTP identities remain correct under physical pinning. +- [ ] Retry/redirect/candidate timeout behavior is bounded and deterministic. +- [ ] Connection reuse cannot cross incompatible physical-route constraints. +- [ ] Existing unpinned proxy, direct static routing, dialer, Python/CLI/HTTPX, and HTTP/3 behavior remains compatible. +- [ ] Tier 1, extended, package, affected focused suites, and current compatibility qualification are green or truthfully record optional skips. +- [ ] No new production dependency appears; specifically no `eggress-*` dependency is present. +- [ ] Documentation and plan status match the implementation actually shipped.