SFT-3834: preserved trailing newlines and added a warning for signing
What changed, and why it matters
This commit changes how the Passport hardware wallet displays messages before the user signs them. It now keeps trailing newlines and spaces exactly as they appear in the original message, instead of trimming them, and shows a warning when a message ends with such invisible characters. The goal is to prevent a trick where an attacker hides part of a message after many blank lines so the user only sees the harmless-looking top portion and unknowingly signs something different.
No immediate action required; this is a defensive hardening patch. Users should ensure firmware is updated to a version containing this change. Developers should consider localizing the new warning strings and extending the warning to other signing flows if not already covered.
Security signals we found
UI message-review hardening against trailing-whitespace hiding attacks
New footer warning for messages ending in whitespace
require_scroll_to_end=True added to message review pages
Trailing newlines/spaces preserved instead of trimmed
Unit tests explicitly cover messages with trailing whitespace and long vertical gaps
Evidence from the diff
The patch modifies message-review flows (sign_electrum_message_flow.py and health_check_common_flow.py) to stop wrapping the escaped text in parentheses and to add a footer warning plus require_scroll_to_end=True. A new utility function message_review_warning() in utils.py detects if the message ends in whitespace (space, \r, \n, \t) and returns a two-line warning. LongTextPage gains a footer rendering capability. Unit tests verify that trailing whitespace is preserved and that the warning appears only when appropriate. The change is defensive: it makes invisible trailing characters visible to the user rather than silently stripping them.
Changed components
ports/stm32/boards/Passport/modules/flows/sign_electrum_message_flow.pyports/stm32/boards/Passport/modules/flows/health_check_common_flow.pyports/stm32/boards/Passport/modules/pages/long_text_page.pyports/stm32/boards/Passport/modules/utils.pyports/stm32/boards/Passport/modules/tests/unit/message_display.pyports/stm32/boards/Passport/modules/tests/unit/transaction_review.pyInspect captured patch +64 / −13
### ports/stm32/boards/Passport/modules/flows/health_check_common_flow.py
@@ -87,7 +87,7 @@ async def validate_lines(self):
async def show_message(self):
import stash
- from utils import escape_text, stylize_address
+ from utils import escape_text, message_review_warning, stylize_address
from pages import LongTextPage, LongQuestionPage
import microns
from public_constants import MARGIN_FOR_ADDRESSES
@@ -99,7 +99,9 @@ async def show_message(self):
display_address = stylize_address(self.address)
result = await LongTextPage(centered=True,
- text=('\n' + escape_text(self.text)),
+ text='\n' + escape_text(self.text),
+ footer=message_review_warning(self.text),
+ require_scroll_to_end=True,
card_header={'title': 'Message'}).show()
if not result:
### ports/stm32/boards/Passport/modules/flows/sign_electrum_message_flow.py
@@ -6,7 +6,7 @@
from flows import Flow, ScanQRFlow
from pages import ErrorPage, LongTextPage, LongQuestionPage, ShowQRPage
from tasks import sign_text_file_task, validate_electrum_message_task
-from utils import escape_text, spinner_task, stylize_address
+from utils import escape_text, message_review_warning, spinner_task, stylize_address
from data_codecs.qr_type import QRType
import microns
from wallets.utils import get_addr_type_from_deriv
@@ -61,7 +61,9 @@ async def show_message(self):
display_address = stylize_address(self.address)
result = await LongTextPage(centered=True,
- text=('\n' + escape_text(self.message)),
+ text='\n' + escape_text(self.message),
+ footer=message_review_warning(self.message),
+ require_scroll_to_end=True,
card_header={'title': 'Message'}).show()
if not result:
### ports/stm32/boards/Passport/modules/pages/long_text_page.py
@@ -7,7 +7,7 @@
from styles.style import Stylize
from views import Label, View, Icon
from pages import Page
-from styles.colors import TEXT_GREY, SCROLLBAR_BG_COLOR
+from styles.colors import TEXT_GREY, SCROLLBAR_BG_COLOR, HIGHLIGHT_TEXT
import microns
import passport
@@ -24,7 +24,8 @@ def __init__(self,
right_micron=microns.Forward,
margins=None,
top_margin=None,
- require_scroll_to_end=False):
+ require_scroll_to_end=False,
+ footer=None):
super().__init__(
card_header=card_header,
statusbar=statusbar,
@@ -82,7 +83,19 @@ def __init__(self,
default.text_align(lv.TEXT_ALIGN.CENTER)
self.container.set_children([self.text])
- self.add_child(self.container)
+
+ if footer is not None:
+ title, body = footer
+ self.footer = Label(text=title, color=HIGHLIGHT_TEXT, center=centered, recolor=False)
+ self.footer.set_width(lv.pct(100))
+ with Stylize(self.footer) as default:
+ default.pad(top=16)
+ self.container.add_child(self.footer)
+ self.footer_body = Label(text=body, color=TEXT_GREY, center=centered, recolor=False)
+ self.footer_body.set_width(lv.pct(100))
+ self.container.add_child(self.footer_body)
+
+ self.add_child(self.container)
def attach(self, group):
super().attach(group)
### ports/stm32/boards/Passport/modules/tests/unit/message_display.py
@@ -14,6 +14,17 @@
class MockReviewPage:
texts = []
+ def __init__(self, text, **kwargs):
+ assert kwargs['require_scroll_to_end']
+ self.texts.append((text, kwargs['footer']))
+
+ async def show(self):
+ return True
+
+
+class MockQuestionPage:
+ texts = []
+
def __init__(self, text, **kwargs):
self.texts.append(text)
@@ -71,11 +82,14 @@ async def run_tests():
original_electrum_spinner = electrum.spinner_task
try:
pages.LongTextPage = electrum.LongTextPage = MockReviewPage
- pages.LongQuestionPage = electrum.LongQuestionPage = MockReviewPage
+ pages.LongQuestionPage = electrum.LongQuestionPage = MockQuestionPage
stash.SensitiveValues = MockSensitiveValues
utils.spinner_task = electrum.spinner_task = mock_sign_spinner
cases = (
+ ('trailing space ', 'trailing space '),
+ ('leading and interior\nwhitespace', 'leading and interior\nwhitespace'),
+ ('I approve A' + '\n' * 40 + 'and B', 'I approve A' + '\n' * 40 + 'and B'),
('\nfirst\n\nsecond\n', '\nfirst\n\nsecond\n'),
('first\r\n#ff0000 second#\r\n', 'first\r\n##ff0000 second##\r\n'),
('literal # and ## hashes', 'literal ## and #### hashes'),
@@ -87,15 +101,19 @@ async def run_tests():
flow = MockFlow()
flow.message = flow.text = message
MockReviewPage.texts = []
+ MockQuestionPage.texts = []
before = len(signed_messages)
if is_electrum:
await electrum.SignElectrumMessageFlow.show_message(flow)
assert flow.next_state == flow.do_sign
else:
await HealthCheckCommonFlow.show_message(flow)
assert flow.next_state == flow.sign_health_check
- assert MockReviewPage.texts[0] == '\n' + displayed
- assert len(MockReviewPage.texts) == 2
+ warning = None
+ if message.endswith(' ') or message.endswith('\n'):
+ warning = ('This message ends with whitespace.', 'It will be included in the signature.')
+ assert MockReviewPage.texts == [('\n' + displayed, warning)]
+ assert len(MockQuestionPage.texts) == 1
assert len(signed_messages) == before
assert flow.message == flow.text == message
if is_electrum:
### ports/stm32/boards/Passport/modules/tests/unit/transaction_review.py
@@ -11,7 +11,7 @@
from pages.long_text_page import LongTextPage
from psbt import psbtOutputProxy
from serializations import CTxOut
-from styles.colors import HIGHLIGHT_TEXT_HEX
+from styles.colors import HIGHLIGHT_TEXT, HIGHLIGHT_TEXT_HEX, TEXT_GREY
from uio import BytesIO
from utils import escape_text, recolor, stylize_address
@@ -217,11 +217,20 @@ def test_scroll_gate():
parent.set_flex_flow(lv.FLEX_FLOW.COLUMN)
group = lv.group_create()
try:
- for text, overflow in (('Short text', False), ('Long warning\n' * 50, True)):
- page = LongTextPage(text=text, require_scroll_to_end=True)
+ for text, footer, overflow in (
+ ('Short text', None, False),
+ ('Long warning\n' * 50, None, True),
+ ('Short text', ('Trailing whitespace notice ' * 30, 'Signature explanation'), True)):
+ page = LongTextPage(text=text, footer=footer, require_scroll_to_end=True)
page.mount(parent)
page.attach(group)
container = page.container.lvgl_root
+ if footer is not None:
+ assert page.footer.lvgl_root.get_style_text_color(0).full == HIGHLIGHT_TEXT.full
+ assert not page.footer.lvgl_root.get_recolor()
+ assert page.footer.lvgl_root.get_height() > 30
+ assert page.footer_body.lvgl_root.get_style_text_color(0).full == TEXT_GREY.full
+ assert not page.footer_body.lvgl_root.get_recolor()
assert (container.get_scroll_bottom() > 0) == overflow
assert (common.ui.right_micron is None) == overflow
page.right_action(True)
### ports/stm32/boards/Passport/modules/utils.py
@@ -1487,6 +1487,13 @@ def escape_text(text):
return text.replace("#", "##")
+def message_review_warning(message):
+ if message and message[-1] in ' \r\n\t':
+ # TODO: localize
+ return ('This message ends with whitespace.', 'It will be included in the signature.')
+ return None
+
+
def stylize_address(address):
from styles.colors import TEXT_GREY_HEX, BLACK_HEX
Why this scored 40/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.