Replace yaml.load() with yaml.safe_load()

Avoid dangerous file parsing and object serialization libraries.
yaml.load is the obvious function to use but it is dangerous[1]
Because yaml.load return Python object may be dangerous if you
receive a YAML document from an untrusted source such as the
Internet. The function yaml.safe_load limits this ability to
simple Python objects like integers or lists.

In addition, Bandit flags yaml.load() as security risk so replace
all occurrences with yaml.safe_load(). Thus I replace yaml.load()
with yaml.safe_load()

[1]https://security.openstack.org/guidelines/dg_avoid-dangerous-input-parsing-libraries.html

Change-Id: Id83e2a28355ba09cf22ea4e422de9b39e4f03c5e
Closes-Bug: #1634265
This commit is contained in:
Luong Anh Tuan 2017-01-16 16:03:54 +07:00 committed by Tuan Luong-Anh
parent 22d0209471
commit a2c1d16fe6
2 changed files with 3 additions and 3 deletions

View File

@ -71,7 +71,7 @@ class DeployOvercloud(command.Command):
# Update parameters from answers file:
if args.answers_file is not None:
with open(args.answers_file, 'r') as answers_file:
answers = yaml.load(answers_file)
answers = yaml.safe_load(answers_file)
if args.templates is None:
args.templates = answers['templates']

View File

@ -43,7 +43,7 @@ class ValidateOvercloudNetenv(command.Command):
self.log.debug("take_action(%s)" % parsed_args)
with open(parsed_args.netenv, 'r') as net_file:
network_data = yaml.load(net_file)
network_data = yaml.safe_load(net_file)
cidrinfo = {}
poolsinfo = {}
@ -162,7 +162,7 @@ class ValidateOvercloudNetenv(command.Command):
def NIC_validate(self, resource, path):
try:
with open(path, 'r') as nic_file:
nic_data = yaml.load(nic_file)
nic_data = yaml.safe_load(nic_file)
except IOError:
self.log.error(
'The resource "%s" reference file does not exist: "%s"',