siyuan-note/siyuan · error
proxy returned unexpected tunnel data
Error message
proxy returned unexpected tunnel data
What it means
The SSRF-safe proxy RoundTrip establishes a CONNECT tunnel through the proxy, then requires that the buffered reader is fully drained before starting TLS. Leftover bytes mean the proxy sent unexpected data inside the tunnel (protocol violation, or a non-CONNECT response such as an error page), so the connection is closed and this error returned.
Solutions
- Fix or replace the proxy so it performs proper CONNECT tunneling with no extra payload
- Authenticate/bypass the captive portal before making requests
- Check the proxy address/port (HTTP_PROXY/HTTPS_PROXY) points at a real HTTP proxy
- Capture the proxy's response (curl --proxy, packet sniffer) to identify the unexpected bytes
Example fix
// before proxy: "http://proxy.internal:3128" // intercepting proxy // after proxy: null // direct SSRF-dialed connection, or a compliant proxy
Defensive patterns
Strategy: retry
Validate before calling
// verify the proxy actually tunnels before use // curl --proxy <proxyURL> -sSI https://example.com
Try / catch
if strings.Contains(err.Error(), "proxy returned unexpected tunnel data") {
// disable or replace the proxy and retry direct
} Prevention
- Use a standards-compliant CONNECT-capable proxy
- Authenticate captive portals before issuing requests
- Keep HTTP_PROXY/HTTPS_PROXY pointing at real HTTP proxies on correct ports
- Avoid transparent/intercepting proxies for agent traffic
When it happens
Trigger: An HTTPS request through the ssrfSafeClient proxy where the proxy responds to CONNECT with extra bytes after the header terminator — e.g. a captive portal, an intercepting corporate proxy returning an HTML error page, or a misbehaving proxy implementation.
Common situations: Corporate/firewall proxies injecting content; hotel/airport captive portals intercepting CONNECT; proxy misconfiguration pointing at an HTTP-only proxy or wrong port; transparent proxies not honoring CONNECT semantics.
Related errors
- discover OIDC provider failed
- authentication probe returned HTTP " + response.status
- boot progress request returned HTTP " + response.status
- download custom emoji failed
- download custom emoji failed with status
AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19).
Data as JSON: /api/errors/d49d49a64ddd04c5.
Report an issue: GitHub.
Appendix: source
Thrown at kernel/util/httprequest.go:109
return nil, err
}
if proxyURL == nil {
return t.directTransport.RoundTrip(req)
}
targetAddr, err := t.resolvePublicTarget(req.Context(), req.URL)
if err != nil {
return nil, err
}
conn, reader, err := dialProxyTunnel(req.Context(), proxyURL, targetAddr)
if err != nil {
return nil, err
}
if req.URL.Scheme == "https" {
if reader.Buffered() != 0 {
conn.Close()
return nil, errors.New("proxy returned unexpected tunnel data")
}
tlsConn := tls.Client(conn, &tls.Config{ServerName: req.URL.Hostname(), NextProtos: []string{"http/1.1"}})
if err = tlsConn.HandshakeContext(req.Context()); err != nil {
conn.Close()
return nil, err
}
conn = tlsConn
reader = bufio.NewReader(conn)
}
targetReq := req.Clone(req.Context())
targetReq.URL = cloneURL(req.URL)
targetReq.URL.Scheme = ""
targetReq.URL.Host = ""
targetReq.RequestURI = ""
targetReq.Header.Del("Proxy-Authorization")
if targetReq.Host == "" {
targetReq.Host = req.URL.HostView on GitHub (pinned to 9f775e8a12)