File tree 1 file changed +42
-0
lines changed
1 file changed +42
-0
lines changed Original file line number Diff line number Diff line change
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
You can’t perform that action at this time.
0 commit comments