Prune all sensitive data before sending it to Sentry

CURA-7245
This commit is contained in:
Nino van Hooff 2020-02-24 15:27:17 +01:00
parent e52dc56a64
commit 62dfadecdf
3 changed files with 23 additions and 10 deletions

View File

@ -32,6 +32,8 @@ from UM.Resources import Resources
from cura import ApplicationMetadata
catalog = i18nCatalog("cura")
home_dir = os.path.expanduser("~")
MYPY = False
if MYPY:
@ -83,6 +85,20 @@ class CrashHandler:
self.dialog = QDialog()
self._createDialog()
@staticmethod
def pruneSensitiveData(obj):
if type(obj) is list:
return [CrashHandler.pruneSensitiveData(item) for item in obj]
if type(obj) is dict:
return {k: CrashHandler.pruneSensitiveData(v) for k, v in obj.items()}
if type(obj) is str:
return obj.replace(home_dir, "<user_home>")
return obj
@staticmethod
def sentry_before_send(event, hint):
return CrashHandler.pruneSensitiveData(event)
def _createEarlyCrashDialog(self):
dialog = QDialog()
dialog.setMinimumWidth(500)

View File

@ -11,6 +11,7 @@ import sys
from UM.Platform import Platform
from cura import ApplicationMetadata
from cura.ApplicationMetadata import CuraAppName
from cura.CrashHandler import CrashHandler
try:
import sentry_sdk
@ -44,6 +45,7 @@ if with_sentry_sdk:
pass
sentry_sdk.init("https://5034bf0054fb4b889f82896326e79b13@sentry.io/1821564",
before_send = CrashHandler.sentry_before_send,
environment = sentry_env,
release = "cura%s" % ApplicationMetadata.CuraVersion,
default_integrations = False,

View File

@ -3,6 +3,9 @@
from UM.Logger import LogOutput
from typing import Set
from cura.CrashHandler import CrashHandler
try:
from sentry_sdk import add_breadcrumb
except ImportError:
@ -10,8 +13,6 @@ except ImportError:
from typing import Optional
import os
home_dir = os.path.expanduser("~")
class SentryLogger(LogOutput):
# Sentry (https://sentry.io) is the service that Cura uses for logging crashes. This logger ensures that the
@ -37,7 +38,7 @@ class SentryLogger(LogOutput):
# \param message String containing message to be logged
def log(self, log_type: str, message: str) -> None:
level = self._translateLogType(log_type)
message = self._pruneSensitiveData(message)
message = CrashHandler.pruneSensitiveData(message)
if level is None:
if message not in self._show_once:
level = self._translateLogType(log_type[0])
@ -47,12 +48,6 @@ class SentryLogger(LogOutput):
else:
add_breadcrumb(level = level, message = message)
@staticmethod
def _pruneSensitiveData(message):
if home_dir in message:
message = message.replace(home_dir, "<user_home>")
return message
@staticmethod
def _translateLogType(log_type: str) -> Optional[str]:
return SentryLogger._levels.get(log_type)