fix(proxy): extract SNI before dial for SNI-deferred connections#14
Merged
nnemirovsky merged 1 commit intomainfrom Apr 9, 2026
Merged
fix(proxy): extract SNI before dial for SNI-deferred connections#14nnemirovsky merged 1 commit intomainfrom
nnemirovsky merged 1 commit intomainfrom
Conversation
41ecfd3 to
2a9c4f7
Compare
Restructure handleConnect so that SNI-deferred connections extract the TLS ClientHello SNI BEFORE dialing through the MITM proxy. Previously, dial was called first with the raw IP as the CONNECT target, causing goproxy to use the IP for the upstream TLS ServerName. The real server's cert has DNS SANs (e.g. *.telegram.org), not IP SANs, so TLS verification failed with "cannot validate certificate for <IP>". New flow for SNI-deferred connections: 1. Send SOCKS5 CONNECT success (so client starts TLS handshake) 2. Peek ClientHello to extract SNI hostname 3. Update context FQDN with recovered hostname 4. Evaluate policy with hostname 5. Dial through MITM with hostname (not IP) Also: refactor relay logic into reusable relayData method, extract sniSaveRule helper to reduce duplication. Also: revised ECH DNS hostname recovery plan from review feedback.
2a9c4f7 to
76dfe9b
Compare
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
Fixes the recurring bug where SNI-deferred IP connections fail with
x509: cannot validate certificate for <IP> because it doesn't contain any IP SANs. This broke OpenClaw's Telegram connection whenever the DNS reverse cache expired.Root cause:
handleConnectcalleds.dial()before extracting SNI, so the MITM proxy used the raw IP for the upstream TLS ServerName. The real server's cert has DNS SANs only.Fix: Restructure
handleConnectfor SNI-deferred connections to extract SNI BEFORE dialing. Also makes SNI the happy path for ALL TLS connections with IP-only CONNECT (no DNS cache dependency for TLS).Also fixes
peekSNIto handle multi-read TLS ClientHello records (some records span multiple TCP segments).Test plan
[SNI] 149.154.166.110 -> api.telegram.org:443[SNI->ALLOW] hostname matched allow rule[INJECT] injected credential "telegram_bot_token"