From b27ae11d1eb9cc3028590b92ad13b2439e61c499 Mon Sep 17 00:00:00 2001 From: DHR60 <192860629+DHR60@users.noreply.github.com> Date: Wed, 5 Aug 2026 06:26:16 +0000 Subject: [PATCH] Adjust allow insecure fmt (#9888) * Adjust allow insecure fmt * Remove `VLESS` insecure fmt --- v2rayN/ServiceLib/Handler/Fmt/AnytlsFmt.cs | 9 +++++ v2rayN/ServiceLib/Handler/Fmt/BaseFmt.cs | 35 ------------------- v2rayN/ServiceLib/Handler/Fmt/Hysteria2Fmt.cs | 8 +++++ v2rayN/ServiceLib/Handler/Fmt/TrojanFmt.cs | 10 ++++++ v2rayN/ServiceLib/Handler/Fmt/TuicFmt.cs | 9 ++++- 5 files changed, 35 insertions(+), 36 deletions(-) diff --git a/v2rayN/ServiceLib/Handler/Fmt/AnytlsFmt.cs b/v2rayN/ServiceLib/Handler/Fmt/AnytlsFmt.cs index d94cbea0..4ea6a0eb 100644 --- a/v2rayN/ServiceLib/Handler/Fmt/AnytlsFmt.cs +++ b/v2rayN/ServiceLib/Handler/Fmt/AnytlsFmt.cs @@ -25,6 +25,11 @@ public class AnytlsFmt : BaseFmt var query = Utils.ParseQueryString(parsedUrl.Query); ResolveUriQuery(query, ref item); + if (GetQueryValue(query, "insecure") == "1") + { + item.AllowInsecure = Global.StringTrue; + } + return item; } @@ -41,6 +46,10 @@ public class AnytlsFmt : BaseFmt } var pw = item.Password; var dicQuery = new Dictionary(); + if (item.GetAllowInsecure()) + { + dicQuery.Add("insecure", "1"); + } ToUriQuery(item, Global.None, ref dicQuery); return ToUri(EConfigType.Anytls, item.Address, item.Port, pw, dicQuery, remark); diff --git a/v2rayN/ServiceLib/Handler/Fmt/BaseFmt.cs b/v2rayN/ServiceLib/Handler/Fmt/BaseFmt.cs index 1427581e..4b6fee41 100644 --- a/v2rayN/ServiceLib/Handler/Fmt/BaseFmt.cs +++ b/v2rayN/ServiceLib/Handler/Fmt/BaseFmt.cs @@ -4,8 +4,6 @@ namespace ServiceLib.Handler.Fmt; public class BaseFmt { - private static readonly string[] _allowInsecureArray = new[] { "insecure", "allowInsecure", "allow_insecure" }; - private static string UrlEncodeSafe(string? value) => Utils.UrlEncode(value ?? string.Empty); protected static string GetIpv6(string address) @@ -67,7 +65,6 @@ public class BaseFmt { dicQuery.Add("alpn", Utils.UrlEncode(item.Alpn)); } - ToUriQueryAllowInsecure(item, ref dicQuery); } if (item.EchConfigList.IsNotEmpty()) { @@ -196,25 +193,6 @@ public class BaseFmt dicQuery.Add("alpn", Utils.UrlEncode(item.Alpn)); } - ToUriQueryAllowInsecure(item, ref dicQuery); - - return 0; - } - - private static int ToUriQueryAllowInsecure(ProfileItem item, ref Dictionary dicQuery) - { - if (item.GetAllowInsecure()) - { - // Add two for compatibility - dicQuery.Add("insecure", "1"); - dicQuery.Add("allowInsecure", "1"); - } - else - { - dicQuery.Add("insecure", "0"); - dicQuery.Add("allowInsecure", "0"); - } - return 0; } @@ -252,19 +230,6 @@ public class BaseFmt item.Finalmask = string.Empty; } - if (_allowInsecureArray.Any(k => GetQueryDecoded(query, k) == "1")) - { - item.AllowInsecure = Global.StringTrue; - } - else if (_allowInsecureArray.Any(k => GetQueryDecoded(query, k) == "0")) - { - item.AllowInsecure = Global.StringFalse; - } - else - { - item.AllowInsecure = string.Empty; - } - var net = GetQueryValue(query, "type", nameof(ETransport.raw)); if (net == Global.RawNetworkAlias) { diff --git a/v2rayN/ServiceLib/Handler/Fmt/Hysteria2Fmt.cs b/v2rayN/ServiceLib/Handler/Fmt/Hysteria2Fmt.cs index 97a55225..83172117 100644 --- a/v2rayN/ServiceLib/Handler/Fmt/Hysteria2Fmt.cs +++ b/v2rayN/ServiceLib/Handler/Fmt/Hysteria2Fmt.cs @@ -162,6 +162,10 @@ public class Hysteria2Fmt : BaseFmt private static void ResolveHy2UriQuery(NameValueCollection query, ref ProfileItem item) { + if (GetQueryValue(query, "insecure") == "1") + { + item.AllowInsecure = Global.StringTrue; + } if (item.CertSha.IsNullOrEmpty()) { item.CertSha = GetQueryDecoded(query, "pinSHA256"); @@ -198,6 +202,10 @@ public class Hysteria2Fmt : BaseFmt private static void ToHy2UriQuery(ProfileItem item, ref Dictionary dicQuery) { + if (item.GetAllowInsecure()) + { + dicQuery.Add("insecure", "1"); + } if (!item.CertSha.IsNullOrEmpty() && !item.CertSha.Contains(',')) { diff --git a/v2rayN/ServiceLib/Handler/Fmt/TrojanFmt.cs b/v2rayN/ServiceLib/Handler/Fmt/TrojanFmt.cs index 630dead1..00a9df7a 100644 --- a/v2rayN/ServiceLib/Handler/Fmt/TrojanFmt.cs +++ b/v2rayN/ServiceLib/Handler/Fmt/TrojanFmt.cs @@ -2,6 +2,8 @@ namespace ServiceLib.Handler.Fmt; public class TrojanFmt : BaseFmt { + private static readonly List _insecureQueryKeys = new() { "allowInsecure", "insecure" }; + public static ProfileItem? Resolve(string str, out string msg) { msg = ResUI.ConfigurationFormatIncorrect; @@ -23,6 +25,10 @@ public class TrojanFmt : BaseFmt item.Password = Utils.UrlDecode(url.UserInfo); var query = Utils.ParseQueryString(url.Query); + if (_insecureQueryKeys.Any(q => GetQueryValue(query, q) == "1")) + { + item.AllowInsecure = Global.StringTrue; + } item.SetProtocolExtra(item.GetProtocolExtra() with { Flow = GetQueryValue(query, "flow") }); ResolveUriQuery(query, ref item); @@ -41,6 +47,10 @@ public class TrojanFmt : BaseFmt remark = "#" + Utils.UrlEncode(item.Remarks); } var dicQuery = new Dictionary(); + if (item.GetAllowInsecure()) + { + _insecureQueryKeys.ForEach(q => dicQuery.Add(q, "1")); + } if (!item.GetProtocolExtra().Flow.IsNullOrEmpty()) { dicQuery.Add("flow", item.GetProtocolExtra().Flow); diff --git a/v2rayN/ServiceLib/Handler/Fmt/TuicFmt.cs b/v2rayN/ServiceLib/Handler/Fmt/TuicFmt.cs index d1f802b0..4085cebc 100644 --- a/v2rayN/ServiceLib/Handler/Fmt/TuicFmt.cs +++ b/v2rayN/ServiceLib/Handler/Fmt/TuicFmt.cs @@ -30,6 +30,10 @@ public class TuicFmt : BaseFmt var query = Utils.ParseQueryString(url.Query); ResolveUriQuery(query, ref item); + if (GetQueryValue(query, "allow_insecure") == "1") + { + item.AllowInsecure = Global.StringTrue; + } item.SetProtocolExtra(item.GetProtocolExtra() with { CongestionControl = GetQueryValue(query, "congestion_control") @@ -53,7 +57,10 @@ public class TuicFmt : BaseFmt var dicQuery = new Dictionary(); ToUriQueryLite(item, ref dicQuery); - + if (item.GetAllowInsecure()) + { + dicQuery.Add("allow_insecure", "1"); + } if (!item.GetProtocolExtra().CongestionControl.IsNullOrEmpty()) { dicQuery.Add("congestion_control", item.GetProtocolExtra().CongestionControl);