chore(core): avoid THP encryption if sending is not allowed
What changed, and why it matters
This commit adds a safety check in the Trezor hardware wallet's code that handles a newer USB protocol (THP). Before encrypting and sending a message, it now asserts that the protocol state allows sending. The change is defensive and small, but the commit message implies there was a path where encryption could happen when sending was not allowed. Without more context, it is unclear whether this closes a real security bug or is just hardening.
Treat as a hardening commit pending further review. Trezor should confirm whether any reachable code path could trigger the assertion, and if so, whether the resulting exception is handled safely. Users do not need to take action unless the vendor issues an advisory.
Security signals we found
Defensive assertion added to enforce state-machine invariant before encryption
Commit wording ('avoid THP encryption if sending is not allowed') suggests a possible state-machine inconsistency
No changelog entry, reducing public visibility of the change
Change is in THP wire/channel layer, which is security-critical for host-device communication
Evidence from the diff
In core/src/trezor/wire/thp/channel.py, the write_message() method now calls assert ABP.is_sending_allowed(self.channel_cache) before proceeding to encrypt and send a protobuf message over a THP (Trezor Host Protocol) channel. The assertion will raise AssertionError in non-debug builds if the channel cache state does not permit sending. The diff is a two-line addition and does not show what code paths previously reached this point without the check, nor does it change any recovery or error-handling behavior.
Changed components
core/src/trezor/wire/thp/channel.pyTrezor Host Protocol (THP) channel write pathInspect captured patch +2 / −0
diff --git a/core/src/trezor/wire/thp/channel.py b/core/src/trezor/wire/thp/channel.py
index 1ecbb08ca..d9cd61d51 100644
--- a/core/src/trezor/wire/thp/channel.py
+++ b/core/src/trezor/wire/thp/channel.py
@@ -386,6 +386,8 @@ class Channel:
msg: protobuf.MessageType,
session_id: int = 0,
) -> None:
+ assert ABP.is_sending_allowed(self.channel_cache)
+
if __debug__:
self._log(
f"write message: {msg.MESSAGE_NAME}",
Why this scored 44/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.