2015-04-16 39 views
7

我试图用Django的@sensitive_post_parameters来过滤敏感信息。我认为把这些注释放在少数特定的功能上就足够了,但它不起作用。我在SafeExceptionReporterFilter里面设置了断点,它只在被其他处理程序从AdminEmailHandler而不是被调用时才会中断。我错过了什么?是否有可能使用Django的SafeExceptionReporterFilter而不是AdminEmailHandler?

+0

您是否设置了'DEBUG = False'? – spg

+0

很明显,但谢谢你指出。 –

回答

1

即使您使用SafeExceptionReporterFilter,异常仍会包含敏感数据(例如您的服务器的ENV变量和其他运行时数据)。

为避免暴露敏感数据,您不应该使用此过滤器。相反,编写自己的异常处理程序中间件并有选择地(递归地?)自己获取日志中需要的数据。

请参阅sys.exc_info了解如何获取异常的回溯以及如何根据需要使用它。

即使您使用CustomHandler,您也会受到特定处理程序的限制,并且据我所知,第三方处理程序不会使用SafeExceptionReporterFilter

+0

事实上,我的确尝试创建一个自定义处理程序,就像@aumo建议的那样,但它基于graypy GELF处理程序,并且无法在不重写整个事物的情况下添加筛选。至于敏感的运行时数据,我知道安全人员不会让我登录它们。我想我会继续写下我自己的异常记录器中间件,因为这是我可以控制信息披露的唯一方式。谢谢 ! –

2

您可以编写自定义Handler,使用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设置在缺省情况下是SafeExceptionReporterFilter定义的ExceptionReporterFilter

查看AdminEmailHandlerimplementation以获取有关如何创建自定义Handler的信息。

相关问题