代码之家  ›  专栏  ›  技术社区  ›  nz_21

Django无法隐藏敏感变量

  •  0
  • nz_21  · 技术社区  · 6 年前

    我的代码是:

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

    我的期望是它将取代 user stars (**********) ,根据文件: https://docs.djangoproject.com/en/2.2/howto/error-reporting/#filtering-sensitive-information

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

    我如何让它用星星来代替敏感信息的价值?

    0 回复  |  直到 6 年前
        1
  •  1
  •   CowGoat Iain Shelvington    5 年前

    你也可以 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
    )
    

    这需要一点实验才能得到你想要的东西