mirror of
https://github.com/ansible/awx.git
synced 2026-03-04 10:11:05 -03:30
prohibit API payloads that represent something other than a JSON object
The JSON serializer for our API uses ``json.loads``, which permits *any* valid JSON (including bare integers, boolean values, etc). Lots of our code, however, assumes that inbound JSON content will be a dict. see: #4756
This commit is contained in:
@@ -26,6 +26,9 @@ class JSONParser(parsers.JSONParser):
|
||||
|
||||
try:
|
||||
data = stream.read().decode(encoding)
|
||||
return json.loads(data, object_pairs_hook=OrderedDict)
|
||||
obj = json.loads(data, object_pairs_hook=OrderedDict)
|
||||
if not isinstance(obj, dict):
|
||||
raise ParseError(_('JSON parse error - not a JSON object'))
|
||||
return obj
|
||||
except ValueError as exc:
|
||||
raise ParseError(_('JSON parse error - %s') % six.text_type(exc))
|
||||
|
||||
Reference in New Issue
Block a user