chore(python): fix protocol_v1 probe for bridge transport
What changed, and why it matters
This is a bug-fix patch in the Python Trezor client library. It changes how the software probes whether a connected device uses the older protocol v1. Previously, the probe tried to read and throw away leftover data, but that read could accidentally disconnect the device when using Trezor Bridge (a browser-to-device communication path). The fix moves the cleanup into the transport layer and skips it entirely for Bridge transports, so connections no longer get dropped during detection.
Treat as a routine bug fix. No immediate security action required. Users relying on Bridge transport should update to benefit from improved connection reliability.
Security signals we found
No security-relevant signal in commit message or diff
Fix is described as a connectivity/functional bug, not a vulnerability
No mention of CVE, researcher credit, or security advisory
Change reduces side effects of probe (fewer session releases/USB resets), which could be considered a stability improvement
Evidence from the diff
The commit refactors protocol_v1.probe() to call a new Transport._discard_stale_packets() method instead of repeatedly calling read() with a short timeout. A default implementation drains up to 500 packets via read_chunk(timeout=0.1). The BridgeTransport overrides this as a no-op because a timed-out read on Bridge v2 releases the session and on Bridge v3 USB-resets the device. The changelog entry says ‘Fix connecting to a device through Trezor Bridge.’
Changed components
python/src/trezorlib/protocol_v1.pypython/src/trezorlib/transport/__init__.pypython/src/trezorlib/transport/bridge.pyInspect captured patch +18 / −12
### python/.changelog.d/8317.fixed
@@ -0,0 +1 @@
+Fix connecting to a device through Trezor Bridge.
### python/src/trezorlib/protocol_v1.py
@@ -29,7 +29,6 @@
from .log import DUMP_BYTES
from .thp import pairing
from .tools import enter_context
-from .transport import Timeout
if t.TYPE_CHECKING:
from .mapping import ProtobufMapping
@@ -348,19 +347,11 @@ def _read(self, session: SessionV1, timeout: float | None = None) -> MessageType
@enter_context
def probe(
- transport: Transport,
- *,
- mapping: ProtobufMapping = mapping.DEFAULT_MAPPING,
- retries: int = 10,
+ transport: Transport, *, mapping: ProtobufMapping = mapping.DEFAULT_MAPPING
) -> bool:
"""Probe the transport to see if it supports protocol v1."""
- for _ in range(retries):
- try:
- # skip stale responses (to prevent the device from blocking during sending)
- resp = read(transport, _ignore_bad_magic=True, timeout=0.1)
- LOG.debug("stale response: %s", resp)
- except Timeout:
- break
+ # skip stale responses (to prevent the device from blocking during sending)
+ transport._discard_stale_packets()
cancel_msg = messages.Cancel()
cancel_msg_type, cancel_msg_bytes = mapping.encode(cancel_msg)
write(transport, cancel_msg_type, cancel_msg_bytes)
### python/src/trezorlib/transport/__init__.py
@@ -155,6 +155,15 @@ def write_chunk(self, chunk: bytes, /) -> None:
def read_chunk(self, *, timeout: float | None = None) -> bytes:
raise NotImplementedError
+ def _discard_stale_packets(self) -> None:
+ max_stale_packets = 500
+ for _ in range(max_stale_packets):
+ try:
+ chunk = self.read_chunk(timeout=0.1)
+ except Timeout:
+ return
+ LOG.debug(f"stale packet: {chunk.hex()}")
+
def is_ready(self) -> bool:
return self.is_open()
### python/src/trezorlib/transport/bridge.py
@@ -195,5 +195,10 @@ def write_chunk(self, chunk: bytes, /) -> None:
def read_chunk(self, *, timeout: float | None = None) -> bytes:
return self.handle.read_buf(timeout=timeout)
+ def _discard_stale_packets(self) -> None:
+ # Bridge can't do a harmless timed read: aborting one releases the session
+ # (Bridge v2) or USB-resets the device (Bridge v3).
+ pass
+
def is_open(self) -> bool:
return self.session is not NoneWhy this scored 19/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.