ngx_http_proxy_connect_module icon indicating copy to clipboard operation
ngx_http_proxy_connect_module copied to clipboard

Basic Auth and Proxy Connect

Open stremovsky opened this issue 3 years ago • 1 comments

Hi guys

The NGINX proxy_connect module is not working with basic auth.

Example:

http {
  server {
    proxy_connect;
    proxy_connect_timeout         60s;

    location / {
      auth_basic "User auth";
      auth_basic_user_file /etc/nginx/passwords;
      proxy_http_version 1.1;
    }
  }
}

This command returns my IP address (without AUTH): curl --proxy http://proxy:port https://ifcfg.co/.

This command is blocked as expected: curl --proxy http://127.0.0.1:1441 http://ifcfg.co/. I am getting: "401 Authorization Required"

stremovsky avatar Nov 25 '21 09:11 stremovsky

The request from ur command curl is http request. This request is not handled by this module. It is handled by original nginx module( http & http auth). Because ur request has no info of authorization, nginx http auth module refused it.

chobits avatar Jan 28 '22 04:01 chobits

I've the same problem, tried as well

curl --proxy "http://${IP}:${PORT}" --proxy-user 'user:pass' ...

This helped https://github.com/chobits/ngx_http_proxy_connect_module/issues/42#issuecomment-502985437 but I used lua script modification https://github.com/chobits/ngx_http_proxy_connect_module/issues/42#issuecomment-820856840

bd-spl avatar Feb 10 '23 10:02 bd-spl

I've the same problem, Nginx 1.24.0 Problem should position in rewrite_by_lua_file /usr/local/nginx/conf/proxy_auth.lua; because i comment it, the nignx server will work normally.

cat /usr/local/nginx/conf/proxy_auth.lua -- check Proxy-Authorization for https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/407 if not ngx.var.http_proxy_authorization then ngx.header["Proxy-Authenticate"] = "Basic realm="Access to internal site"" ngx.exit(407) end

-- transfer Proxy-Authorization header to Authorization for auth basic module ngx.req.set_header("Authorization", ngx.var.http_proxy_authorization)

grayguest avatar May 26 '23 14:05 grayguest

I've the same problem, Nginx 1.24.0 Problem should position in rewrite_by_lua_file /usr/local/nginx/conf/proxy_auth.lua; because i comment it, the nignx server will work normally.

cat /usr/local/nginx/conf/proxy_auth.lua -- check Proxy-Authorization for https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/407 if not ngx.var.http_proxy_authorization then ngx.header["Proxy-Authenticate"] = "Basic realm="Access to internal site"" ngx.exit(407) end

-- transfer Proxy-Authorization header to Authorization for auth basic module ngx.req.set_header("Authorization", ngx.var.http_proxy_authorization)

Solved,Need nginx_lua_module support, i am newer so stupid

grayguest avatar May 27 '23 09:05 grayguest