Coverage for website/utils/exception_filter.py: 22.73%

16 statements  

« prev     ^ index     » next       coverage.py v7.6.7, created at 2025-08-14 10:31 +0000

1import logging 

2 

3from django.views.debug import SafeExceptionReporterFilter 

4 

5__LOGGER = logging.getLogger(__name__) 

6 

7 

8class ThaliaSafeExceptionReporterFilter(SafeExceptionReporterFilter): 

9 """Filter additional variables from tracebacks. 

10 

11 https://docs.djangoproject.com/en/2.0/howto/error-reporting/#filtering-sensitive-information 

12 """ 

13 

14 def get_traceback_frame_variables(self, request, tb_frame): 

15 """Filter traceback frame variables.""" 

16 local_vars = super().get_traceback_frame_variables(request, tb_frame) 

17 

18 if self.is_active(request): 

19 for name, val in local_vars: 

20 if name == "request": 

21 try: 

22 val.COOKIES = {"cookies have been cleaned": True} 

23 val.META["HTTP_COOKIE"] = ( 

24 SafeExceptionReporterFilter.cleansed_substitute 

25 ) 

26 val.META["HTTP_AUTHORIZATION"] = ( 

27 SafeExceptionReporterFilter.cleansed_substitute 

28 ) 

29 except (AttributeError, IndexError): 

30 __LOGGER.exception("Somehow cleaning the request failed") 

31 

32 return local_vars