{"record":{"id":"d49d49a64ddd04c5","repo":"siyuan-note/siyuan","slug":"proxy-returned-unexpected-tunnel-data","errorCode":null,"errorMessage":"proxy returned unexpected tunnel data","messagePattern":"proxy returned unexpected tunnel data","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/util/httprequest.go","lineNumber":109,"sourceCode":"\t\treturn nil, err\n\t}\n\tif proxyURL == nil {\n\t\treturn t.directTransport.RoundTrip(req)\n\t}\n\n\ttargetAddr, err := t.resolvePublicTarget(req.Context(), req.URL)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tconn, reader, err := dialProxyTunnel(req.Context(), proxyURL, targetAddr)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\tif req.URL.Scheme == \"https\" {\n\t\tif reader.Buffered() != 0 {\n\t\t\tconn.Close()\n\t\t\treturn nil, errors.New(\"proxy returned unexpected tunnel data\")\n\t\t}\n\t\ttlsConn := tls.Client(conn, &tls.Config{ServerName: req.URL.Hostname(), NextProtos: []string{\"http/1.1\"}})\n\t\tif err = tlsConn.HandshakeContext(req.Context()); err != nil {\n\t\t\tconn.Close()\n\t\t\treturn nil, err\n\t\t}\n\t\tconn = tlsConn\n\t\treader = bufio.NewReader(conn)\n\t}\n\n\ttargetReq := req.Clone(req.Context())\n\ttargetReq.URL = cloneURL(req.URL)\n\ttargetReq.URL.Scheme = \"\"\n\ttargetReq.URL.Host = \"\"\n\ttargetReq.RequestURI = \"\"\n\ttargetReq.Header.Del(\"Proxy-Authorization\")\n\tif targetReq.Host == \"\" {\n\t\ttargetReq.Host = req.URL.Host","sourceCodeStart":91,"sourceCodeEnd":127,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/util/httprequest.go#L91-L127","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\nproxy: \"http://proxy.internal:3128\"  // intercepting proxy\n// after\nproxy: null  // direct SSRF-dialed connection, or a compliant proxy","handlingStrategy":"retry","validationCode":"// verify the proxy actually tunnels before use\n// curl --proxy <proxyURL> -sSI https://example.com","typeGuard":null,"tryCatchPattern":"if strings.Contains(err.Error(), \"proxy returned unexpected tunnel data\") {\n    // disable or replace the proxy and retry direct\n}","preventionTips":["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"],"tags":["network","proxy","tls","http"],"backgroundTag":"unexpected-response-shape","analyzedSha":"9f775e8a12daef8255556097396f9b2739078892","analyzedAt":"2026-09-19T03:17:15.984Z","contentChangedAt":"2026-09-19T03:17:15.984Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}