luasocket icon indicating copy to clipboard operation
luasocket copied to clipboard

Requesting HTTPS over an HTTP proxy doesn't work

Open Max1Truc opened this issue 3 years ago • 5 comments

When requesting an HTTPS url over an HTTP proxy, LuaSocket tries to initiate a TLS session with the proxy server.

This works with mitmproxy, but not with other proxies.

Is it intended behavior ?

Otherwise, I can submit a PR to use the HTTP create function when an HTTP proxy is used.

Max1Truc avatar Aug 23 '22 06:08 Max1Truc

I don't have much time to research the current or correct behavior, but will help facilitate a PR if one comes. From reading the issue at least that situation does sound like a bug.

alerque avatar Aug 23 '22 06:08 alerque

It seems to me most clients requesting HTTPS over an HTTP proxy would simply ask for a TCP tunnel with CONNECT.

However, doing a GET https://[...], like for HTTP over an HTTP proxy, works on the proxies I tested.

I'm going to send the snippet that doesn't work later.

As to the PR, I'm working on it.

Max1Truc avatar Aug 23 '22 07:08 Max1Truc

for inspiration; lua-resty-http does include proxy support; https://github.com/ledgetech/lua-resty-http

Tieske avatar Aug 23 '22 07:08 Tieske

Thanks for the insiration.

Some features lua-resty-http supports:

  • Proxied HTTP is requested with a request like GET http://... while proxied HTTPS is requested with a CONNECT host:port
  • Two different proxy settings when proxying HTTP or HTTPS
  • A no_proxy setting, to specify which hosts shouldn't be reached over a proxy

For now, I do not intend to provide any of these features in the PR.

It seems sufficient to send a GET https://... to the proxy server. I just read the RFCs and it seems this does not break the specifications, but don't take my word for it.

I'll also test this against some proxies I find to check if this works in practice.

Max1Truc avatar Aug 23 '22 08:08 Max1Truc

Should I add back the proxy tests ? (in test/httptest.lua)

Max1Truc avatar Aug 23 '22 13:08 Max1Truc