Skip to content

Commit

Permalink
fix: safe deserialisation of user-controlled data
Browse files Browse the repository at this point in the history
  • Loading branch information
kikkomep committed Nov 22, 2023
1 parent 750fcee commit b0a778a
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions lifemonitor/schemas/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,11 @@ def validate():
data = None
logger.debug("Request: data", request.data)
try:
data = yaml.unsafe_load(request.data)
data = yaml.safe_load(request.data)
except yaml.parser.ParserError:
data = json.loads(request.data.decode())
logger.debug("JSON data: %r", data)
data = json.loads(request.data.decode())
finally:
if not data:
raise BadRequestException(title="Invalid file format", detail="It should be a JSON or YAML file")
logger.debug("Data: %r", data)
logger.debug("JSON data to validate: %r", data)
return ConfigFileValidator.validate(data).to_dict()

0 comments on commit b0a778a

Please sign in to comment.