From 8a5e89e24b5fed3780855a3cad8a190496f3ad5e Mon Sep 17 00:00:00 2001 From: John Maynard Date: Wed, 1 Dec 2021 15:22:27 -0500 Subject: [PATCH] Switch Jinja2 environment for rendering before testing JSON to ImmutableSandboxedEnvironment Render Jinja template before checking for valid JSON --- awx/api/serializers.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/awx/api/serializers.py b/awx/api/serializers.py index 08503db45e..f5b3e87ecf 100644 --- a/awx/api/serializers.py +++ b/awx/api/serializers.py @@ -4480,7 +4480,10 @@ class NotificationTemplateSerializer(BaseSerializer): body = messages[event].get('body', {}) if body: try: - potential_body = json.loads(body) + rendered_body = ( + sandbox.ImmutableSandboxedEnvironment(undefined=DescriptiveUndefined).from_string(body).render(JobNotificationMixin.context_stub()) + ) + potential_body = json.loads(rendered_body) if not isinstance(potential_body, dict): error_list.append( _("Webhook body for '{}' should be a json dictionary. Found type '{}'.".format(event, type(potential_body).__name__))