Skip to content

Commit

Permalink
Merge pull request #589 from sparklemotion/flavorjones-use-psych-safe…
Browse files Browse the repository at this point in the history
…-load

use safe_load when using Psych >= 3.1
  • Loading branch information
flavorjones committed Jan 17, 2022
2 parents 4a0dfe5 + 1c099a6 commit ec9af73
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 ec9af73

Please sign in to comment.