我试图使用Django的@sensitive_post_parameters过滤掉敏感信息。我认为在这些注释之前加上几个特定的字体就足够了,但是它不起作用。我在SafeExceptionReporterFilter中设置了断点,它只在从AdminEmailHandler和调用时中断,而不是在其他处理程序调用时中断。我错过了什么?
发布于 2015-04-23 15:01:35
即使使用SafeExceptionReporterFilter,异常仍将包含敏感数据(例如服务器的ENV变量和其他运行时数据)。
若要避免公开敏感数据,请不要使用此筛选器。相反,编写自己的异常处理程序中间件并有选择地(递归地?)在日志中获取您想要的数据。
有关如何获取异常的跟踪以及如何将其用于您的需要,请参见sys.exc_info。
即使您使用CustomHandler,您也会受到特定处理程序的限制,据我所知,第三方处理程序不会使用SafeExceptionReporterFilter。
发布于 2015-04-21 18:18:47
您可以编写一个自定义处理程序,它使用django.views.debug.ExceptionReporter来格式化异常。
ExceptionReporter的示例使用
from django.views.debug import ExceptionReporter
# exc_type, exc_value, traceback are a standard exception
# tuple as returned by sys.exc_info
reporter = ExceptionReporter(request, exc_type, exc_value, traceback)
html_report = reporter.get_traceback_html()
text_report = reporter.get_traceback_text()ExceptionReporter将使用DEFAULT_EXCEPTION_REPORTER_FILTER设置定义的ExceptionReporterFilter,默认情况下是SafeExceptionReporterFilter。
查看一下AdminEmailHandler的实现,了解如何创建自定义Handler。
https://stackoverflow.com/questions/29679391
复制相似问题