From 6aeb17327484de7bc62fa5e83abb57e5ec04f720 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Sat, 29 Aug 2026 10:05:09 +0000 Subject: [PATCH] Fix NO_PROXY wildcard bypass entries not matching subdomains Root cause: envProxies() built the bypass regex by first calling Regex.Escape on the entire NO_PROXY string, then attempting to replace literal '*' with '.*'. But Regex.Escape had already turned '*' into the literal sequence '\*', so the later .Replace("*", ".*") matched nothing and wildcard entries like '*.internal.company.com' were passed through as a useless escaped literal pattern that could never match any host, causing the proxy to always be used even when it should have been bypassed. Fix: split each NO_PROXY entry on '*', Regex.Escape only the literal segments, and rejoin with '.*', producing a valid regex consistent with WebProxy.BypassList semantics. Closes #3548 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- src/Paket.Core/Common/NetUtils.fs | 16 ++++++++++++---- tests/Paket.Tests/UtilsSpecs.fs | 18 +++++++++++++++++- 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/src/Paket.Core/Common/NetUtils.fs b/src/Paket.Core/Common/NetUtils.fs index 7c5ee49abe..a131e31b35 100644 --- a/src/Paket.Core/Common/NetUtils.fs +++ b/src/Paket.Core/Common/NetUtils.fs @@ -76,10 +76,18 @@ let envProxies () = if isNull v then Environment.GetEnvironmentVariable(name.ToLowerInvariant()) else v let bypassList = let noproxyString = getEnvValue "NO_PROXY" - let noproxy = if not (String.IsNullOrEmpty noproxyString) then System.Text.RegularExpressions.Regex.Escape(noproxyString).Replace(@"*", ".*") else noproxyString - - if String.IsNullOrEmpty noproxy then [||] else - noproxy.Split([| ',' |], StringSplitOptions.RemoveEmptyEntries) + if String.IsNullOrEmpty noproxyString then [||] else + // Each comma-separated entry may contain '*' as a wildcard. We escape the entry as a + // regex, but must treat '*' specially: escaping the whole string first (as was done + // previously) turns '*' into the literal '\*', so a later ".Replace(\"*\", \".*\")" has + // no effect and wildcard bypass entries (e.g. "*.internal.company.com") never match. + // Instead, split on '*', escape each literal segment, and re-join with ".*". + let escapeWithWildcard (entry:string) = + entry.Split('*') + |> Array.map System.Text.RegularExpressions.Regex.Escape + |> String.concat ".*" + noproxyString.Split([| ',' |], StringSplitOptions.RemoveEmptyEntries) + |> Array.map escapeWithWildcard let getCredentials (uri:Uri) = let userPass = uri.UserInfo.Split([| ':' |], 2) if userPass.Length <> 2 || userPass.[0].Length = 0 then None else diff --git a/tests/Paket.Tests/UtilsSpecs.fs b/tests/Paket.Tests/UtilsSpecs.fs index 93872fa63c..d878d6e781 100644 --- a/tests/Paket.Tests/UtilsSpecs.fs +++ b/tests/Paket.Tests/UtilsSpecs.fs @@ -297,10 +297,26 @@ let ``get http env proxy with bypass list containing wildcards``() = p.BypassList.Length |> shouldEqual 3 p.BypassList.[0] |> shouldEqual "\\.local" p.BypassList.[1] |> shouldEqual "localhost" - p.BypassList.[2] |> shouldEqual "\\.*\\.asdf\\.com" + p.BypassList.[2] |> shouldEqual ".*\\.asdf\\.com" #endif p.Credentials |> shouldEqual null +[] +let ``no_proxy wildcard bypass entry actually bypasses matching subdomain``() = + use v = new DisposableEnvVar("http_proxy", "http://proxy.local:8080") + use w = new DisposableEnvVar("no_proxy", "*.internal.company.com") + let pOpt = envProxies().TryFind "http" + Option.isSome pOpt |> shouldEqual true + let p = Option.get pOpt +#if WEBPROXY_NETSTANDARD + ignore p //TODO readd check +#else + // were escaped incorrectly and therefore never matched any host, even though they should + // bypass the proxy for matching subdomains. + p.IsBypassed(new Uri("http://nuget.internal.company.com")) |> shouldEqual true + p.IsBypassed(new Uri("http://example.com")) |> shouldEqual false +#endif + [] let ``should simplify path``() = let p0 = "/Users/dna/Downloads/test/aa/src/bb"