Skip to content

Commit

Permalink
[common] Try to replace all sensitive data in logs
Browse files Browse the repository at this point in the history
  • Loading branch information
rixx committed Feb 22, 2019
1 parent 584c5d8 commit 1b112d4
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/pretalx/common/mixins/models.py
Expand Up @@ -3,6 +3,7 @@
from django.contrib.contenttypes.models import ContentType
from i18nfield.utils import I18nJSONEncoder

SENSITIVE_KEYS = ['password', 'secret', 'api_key']

class LogMixin:

Expand All @@ -11,8 +12,14 @@ def log_action(self, action, data=None, person=None, orga=False):
return

from pretalx.common.models import ActivityLog
if data and not isinstance(data, str):
if data and isinstance(data, dict):
for key, value in data.items():
if any(sensitive_key in key for sensitive_key in SENSITIVE_KEYS):
value = data[key]
data[key] = '********' if value else value
data = json.dumps(data, cls=I18nJSONEncoder)
elif data:
raise TypeError('Logged data should always be a dictionary.')

ActivityLog.objects.create(
event=getattr(self, 'event', None), person=person, content_object=self,
Expand Down

0 comments on commit 1b112d4

Please sign in to comment.