Skip to content

Commit 023eb52

Browse files
committed
Add spec for CVE-2020-10663
1 parent 3eb6dc0 commit 023eb52

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

security/cve_2020_10663_spec.rb

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
require_relative '../spec_helper'
2+
require 'json'
3+
4+
module JSONSpecs
5+
class MyClass
6+
def initialize(foo)
7+
@foo = foo
8+
end
9+
10+
def self.json_create(hash)
11+
new(*hash['args'])
12+
end
13+
14+
def to_json(*args)
15+
{ 'json_class' => self.class.name, 'args' => [ @foo ] }.to_json(*args)
16+
end
17+
end
18+
end
19+
20+
guard -> {
21+
ruby_version_is "2.4.10"..."2.5.0" or
22+
ruby_version_is "2.5.8"..."2.6.0" or
23+
ruby_version_is "2.6.6" or
24+
JSON.const_defined?(:Pure) or
25+
SpecVersion.new(JSON::VERSION) >= SpecVersion.new('2.3.0')
26+
} do
27+
describe "CVE-2020-10663 is resisted by" do
28+
it "only creating custom objects if passed create_additions: true or using JSON.load" do
29+
obj = JSONSpecs::MyClass.new("bar")
30+
JSONSpecs::MyClass.json_creatable?.should == true
31+
json = JSON.dump(obj)
32+
33+
JSON.parse(json, create_additions: true).class.should == JSONSpecs::MyClass
34+
JSON(json, create_additions: true).class.should == JSONSpecs::MyClass
35+
JSON.load(json).class.should == JSONSpecs::MyClass
36+
37+
JSON.parse(json).class.should == Hash
38+
JSON.parse(json, nil).class.should == Hash
39+
JSON(json).class.should == Hash
40+
end
41+
end
42+
end

0 commit comments

Comments
 (0)