Bug 36356 - HTTP proxy wildcard for no_proxy
Summary: HTTP proxy wildcard for no_proxy
Status: RESOLVED FIXED
Alias: None
Product: Class Libraries
Classification: Mono
Component: System (show other bugs)
Version: 4.2.0 (C6)
Hardware: PC Linux
: --- normal
Target Milestone: Untriaged
Assignee: Andi McClure
URL:
Depends on:
Blocks:
 
Reported: 2015-11-30 09:04 UTC by Christoph Brill
Modified: 2015-12-10 16:56 UTC (History)
2 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on GitHub or Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FIXED

Description Christoph Brill 2015-11-30 09:04:18 UTC
When setting the environment variable "no_proxy='localhost,127.0.0.0/8,::1,*.local'" I get the following exception:

System.TypeInitializationException: The type initializer for 'NuGet.ProxyCache' threw an exception. ---> System.ArgumentException: parsing '*.cgm.ag' - Quantifier {x,y} following nothing.
  at System.Text.RegularExpressions.RegexParser.ScanRegex () <0x4167b4a0 + 0x00633> in <filename unknown>:0 
  at System.Text.RegularExpressions.RegexParser.Parse (System.String re, RegexOptions op) <0x4167a340 + 0x000af> in <filename unknown>:0 
  at System.Text.RegularExpressions.Regex..ctor (System.String pattern, RegexOptions options, TimeSpan matchTimeout, Boolean useCache) <0x41679770 + 0x00227> in <filename unknown>:0 
  at System.Text.RegularExpressions.Regex..ctor (System.String pattern) <0x41679720 + 0x00033> in <filename unknown>:0 
  at System.Net.WebProxy.CheckBypassList () <0x416790e0 + 0x0007b> in <filename unknown>:0 
  at System.Net.WebProxy..ctor (System.Uri address, Boolean bypassOnLocal, System.String[] bypassList, ICredentials credentials) <0x41678b50 + 0x00103> in <filename unknown>:0 
  at System.Net.WebProxy..ctor (System.Uri address, Boolean bypassOnLocal, System.String[] bypassList) <0x41678b10 + 0x0002b> in <filename unknown>:0 
  at System.Net.WebRequest.GetSystemWebProxy () <0x4164e220 + 0x0083f> in <filename unknown>:0 
  at NuGet.ProxyCache..cctor () <0x4164bd10 + 0x0000b> in <filename unknown>:0 
  --- End of inner exception stack trace ---
  at NuGet.HttpClient.GetResponse () <0x4164bb10 + 0x00117> in <filename unknown>:0 
  at NuGet.RedirectedHttpClient.GetResponseUri (NuGet.HttpClient client) <0x4164b9e0 + 0x00029> in <filename unknown>:0 
  at NuGet.RedirectedHttpClient.EnsureClient () <0x4164b950 + 0x00047> in <filename unknown>:0 
  at System.Lazy`1[T].CreateValue () <0x415c8c20 + 0x001b7> in <filename unknown>:0 

This syntax is e.g. supported by the major browsers.
Comment 1 Christoph Brill 2015-11-30 09:08:07 UTC
Note that "*.cgm.ag" should be replaced by "*.local" in the stack trace.
Comment 2 Andi McClure 2015-12-07 19:37:01 UTC
Christoph's problem is that the no_proxy value for WebRequest is expecting regular expressions (as in, System.Text.RegularExpressions.Regex syntax) but Christoph reasonably expects to use fileglob syntax.

The no_proxy variable goes directly into the bypassList of a WebProxy. 

The bypassList is documented by https://msdn.microsoft.com/en-us/library/ms144293(v=vs.110).aspx to take "An array of regular expression strings". Our current implementation interprets that as a Regex. However, the sample code at that same MSDN URL gives ";*.Contoso.com" as an example of a bypass list member, which appears to be a glob expression and clearly not a Regex (what's up with the semicolon...?). Meanwhile our own WebRequest code seems to expect that the bypass list members are fileglobs, with System.Net.WebRequest special-casing "*.local".

Either WebRequest should be converting from fileglob to regex, or WebProxy should treat the bypass list members as fileglobs to start with.
Comment 3 Andi McClure 2015-12-07 19:59:54 UTC
Double-checked the reference sources, MS's implementation is definitely using Regex. So we are obliged to treat WebProxy as "correct" and fix WebRequest.

Checking Google suggests other people have run into this problem also http://stackoverflow.com/questions/30620652/nuget-on-mono-behind-proxy-not-able-to-connect-to-the-internet
Comment 4 Andi McClure 2015-12-07 20:32:51 UTC
Minimal test program

```
using System;
using System.Net;

namespace Test {
	class Program {
	    static void Main(string[] args) {
	    	Console.WriteLine("{0}", WebRequest.GetSystemWebProxy());
	    }
	}
}
```

Try invoking with
http_proxy="https://example.com" no_proxy="*.google.com" mono --debug Test.exe
on Linux (proxy env vars ignored on mac)
Comment 5 Andi McClure 2015-12-07 21:05:38 UTC
See https://github.com/mono/mono/pull/2296
Comment 6 Andi McClure 2015-12-10 16:56:55 UTC
Should be fixed as of 6ae64e4 (goes into Mono 4.4)