Skip to content

Commit 60c3f31

Browse files
Pangjipingclaude
andauthored
fix(egress): add ssl_insecure opt-in and connection_strategy=lazy for mitmproxy (#860)
* fix(egress): set connection_strategy=lazy for egress mitmproxy * fix(egress): resolve upstream by SNI hostname to fix TLS IP mismatch Transparent mode redirects connections to IP addresses, but upstream server certificates contain hostnames, causing "Certificate verify failed: IP address mismatch". Instead of disabling TLS verification (ssl_insecure), add a built-in mitmproxy addon that rewrites the upstream server address from IP to SNI hostname, preserving full certificate verification. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com> * fix(egress): improve resolve_by_sni addon with debug logging and upstream_cert=false - Add load event to confirm the addon is loaded by mitmdump - Add verbose server_connect logging to diagnose why the hook may not fire - Set data.server.sni explicitly when rewriting address - Add upstream_cert=false to prevent mitmproxy from eagerly connecting to the original IP before the addon can rewrite the server address Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com> * fix(egress): use f-strings for ctx.log to avoid TypeError in mitmproxy 10.x mitmproxy 10.x ctx.log() accepts only a single message string, not printf-style format args. Switch all ctx.log calls to f-strings. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com> * fix(egress): add ssl_insecure=true for transparent mitmproxy, remove SNI addon Clients connecting to IP addresses do not send TLS SNI (RFC 6066), so upstream certificate hostname verification is impossible in transparent mode. Default to ssl_insecure=true to skip upstream TLS verification. Also revert the resolve_by_sni addon and its integration since SNI is not available — the addon cannot help when sni=None. Set OPENSANDBOX_EGRESS_MITMPROXY_SSL_INSECURE=false to re-enable upstream verification if all clients connect by hostname. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com> * fix(egress): default ssl_insecure to false, only enable via env var Do not skip upstream TLS verification by default. Users must explicitly set OPENSANDBOX_EGRESS_MITMPROXY_SSL_INSECURE=true to disable it when clients connect by IP (no SNI available). Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>
1 parent 7f16d6f commit 60c3f31

2 files changed

Lines changed: 13 additions & 0 deletions

File tree

components/egress/pkg/constants/configuration.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ const (
4242
EnvMitmproxyScript = "OPENSANDBOX_EGRESS_MITMPROXY_SCRIPT"
4343
EnvMitmproxyUpstreamTrustDir = "OPENSANDBOX_EGRESS_MITMPROXY_UPSTREAM_TRUST_DIR"
4444
EnvMitmproxyIgnoreHosts = "OPENSANDBOX_EGRESS_MITMPROXY_IGNORE_HOSTS"
45+
EnvMitmproxySslInsecure = "OPENSANDBOX_EGRESS_MITMPROXY_SSL_INSECURE"
4546

4647
// Comma-separated upstream resolvers: literal IP only (optional :port) — no hostnames (see dnsproxy REDIRECT note).
4748
EnvDNSUpstream = "OPENSANDBOX_EGRESS_DNS_UPSTREAM"

components/egress/pkg/mitmproxy/launch.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,18 @@ func Launch(cfg Config) (*Running, error) {
102102
// Stream large bodies instead of buffering them in memory (OOM prevention).
103103
args = append(args, "--set", "stream_large_bodies=1m")
104104

105+
// Lazy connection strategy: defer upstream connection until the request is fully received,
106+
// which avoids unnecessary connections for blocked/filtered requests.
107+
args = append(args, "--set", "connection_strategy=lazy")
108+
109+
// Transparent mode redirects TCP to IP addresses. Clients connecting to IPs
110+
// do not send SNI, so upstream TLS cert hostname verification fails with
111+
// "IP address mismatch". Set OPENSANDBOX_EGRESS_MITMPROXY_SSL_INSECURE=true
112+
// to skip upstream verification when clients connect by IP.
113+
if constants.IsTruthy(os.Getenv(constants.EnvMitmproxySslInsecure)) {
114+
args = append(args, "--set", "ssl_insecure=true")
115+
}
116+
105117
homeEnv := home
106118
if strings.TrimSpace(cfg.ConfDir) != "" {
107119
cd := strings.TrimSpace(cfg.ConfDir)

0 commit comments

Comments
 (0)