#Proxy broken with https due to scheme being empty

17 messages · Page 1 of 1 (latest)

tranquil sigil
#

I am writing a simple proxy that uses a random iPv6 from all available ones and it works fine with HTTP URLs, however if I try to request a https one, scheme becomes empty.

https://gist.github.com/Diniboy1123/fb934efc37ed9863d1d606d49f2cd53d#file-proxy-go-L108

In the highlighted line r.Host seems to be fine, but r.URL.Path and r.URL.Scheme is just empty. Even though I set something using curl -x "http://127.0.0.1:1337" https://cloudflare.com/cdn-cgi/trace.

#

I want it to work with both http and https urls. It should just forward the request as-is to and use the outbound address.

left junco
#

i think you might be misunderstanding curl's behavior—in the case of an HTTPS URL, it'll perform a CONNECT request rather than sending the request itself; this is setting up the forward proxy (not a reverse proxy).

#

the fact that you're using https in the request URL is telling curl that you want your request to use HTTPS—i.e. between you and the end server—not between the proxy server and the end server. there really isn't a standardized way to tell the proxy server to make an HTTPS request via a plaintext HTTP request, because, well…that kinda defeats the purpose of things.

#

if you want to do such a thing, you could perhaps use port numbers in the host string and go based on that, but you'd have to control the client in that situation. i don't think you can expect arbitrary HTTP clients to reach out over plaintext HTTP when they are given an HTTPS URL.

tranquil sigil
#

You are right. I want to recreate squid's behavior. That one is able to forward requests no matter if they are https or http urls. I am just not sure what is the right way to do so in Go

#

In fact I probably don't even want to parse the request curl makes, just pass it along as-is

left junco
#

i’m not familiar with what squid does, but are you sure that in the HTTPS case it’s not just passing along the bytes of the TLS stream, rather than the HTTP request?

tranquil sigil
#

Well if I do curl -x "http://127.0.0.1:1337" https://google.com/search with squid, it works as expected

#

(Assuming squid runs on port 1337)

left junco
#

i believe you, i just don’t know what it’s doing and therefore what you’re expecting. 🙂

tranquil sigil
#

It is probably passing bytes then

left junco
#

if the proxy is just forwarding the TLS stream it can’t read the request, unless it is doing some certificate shenanigans where the client trusts its root.

tranquil sigil
#

Actually no, it can't be doing that

#

Since it adds certain headers to the request

#

I will investigate further tomorrow