Skip to content

Commit 3ef63ee

Browse files
committed
handle payload json string to dict, type check
1 parent 2361acf commit 3ef63ee

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

auditmiddleware/_api.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -776,7 +776,26 @@ def _get_action_from_payload(self, request, res_spec, res_id):
776776
"""Determine the CADF action from the payload."""
777777
try:
778778
payload = request.json
779+
780+
# Handle case where payload is a string (JSON-encoded)
781+
if isinstance(payload, str):
782+
try:
783+
payload = json.loads(payload)
784+
except json.JSONDecodeError:
785+
self._log.warning(
786+
"Invalid JSON string payload for path: %s",
787+
request.path)
788+
return None
789+
779790
if payload:
791+
# Type checking for payload
792+
if not isinstance(payload, dict):
793+
self._log.warning(
794+
"Unexpected payload type %s for path: %s",
795+
type(payload), request.path
796+
)
797+
return None
798+
780799
rest_action = next(iter(payload))
781800
# check for individual mapping of action
782801
action = res_spec.custom_actions.get(rest_action)

0 commit comments

Comments
 (0)