network.py: do not require MyEncoder for serializing recent servers
What changed, and why it matters
This commit changes how Electrum saves its list of recently used Bitcoin servers to a small file on disk. Previously it used a custom helper class called MyEncoder; now it uses Python's simpler default=str option. The change is described by the developer as a cleanup to limit MyEncoder to wallet database code. There is no direct evidence in the commit that this fixes a security vulnerability, but switching serializers can in principle change how unusual data is written or read back.
Treat as a routine refactor unless independent review shows that MyEncoder enforced security-relevant constraints that default=str now bypasses. Reviewers should verify that _recent_servers contains only plain strings/tuples so that default=str is behaviorally equivalent and does not introduce unexpected serialization of objects. No immediate security response is warranted based solely on this commit.
Security signals we found
Serializer change: custom JSONEncoder replaced with default=str
File write of recently-used server list remains unchanged
No explicit security framing in commit message or diff
No references to CVEs, advisories, or researcher attribution in supplied materials
Evidence from the diff
In electrum/network.py the import of util.MyEncoder is removed and the serialization of self._recent_servers is changed from json.dumps(…, cls=MyEncoder) to json.dumps(…, default=str). MyEncoder is a custom JSONEncoder subclass; default=str is Python’s built-in fallback that stringifies any non-serializable object. The commit message frames this as a refactoring to restrict MyEncoder usage to wallet_db. The diff does not show any related input-validation, parsing, or file-handling changes.
Changed components
electrum/network.pyRecent-server list persistence (recent_servers file)Inspect captured patch +2 / −2
diff --git a/electrum/network.py b/electrum/network.py
index f1ce71f..fb60074 100644
--- a/electrum/network.py
+++ b/electrum/network.py
@@ -43,7 +43,7 @@ from aiohttp import ClientResponse
from . import util
from .util import (
- log_exceptions, ignore_exceptions, OldTaskGroup, make_aiohttp_session, MyEncoder,
+ log_exceptions, ignore_exceptions, OldTaskGroup, make_aiohttp_session,
NetworkRetryManager, error_text_str_to_safe_str, detect_tor_socks_proxy
)
from . import constants
@@ -471,7 +471,7 @@ class Network(Logger, NetworkRetryManager[ServerAddr]):
if not self.config.path:
return
path = os.path.join(self.config.path, "recent_servers")
- s = json.dumps(self._recent_servers, indent=4, sort_keys=True, cls=MyEncoder)
+ s = json.dumps(self._recent_servers, indent=4, sort_keys=True, default=str)
try:
with open(path, "w", encoding='utf-8') as f:
f.write(s)
Why this scored 11/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.