chore(core): don't access `CURRENT_CONTEXT` outside `trezor.wire.context`
What changed, and why it matters
This is a small internal cleanup in the Trezor firmware that replaces direct access to a global variable (CURRENT_CONTEXT) with a safer helper function (get_context()). The change is described by the developers as a code hygiene improvement, not a security fix. It slightly reduces the risk of future bugs by making context access more controlled, but there is no direct evidence it fixes an exploitable vulnerability.
No immediate action required. Treat as routine code maintenance. If auditing, verify that context.get_context() correctly enforces access rules and that NoWireContext is handled safely in all callers.
Security signals we found
Refactoring of context access to use an abstraction rather than direct global variable access
Exception handling added for NoWireContext in UI layout initialization
No changelog entry and commit title marked as chore, indicating developer-perceived low severity
No explicit security relevance, CVE, advisory, or researcher attribution in commit or supplied references
Evidence from the diff
The commit modifies two files to stop directly reading context.CURRENT_CONTEXT outside of trezor.wire.context. In payment_request.py, it now calls context.get_context() and catches context.NoWireContext. In ui/init.py, it similarly uses get_context() with exception handling instead of direct attribute access. The commit message labels this as a chore (routine maintenance) and explicitly says [no changelog], indicating the vendor does not treat it as a user-visible or security-relevant change. No vulnerability, exploit primitive, or security impact is demonstrated by the diff itself.
Changed components
core/src/apps/common/payment_request.pycore/src/trezor/ui/__init__.pyInspect captured patch +8 / −3
diff --git a/core/src/apps/common/payment_request.py b/core/src/apps/common/payment_request.py
index 4e219544..339ab91e 100644
--- a/core/src/apps/common/payment_request.py
+++ b/core/src/apps/common/payment_request.py
@@ -107,7 +107,9 @@ class PaymentRequestVerifier:
if __debug__:
self._use_debug_key()
self._use_debug_verification()
- if context.CURRENT_CONTEXT is None:
+ try:
+ context.get_context()
+ except context.NoWireContext:
# in unit tests we don't have a context, so we replace
# the nonce verification with the debug version
# otherwise (device tests, etc) we should use the proper nonce verification
diff --git a/core/src/trezor/ui/__init__.py b/core/src/trezor/ui/__init__.py
index 03c8569b..72d02089 100644
--- a/core/src/trezor/ui/__init__.py
+++ b/core/src/trezor/ui/__init__.py
@@ -209,8 +209,11 @@ class Layout(Generic[T]):
# do not notify debuglink, we will do it when we receive an ATTACHED event
set_current_layout(self)
- # save context
- self.context = context.CURRENT_CONTEXT
+ try:
+ # save context (if exists)
+ self.context = context.get_context()
+ except context.NoWireContext:
+ pass
# attach a timer callback and paint self
self._event(self.layout.attach_timer_fn, self._set_timer, transition_in)
Why this scored 16/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.