Skip to content

Commit 4f51f62

Browse files
tenderlovematzbot
authored andcommitted
[rubygems/rubygems] Restrict what schemes are acceptable in the remote fetcher
The remote fetcher only works with certain schemes (`http`, `https`, `s3`, and `file`). It's possible for other schemes to show up in this code and it can cause bugs. Before this patch, doing `gem install path:///hello` would result in an infinite loop because this function would do `send "fetch_path"`, calling itself forever. Now we see an exception. I think we should validate gem names earlier, but it's really best practice to restrict the possible strings passed to `send`. ruby/rubygems@54e2781b73
1 parent 9a80258 commit 4f51f62

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

lib/rubygems/remote_fetcher.rb

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -245,11 +245,14 @@ def fetch_http(uri, last_modified = nil, head = false, depth = 0)
245245
def fetch_path(uri, mtime = nil, head = false)
246246
uri = Gem::Uri.new uri
247247

248-
unless uri.scheme
249-
raise ArgumentError, "uri scheme is invalid: #{uri.scheme.inspect}"
250-
end
251-
252-
data = send "fetch_#{uri.scheme}", uri, mtime, head
248+
method = {
249+
"http" => "fetch_http",
250+
"https" => "fetch_http",
251+
"s3" => "fetch_s3",
252+
"file" => "fetch_file",
253+
}.fetch(uri.scheme) { raise ArgumentError, "uri scheme is invalid: #{uri.scheme.inspect}" }
254+
255+
data = send method, uri, mtime, head
253256

254257
if data && !head && uri.to_s.end_with?(".gz")
255258
begin

0 commit comments

Comments
 (0)