summaryrefslogtreecommitdiff
path: root/test/psych/test_string.rb
diff options
context:
space:
mode:
authorAaron Patterson <tenderlove@ruby-lang.org>2021-05-10 09:50:06 -0700
committerHiroshi SHIBATA <hsbt@ruby-lang.org>2021-05-17 11:20:45 +0900
commitc7c2ad5749f7f0767ef38be160f4b391228396c1 (patch)
tree38a9d1db4a3a5dd2f5efa3705c9f3be51ccadef5 /test/psych/test_string.rb
parentbcaa6aeceadd34eb6a0de1d55bf17ecb153a7916 (diff)
[ruby/psych] Introduce `Psych.unsafe_load`
In future versions of Psych, the `load` method will be mostly the same as the `safe_load` method. In other words, the `load` method won't allow arbitrary object deserialization (which can be used to escalate to an RCE). People that need to load *trusted* documents can use the `unsafe_load` method. This commit introduces the `unsafe_load` method so that people can incrementally upgrade. For example, if they try to upgrade to 4.0.0 and something breaks, they can downgrade, audit callsites, change to `safe_load` or `unsafe_load` as required, and then upgrade to 4.0.0 smoothly. https://github.com/ruby/psych/commit/cb50aa8d3f
Diffstat (limited to 'test/psych/test_string.rb')
-rw-r--r--test/psych/test_string.rb14
1 files changed, 7 insertions, 7 deletions
diff --git a/test/psych/test_string.rb b/test/psych/test_string.rb
index 973f38b9c2..20ab79c05a 100644
--- a/test/psych/test_string.rb
+++ b/test/psych/test_string.rb
@@ -104,7 +104,7 @@ module Psych
end
def test_string_subclass_with_anchor
- y = Psych.load <<-eoyml
+ y = Psych.unsafe_load <<-eoyml
---
body:
string: &70121654388580 !ruby/string
@@ -116,7 +116,7 @@ body:
end
def test_self_referential_string
- y = Psych.load <<-eoyml
+ y = Psych.unsafe_load <<-eoyml
---
string: &70121654388580 !ruby/string
str: ! 'foo'
@@ -129,32 +129,32 @@ string: &70121654388580 !ruby/string
end
def test_another_subclass_with_attributes
- y = Psych.load Psych.dump Y.new("foo").tap {|o| o.val = 1}
+ y = Psych.unsafe_load Psych.dump Y.new("foo").tap {|o| o.val = 1}
assert_equal "foo", y
assert_equal Y, y.class
assert_equal 1, y.val
end
def test_backwards_with_syck
- x = Psych.load "--- !str:#{X.name} foo\n\n"
+ x = Psych.unsafe_load "--- !str:#{X.name} foo\n\n"
assert_equal X, x.class
assert_equal 'foo', x
end
def test_empty_subclass
assert_match "!ruby/string:#{X}", Psych.dump(X.new)
- x = Psych.load Psych.dump X.new
+ x = Psych.unsafe_load Psych.dump X.new
assert_equal X, x.class
end
def test_empty_character_subclass
assert_match "!ruby/string:#{Z}", Psych.dump(Z.new)
- x = Psych.load Psych.dump Z.new
+ x = Psych.unsafe_load Psych.dump Z.new
assert_equal Z, x.class
end
def test_subclass_with_attributes
- y = Psych.load Psych.dump Y.new.tap {|o| o.val = 1}
+ y = Psych.unsafe_load Psych.dump Y.new.tap {|o| o.val = 1}
assert_equal Y, y.class
assert_equal 1, y.val
end