Skip to content

Commit 1e45851

Browse files
committed
Remove ENVIRONMENT_VARIABLE_IS_MULTIUSER_SAFE
This list is out of date. At least OpenBSD since 2013 does not allow one user to read the environment variables of a process run by another user. While we could try to keep the list updated, I think it's a bad idea to not use the user/password from the environment, even if another user on the system could read it. If http_proxy exists in the environment, and other users can read it, it doesn't make it more secure for Ruby to ignore it. You could argue that it encourages poor security practices, but net/http should provide mechanism, not policy. Fixes [Bug #18908]
1 parent 196f3d7 commit 1e45851

File tree

2 files changed

+6
-23
lines changed

2 files changed

+6
-23
lines changed

lib/net/http.rb

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1221,16 +1221,9 @@ def proxy_port
12211221
end
12221222
end
12231223

1224-
# [Bug #12921]
1225-
if /linux|freebsd|darwin/ =~ RUBY_PLATFORM
1226-
ENVIRONMENT_VARIABLE_IS_MULTIUSER_SAFE = true
1227-
else
1228-
ENVIRONMENT_VARIABLE_IS_MULTIUSER_SAFE = false
1229-
end
1230-
12311224
# The username of the proxy server, if one is configured.
12321225
def proxy_user
1233-
if ENVIRONMENT_VARIABLE_IS_MULTIUSER_SAFE && @proxy_from_env
1226+
if @proxy_from_env
12341227
user = proxy_uri&.user
12351228
unescape(user) if user
12361229
else
@@ -1240,7 +1233,7 @@ def proxy_user
12401233

12411234
# The password of the proxy server, if one is configured.
12421235
def proxy_pass
1243-
if ENVIRONMENT_VARIABLE_IS_MULTIUSER_SAFE && @proxy_from_env
1236+
if @proxy_from_env
12441237
pass = proxy_uri&.password
12451238
unescape(pass) if pass
12461239
else

test/net/http/test_http.rb

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -178,13 +178,8 @@ def test_proxy_eh_ENV_with_user
178178
http = Net::HTTP.new 'hostname.example'
179179

180180
assert_equal true, http.proxy?
181-
if Net::HTTP::ENVIRONMENT_VARIABLE_IS_MULTIUSER_SAFE
182-
assert_equal 'foo', http.proxy_user
183-
assert_equal 'bar', http.proxy_pass
184-
else
185-
assert_nil http.proxy_user
186-
assert_nil http.proxy_pass
187-
end
181+
assert_equal 'foo', http.proxy_user
182+
assert_equal 'bar', http.proxy_pass
188183
end
189184
end
190185

@@ -195,13 +190,8 @@ def test_proxy_eh_ENV_with_urlencoded_user
195190
http = Net::HTTP.new 'hostname.example'
196191

197192
assert_equal true, http.proxy?
198-
if Net::HTTP::ENVIRONMENT_VARIABLE_IS_MULTIUSER_SAFE
199-
assert_equal "Y\\X", http.proxy_user
200-
assert_equal "R%S] ?X", http.proxy_pass
201-
else
202-
assert_nil http.proxy_user
203-
assert_nil http.proxy_pass
204-
end
193+
assert_equal "Y\\X", http.proxy_user
194+
assert_equal "R%S] ?X", http.proxy_pass
205195
end
206196
end
207197

0 commit comments

Comments
 (0)