1
0

JsonDB: monkeypatch jsonpatch exceptions to avoid leaking secrets

closes https://github.com/spesmilo/electrum/issues/10001
This commit is contained in:
SomberNight
2025-07-14 12:13:46 +00:00
parent 78a7c85f49
commit 195d89a509
2 changed files with 98 additions and 0 deletions

View File

@@ -28,6 +28,7 @@ import json
from typing import TYPE_CHECKING, Optional, Sequence, List, Union
import jsonpatch
import jsonpointer
from . import util
from .util import WalletFileException, profiler
@@ -36,6 +37,15 @@ from .logging import Logger
if TYPE_CHECKING:
from .storage import WalletStorage
# We monkeypatch exceptions in the jsonpatch package to ensure they do not contain secrets from the DB.
# We often log exceptions and offer to send them to the crash reporter, so they must not contain secrets.
jsonpointer.JsonPointerException.__str__ = lambda self: """(JPE) 'redacted'"""
jsonpointer.JsonPointerException.__repr__ = lambda self: """<JsonPointerException 'redacted'>"""
jsonpatch.JsonPatchException.__str__ = lambda self: """(JPE) 'redacted'"""
jsonpatch.JsonPatchException.__repr__ = lambda self: """<JsonPatchException 'redacted'>"""
def modifier(func):
def wrapper(self, *args, **kwargs):
with self.lock: