From 983c1adb28b23252cbc84b892a8c3651ca85f41a Mon Sep 17 00:00:00 2001 From: noisyfox Date: Thu, 8 Dec 2016 18:48:40 +1100 Subject: [PATCH] Check secret in PACServer --- .../Controller/Service/PACServer.cs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/shadowsocks-csharp/Controller/Service/PACServer.cs b/shadowsocks-csharp/Controller/Service/PACServer.cs index cf918e0a..30bf246f 100644 --- a/shadowsocks-csharp/Controller/Service/PACServer.cs +++ b/shadowsocks-csharp/Controller/Service/PACServer.cs @@ -60,6 +60,7 @@ namespace Shadowsocks.Controller string request = Encoding.UTF8.GetString(firstPacket, 0, length); string[] lines = request.Split('\r', '\n'); bool hostMatch = false, pathMatch = false, useSocks = false; + bool secretMatch = PacSecret.IsNullOrEmpty(); foreach (string line in lines) { string[] kv = line.Split(new char[] { ':' }, 2); @@ -87,11 +88,25 @@ namespace Shadowsocks.Controller { pathMatch = true; } + if (!secretMatch) + { + if(line.IndexOf(PacSecret, StringComparison.Ordinal) >= 0) + { + secretMatch = true; + } + } } } if (hostMatch && pathMatch) { - SendResponse(firstPacket, length, socket, useSocks); + if (!secretMatch) + { + socket.Close(); // Close immediately + } + else + { + SendResponse(firstPacket, length, socket, useSocks); + } return true; } return false;