Django无法隐藏敏感变量

时间:2019-08-02 10:24:50

标签: python django python-3.x sentry

我已经将我的应用程序连接到Sentry,并且正在尝试检查是否可以防止敏感变量被记录下来。

这是我的代码:

   @sensitive_variables('user', 'pw', 'cc')
    def get(self, request):
        user = "foobar"
        raise Exception(f"{user}")


我的期望是根据文档:https://docs.djangoproject.com/en/2.2/howto/error-reporting/#filtering-sensitive-information

user的值替换为stars (**********)

但是,异常打印出了它的实际值-哨兵日志反映了这一点。

如何获取以星号代替敏感信息的值?

1 个答案:

答案 0 :(得分:1)

您可以configure Sentry隐藏某些字段/值,也可以定义filter function

import sentry_sdk

def strip_sensitive_data(event, hint):
    # modify event here
    return event

sentry_sdk.init(
    before_send=strip_sensitive_data
)

这将需要一些实验才能得到您想要的