From f11486e9a68475b4749520f4818ad25e38527d08 Mon Sep 17 00:00:00 2001 From: Yusuke Endoh Date: Sun, 29 Nov 2026 19:16:39 +0900 Subject: [PATCH] Clear proxy credentials when p_no_proxy excludes the host Net::HTTP.new dropped the proxy address and port when the host matched p_no_proxy, but kept p_user and p_pass, so the request to the host still carried a Proxy-Authorization header. Clear them as well, as is already the case when the proxy comes from the environment. Reported-by: Claude (Anthropic) and Stephan Lipp (Ada Logics) Co-Authored-By: Claude Opus 5.5 --- lib/net/http.rb | 2 ++ test/net/http/test_http.rb | 12 ++++++++++++ 2 files changed, 14 insertions(+) diff --git a/lib/net/http.rb b/lib/net/http.rb index 09b898db..d0018cab 100644 --- a/lib/net/http.rb +++ b/lib/net/http.rb @@ -1116,6 +1116,8 @@ def HTTP.new(address, port = nil, p_addr = :ENV, p_port = nil, p_user = nil, p_p if p_addr && p_no_proxy && !URI::Generic.use_proxy?(address, address, port, p_no_proxy) p_addr = nil p_port = nil + p_user = nil + p_pass = nil end http.proxy_address = p_addr http.proxy_port = p_port || default_port diff --git a/test/net/http/test_http.rb b/test/net/http/test_http.rb index 5cccb06e..83ed3345 100644 --- a/test/net/http/test_http.rb +++ b/test/net/http/test_http.rb @@ -134,6 +134,18 @@ def test_proxy_address_no_proxy end end + def test_proxy_user_no_proxy + TestNetHTTPUtils.clean_http_proxy_env do + http = Net::HTTP.new 'hostname.example', nil, 'proxy.com', nil, 'user', 'pass', 'example' + assert_nil http.proxy_user + assert_nil http.proxy_pass + + http = Net::HTTP.new 'hostname.other', nil, 'proxy.com', nil, 'user', 'pass', 'example' + assert_equal 'user', http.proxy_user + assert_equal 'pass', http.proxy_pass + end + end + def test_proxy_from_env_ENV TestNetHTTPUtils.clean_http_proxy_env do ENV['http_proxy'] = 'http://proxy.example:8000'