SFT-8249: escape PSBT error text before displaying it
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 have important text hidden from the user. The device's screen library treats a '#' character as the start of a color command, so an error like 'problem with input #3' would show only 'problem with input ' and hide the number. The fix escapes the '#' so the full message appears. It is a user-interface reliability fix rather than a direct theft-of-funds vulnerability, but missing error details could mislead a user during transaction signing.
Treat this as a low-severity UI hardening fix. Merge the patch, then consider a broader audit of ErrorPage and other label text paths for similar unescaped '#' or markup characters, as the commit deliberately narrows scope to avoid behavior changes across 141 call sites.
Security signals we found
UI markup injection / display corruption via unescaped '#' in LVGL recolor mode
Loss of security-relevant numeric context (input index) in PSBT error messages
Prior partial fix (deef57bc) left additional error path unescaped
New centralized escaping helper improves testability and maintainability
Unit tests added for escaping behavior
Evidence from the diff
The Passport firmware uses LVGL with recoloring enabled, so a literal ‘#’ in a label begins a color tag and the following characters are parsed as a hex color code and not rendered. PSBT validation errors from psbt.py commonly contain ‘input #N’, causing the input index to disappear from the displayed error. The patch routes two ‘Invalid PSBT: {}’.format(e) call sites through a new invalid_psbt_text() helper that escapes ‘#’ via escape_text() before display, and adds unit tests verifying that ‘#’ is doubled to ‘##’, plain messages pass unchanged, and 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 firmware PSBT signing flow error displayInspect 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 38/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.