Skip to content

Add spec for CVE-2020-10663 #764

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 23, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions security/cve_2020_10663_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
require_relative '../spec_helper'
require 'json'

module JSONSpecs
class MyClass
def initialize(foo)
@foo = foo
end

def self.json_create(hash)
new(*hash['args'])
end

def to_json(*args)
{ 'json_class' => self.class.name, 'args' => [ @foo ] }.to_json(*args)
end
end
end

guard -> {
ruby_version_is "2.4.10"..."2.5.0" or
ruby_version_is "2.5.8"..."2.6.0" or
ruby_version_is "2.6.6" or
JSON.const_defined?(:Pure) or
SpecVersion.new(JSON::VERSION) >= SpecVersion.new('2.3.0')
} do
describe "CVE-2020-10663 is resisted by" do
it "only creating custom objects if passed create_additions: true or using JSON.load" do
obj = JSONSpecs::MyClass.new("bar")
JSONSpecs::MyClass.json_creatable?.should == true
json = JSON.dump(obj)

JSON.parse(json, create_additions: true).class.should == JSONSpecs::MyClass
JSON(json, create_additions: true).class.should == JSONSpecs::MyClass
JSON.load(json).class.should == JSONSpecs::MyClass

JSON.parse(json).class.should == Hash
JSON.parse(json, nil).class.should == Hash
JSON(json).class.should == Hash
end
end
end