Skip to content

Commit

Permalink
Fixed vulnerability issue
Browse files Browse the repository at this point in the history
  • Loading branch information
Dev authored and Dev committed May 22, 2024
1 parent 37e183a commit dc793b3
Showing 1 changed file with 17 additions and 16 deletions.
33 changes: 17 additions & 16 deletions lib/money/bank/variable_exchange.rb
Original file line number Diff line number Diff line change
Expand Up @@ -259,25 +259,26 @@ def rates
# bank.get_rate("USD", "CAD") #=> 1.24515
# bank.get_rate("CAD", "USD") #=> 0.803115
def import_rates(format, s, opts = {})
raise Money::Bank::UnknownRateFormat unless RATE_FORMATS.include?(format)

if format == :ruby
warn '[WARNING] Using :ruby format when importing rates is potentially unsafe and ' \
'might lead to remote code execution via Marshal.load deserializer. Consider using ' \
'safe alternatives such as :json and :yaml.'
raise Money::bank::UnknownRateFormat unless RATE_FORMATS.include?(format)

store.transaction do
data = case format
when :json
JSON.parse(s)
when :yaml
YAML.safe_load(s, permitted_classes: [BigDecimal, Date, Time], aliases: true)
else
raise Money::bank::UnknownRateFormat, "Unknown format: #{format}"
end

store.transaction do
data = FORMAT_SERIALIZERS[format].load(s)

data.each do |key, rate|
from, to = key.split(SERIALIZER_SEPARATOR)
store.add_rate from, to, rate
end

data.each do |key, rate|
from, to = key.split(SERIALIZER_SEPARATOR)
store.add_rate from, to, rate
end

self
end

self
end
end
end
end

0 comments on commit dc793b3

Please sign in to comment.