Skip to content
This repository was archived by the owner on Jul 9, 2023. It is now read-only.

Commit 48c041e

Browse files
committed
#565 Verify hostname before prefetching connection
1 parent 10c923e commit 48c041e

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

src/Titanium.Web.Proxy/ExplicitClientHandler.cs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ private async Task handleClient(ExplicitProxyEndPoint endPoint, TcpClientConnect
4747
{
4848
string connectHostname = null;
4949
TunnelConnectSessionEventArgs connectArgs = null;
50-
50+
5151

5252
// Client wants to create a secure tcp tunnel (probably its a HTTPS or Websocket request)
5353
if (await HttpHelper.IsConnectMethod(clientStream) == 1)
@@ -154,11 +154,17 @@ await clientStreamWriter.WriteResponseAsync(connectArgs.HttpClient.Response,
154154

155155
if (EnableTcpServerConnectionPrefetch)
156156
{
157-
//don't pass cancellation token here
158-
//it could cause floating server connections when client exits
159-
prefetchConnectionTask = tcpConnectionFactory.GetServerConnection(this, connectArgs,
160-
isConnect: true, applicationProtocols: null, noCache: false,
161-
cancellationToken: CancellationToken.None);
157+
//make sure the host can be resolved before creating the prefetch task
158+
var ipAddresses = await Dns.GetHostAddressesAsync(connectArgs.HttpClient.Request.RequestUri.Host);
159+
160+
if (ipAddresses != null && ipAddresses.Length > 0)
161+
{
162+
//don't pass cancellation token here
163+
//it could cause floating server connections when client exits
164+
prefetchConnectionTask = tcpConnectionFactory.GetServerConnection(this, connectArgs,
165+
isConnect: true, applicationProtocols: null, noCache: false,
166+
cancellationToken: CancellationToken.None);
167+
}
162168
}
163169

164170
X509Certificate2 certificate = null;

0 commit comments

Comments
 (0)