Skip to content

Commit 778ee7c

Browse files
authored
[#3] Ensure valid json for header field values (#4)
fixes https://github.com/peppelinux/django-audit-wazuh/issues
1 parent 37ee8b3 commit 778ee7c

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

auditing/middlewares.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import http
22
import logging
33
import re
4+
import json
45

56
from django.conf import settings
67
try:
@@ -49,7 +50,12 @@ def process_response(self, request, response):
4950
response_headers = [(str(k), str(v)) for k, v in response.items()]
5051
for cookie in response.cookies.values():
5152
response_headers.append(('Set-Cookie', str(cookie.output(header=''))))
52-
head_items = ['"{}": "{}"'.format(*hea) for hea in response_headers]
53+
54+
head_items = [
55+
# Use json.dumps on value field below to ensure valid json
56+
'"{}": "{}"'.format(k, json.dumps(v))
57+
for k, v in response_headers
58+
]
5359
headers = ', '.join(head_items)
5460
_msg = '"Http Response", "method": "{}", "url": "{}", "status": "{}", {}'.format(request.method,
5561
request.build_absolute_uri(),

0 commit comments

Comments
 (0)