Skip to content

Commit 1c099a6

Browse files
committed
use safe_load when using Psych >= 3.1
see related sparklemotion/http-cookie#34
1 parent 4a0dfe5 commit 1c099a6

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

lib/mechanize/cookie_jar.rb

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ def load(input, *options)
149149
return super(input, opthash) if opthash[:format] != :yaml
150150

151151
begin
152-
data = YAML.load(input) # rubocop:disable Security/YAMLLoad
152+
data = load_yaml(input)
153153
rescue ArgumentError
154154
@logger.warn "unloadable YAML cookie data discarded" if @logger
155155
return self
@@ -174,6 +174,18 @@ def load(input, *options)
174174
return self
175175
end
176176
end
177+
178+
private
179+
180+
if YAML.name == "Psych" && Gem::Requirement.new(">= 3.1").satisfied_by?(Gem::Version.new(Psych::VERSION))
181+
def load_yaml(yaml)
182+
YAML.safe_load(yaml, aliases: true, permitted_classes: ["Mechanize::Cookie", "Time"])
183+
end
184+
else
185+
def load_yaml(yaml)
186+
YAML.load(yaml) # rubocop:disable Security/YAMLLoad
187+
end
188+
end
177189
end
178190

179191
class ::HTTP::CookieJar

0 commit comments

Comments
 (0)