SECURITY: use strict JSON parsing when parsing backup metadata

This commit is contained in:
Martin Brennan 2020-01-15 11:24:41 +01:00 committed by Régis Hanol
parent 5d75f90b27
commit c3cd2389fe
1 changed files with 10 additions and 2 deletions

View File

@ -19,6 +19,14 @@ module BackupRestore
def validate
metadata = extract_metadata
if metadata[:version].blank?
raise MetaDataError.new("Version not defined in metadata file.")
end
if !metadata[:version].is_a?(String) && !metadata[:version].is_a?(Integer)
raise MetaDataError.new("Version is not in a valid format.")
end
log "Validating metadata..."
log " Current version: #{@current_version}"
log " Restored version: #{metadata[:version]}"
@ -50,10 +58,10 @@ module BackupRestore
end
def load_metadata_file(path)
metadata = Oj.load_file(path, symbol_keys: true)
metadata = JSON.parse(File.read(path), symbolize_names: true)
raise MetaDataError.new("Failed to load metadata file.") if metadata.blank?
metadata
rescue Oj::ParseError
rescue JSON::ParserError
raise MetaDataError.new("Failed to parse metadata file.")
end
end