elazarl / goproxy

An HTTP proxy library for Go
BSD 3-Clause "New" or "Revised" License
6.06k stars 1.1k forks source link

IsLocalHost only works with default ports #487

Open mmatczuk opened 2 years ago

mmatczuk commented 2 years ago

It was originally observed in https://github.com/elazarl/goproxy/issues/289.

The IsLocalHost function uses req.URL.Host https://github.com/elazarl/goproxy/blob/a0805db90819b464f8fadc660e23a6a6b9d4942f/dispatcher.go#L105

It can be host or host:port. In the latter case the check simply does not work. It's not documented and it simply looks like a bug. It should be using the Hostname function instead.

mmatczuk commented 2 years ago

It seems this is not the only problem the var localHostIpv4 = regexp.MustCompile(127.0.0.\d+) matches everything that contains the 127.0.0. string say my127.0.0.foo.