Skip to content

Commit

Permalink
use safe_load when using Psych >= 3.1
Browse files Browse the repository at this point in the history
  • Loading branch information
flavorjones committed Jan 17, 2022
1 parent 4a0dfe5 commit 1c099a6
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion lib/mechanize/cookie_jar.rb
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ def load(input, *options)
return super(input, opthash) if opthash[:format] != :yaml

begin
data = YAML.load(input) # rubocop:disable Security/YAMLLoad
data = load_yaml(input)
rescue ArgumentError
@logger.warn "unloadable YAML cookie data discarded" if @logger
return self
Expand All @@ -174,6 +174,18 @@ def load(input, *options)
return self
end
end

private

if YAML.name == "Psych" && Gem::Requirement.new(">= 3.1").satisfied_by?(Gem::Version.new(Psych::VERSION))
def load_yaml(yaml)
YAML.safe_load(yaml, aliases: true, permitted_classes: ["Mechanize::Cookie", "Time"])
end
else
def load_yaml(yaml)
YAML.load(yaml) # rubocop:disable Security/YAMLLoad
end
end
end

class ::HTTP::CookieJar
Expand Down

0 comments on commit 1c099a6

Please sign in to comment.