lnworker: add type assert to get_channel_by_short_id
What changed, and why it matters
This commit adds a safety check to a Lightning Network function so it refuses to accept an empty or wrong-type channel identifier. The change is defensive: it turns a silent 'no match found' return value into an immediate crash if a caller accidentally passes an invalid identifier. There is no direct evidence in the commit that this fixes an active security vulnerability or real-world exploit.
Treat as a minor hardening change. Review all call sites of get_channel_by_short_id to confirm none rely on the previous silent None-return behavior, and consider whether the assert should be a typed exception for production robustness.
Security signals we found
Defensive type assertion added to prevent accidental None propagation
Function handles Lightning short channel IDs, which are security-sensitive identifiers
Commit message describes intent as accident prevention, not security bug fix
Evidence from the diff
In electrum/lnworker.py, get_channel_by_short_id() now asserts that short_channel_id is truthy and is a bytes object. Previously, if a caller passed None (for example, when channel.short_id was not yet populated), the function would iterate channels, find no match, and return None. The new assert makes such programming errors fail fast rather than propagate a None result. The commit message frames this as preventing accidental misuse, not as a vulnerability fix.
Changed components
electrum/lnworker.pyLNWallet.get_channel_by_short_idInspect captured patch +1 / −0
diff --git a/electrum/lnworker.py b/electrum/lnworker.py
index c49aa3d..f28c99a 100644
--- a/electrum/lnworker.py
+++ b/electrum/lnworker.py
@@ -1574,6 +1574,7 @@ class LNWallet(LNWorker):
return chan, funding_tx
def get_channel_by_short_id(self, short_channel_id: bytes) -> Optional[Channel]:
+ assert short_channel_id and isinstance(short_channel_id, bytes), repr(short_channel_id)
# First check against *real* SCIDs.
# This e.g. protects against maliciously chosen SCID aliases, and accidental collisions.
for chan in self.channels.values():
Why this scored 29/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.