Skip to content

Instantly share code, notes, and snippets.

@balazs-endresz
Last active February 3, 2016 15:56
Show Gist options
  • Save balazs-endresz/2ec1b373c39949eaf875 to your computer and use it in GitHub Desktop.
Save balazs-endresz/2ec1b373c39949eaf875 to your computer and use it in GitHub Desktop.
Remove passwords from all stack traces
from django.views.debug import SafeExceptionReporterFilter, CLEANSED_SUBSTITUTE
class CustomExceptionReporterFilter(SafeExceptionReporterFilter):
""" Add this is to the settings:
DEFAULT_EXCEPTION_REPORTER_FILTER = 'path.to.CustomExceptionReporterFilter'
"""
def get_post_parameters(self, request):
post_parameters = super(CustomExceptionReporterFilter, self).get_post_parameters(request)
cleansed = post_parameters.copy()
for param in cleansed:
if 'password' in param.lower():
cleansed[param] = CLEANSED_SUBSTITUTE
return cleansed
def get_traceback_frame_variables(self, request, tb_frame):
variables = super(CustomExceptionReporterFilter, self).get_traceback_frame_variables(request, tb_frame)
cleansed = {}
for name, value in variables:
if 'password' in name.lower():
value = CLEANSED_SUBSTITUTE
cleansed[name] = value
return cleansed.items()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment