Merge pull request #717 from Foundation-Devices/sft-8249-passport-core-psbt-error-text-loses-characters-to-lvgl
What changed, and why it matters
This commit fixes a display bug in the Passport hardware wallet where error messages about Bitcoin transaction files (PSBTs) could lose important text, such as input numbers, because the screen-rendering library treats the '#' character as a color-code marker. The fix escapes every '#' so the full error message is shown to the user. It is primarily a usability and information-integrity issue rather than a direct theft-of-funds vulnerability, because the error still blocks signing; however, a malformed PSBT could hide or alter the visible reason for refusal.
Review whether other user-facing labels in the signing and validation flows also render untrusted strings with recolor enabled, and apply escape_text() consistently. Consider a defense-in-depth measure such as disabling recolor on labels that display dynamic error text.
Security signals we found
UI text truncation due to unescaped markup metacharacter
Error-message integrity issue in security-critical signing flow
Potential for crafted PSBT to influence displayed failure reason
Display-layer parsing ambiguity between data and control characters
Evidence from the diff
The Passport firmware uses LVGL with recoloring enabled for label widgets. When a PSBT validation failure is shown, the exception text is inserted directly into an ErrorPage label. If the exception contains a literal ‘#’, LVGL interprets it as the start of a recolor tag and consumes following characters as a hex color code, causing text such as ‘input #3’ to be truncated or mangled. The patch introduces invalid_psbt_text(), which passes the exception string through escape_text() before formatting it into ‘Invalid PSBT: {}’. The unit tests verify that ‘#’ characters are doubled to ‘##’, that plain messages are unchanged, and that injected recolor markup cannot open a color span.
Changed components
ports/stm32/boards/Passport/modules/flows/sign_psbt_common_flow.pyports/stm32/boards/Passport/modules/tests/unit/sign_psbt.pyPassport PSBT signing error display pathLVGL label rendering with recolor enabledInspect captured patch +30 / −2
### ports/stm32/boards/Passport/modules/flows/sign_psbt_common_flow.py
@@ -117,7 +117,7 @@ async def show_transaction_details(self):
self.set_result(None)
except BaseException as e:
- await ErrorPage(text='Invalid PSBT: {}'.format(e)).show()
+ await ErrorPage(text=self.invalid_psbt_text(e)).show()
self.set_result(None)
async def show_change(self):
@@ -138,7 +138,7 @@ async def show_change(self):
else:
self.goto(self.show_warnings)
except Exception as e:
- await ErrorPage(text='Invalid PSBT: {}'.format(e)).show()
+ await ErrorPage(text=self.invalid_psbt_text(e)).show()
self.set_result(None)
async def show_warnings(self):
@@ -250,6 +250,13 @@ def render_change_text(self):
return msg.getvalue()
+ def invalid_psbt_text(self, exc):
+ # Labels render with LVGL recolor on, so a literal '#' in the text opens
+ # a colour tag and the characters after it are eaten as a hex code.
+ # psbt.py raises plenty of messages shaped like "... for input #3", and
+ # the index is the most useful part of them, so escape before display.
+ return 'Invalid PSBT: {}'.format(escape_text('{}'.format(exc)))
+
def render_warnings(self):
import uio
### ports/stm32/boards/Passport/modules/tests/unit/sign_psbt.py
@@ -67,4 +67,25 @@ def assert_op_return_output(value, message):
assert rendered == '\n{}\n42 sats\n\n{}\n{}'.format(
amount_heading, destination_heading, stylize_address(address))
+# PSBT failures are reported through a recolor-enabled label, and psbt.py raises
+# plenty of messages carrying a literal '#'. Unescaped, LVGL reads that as the
+# start of a colour tag and drops the index that follows it.
+indexed = 'Missing redeem/witness script for input #3'
+rendered = SignPsbtCommonFlow.invalid_psbt_text(MockFlow(), ValueError(indexed))
+assert rendered == 'Invalid PSBT: {}'.format(escape_text(indexed))
+assert 'input ##3' in rendered
+# Every '#' is doubled, which is what makes LVGL draw it rather than read a
+# colour tag. Checking the invariant beats checking for a literal, because the
+# escaped form of a tag still contains the unescaped form as a substring.
+assert '#' not in rendered.replace('##', '')
+
+# A message with no '#' must come through untouched.
+plain = 'Network fee bigger than the amount you are sending'
+assert SignPsbtCommonFlow.invalid_psbt_text(MockFlow(), ValueError(plain)) == \
+ 'Invalid PSBT: {}'.format(plain)
+
+# And recolor markup inside an exception cannot open a colour span.
+injected = SignPsbtCommonFlow.invalid_psbt_text(MockFlow(), ValueError(amount_heading))
+assert '#' not in injected.replace('##', '')
+
return_value.write(b'OK')Why this scored 31/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.