Skip to content

Commit

Permalink
Fix possible Unsafe Object Deserialization Vulnerability in gem owner
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonathan Claudius authored and segiddins committed Feb 16, 2018
1 parent 92e98bf commit 254e3d0
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/rubygems/commands/owner_command.rb
Expand Up @@ -64,7 +64,7 @@ def show_owners name
end

with_response response do |resp|
owners = YAML.load resp.body
owners = Gem::SafeYAML.load resp.body

say "Owners for gem: #{name}"
owners.each do |owner|
Expand Down
28 changes: 28 additions & 0 deletions test/rubygems/test_gem_commands_owner_command.rb
Expand Up @@ -2,6 +2,9 @@
require 'rubygems/test_case'
require 'rubygems/commands/owner_command'

class Foo
end

class TestGemCommandsOwnerCommand < Gem::TestCase

def setup
Expand Down Expand Up @@ -43,6 +46,31 @@ def test_show_owners
assert_match %r{- 4}, @ui.output
end

def test_show_owners_dont_load_objects
skip "testing a psych-only API" unless defined?(::Psych::DisallowedClass)

response = <<EOF
---
- email: !ruby/object:Foo {}
id: 1
handle: user1
- email: user2@example.com
- id: 3
handle: user3
- id: 4
EOF

@fetcher.data["#{Gem.host}/api/v1/gems/freewill/owners.yaml"] = [response, 200, 'OK']

assert_raises Psych::DisallowedClass do
use_ui @ui do
@cmd.show_owners("freewill")
end
end

end


def test_show_owners_setting_up_host_through_env_var
response = "- email: user1@example.com\n"
host = "http://rubygems.example"
Expand Down

0 comments on commit 254e3d0

Please sign in to comment.