What changed, and why it matters
This commit tightens how Passport handles QR codes when importing a multi-signature wallet configuration. Previously, the code could accept an unexpected type of Uniform Resource (UR) object and try to treat it as plain bytes, which could cause a crash or confuse the wallet import process. Now the firmware explicitly checks that the UR type is 'bytes' before unwrapping it, and the multisig import flow only allows plain QR data or bytes-type UR data. A new unit test confirms that wrong UR types are rejected with a user-facing error.
Treat as a defensive hardening fix. Review whether other unwrap_* helpers in modfoundation-ur.h perform similar tag checks, and ensure ScanQRFlow's ur_types filtering is enforced consistently across all QR-import flows. No immediate incident response is indicated by the diff alone.
Security signals we found
Type confusion hardening: unwrap_bytes now validates UR tag before dereferencing bytes payload
Input scope reduction: multisig QR import restricted to QRType.QR and QRType.UR2 with ur.Value.BYTES only
Crash-to-exception conversion: mp_check_self assertion replaced by explicit ValueError
Regression test added covering wrong UR types, malformed bytes, oversized QR, and invalid QR errors
Evidence from the diff
The patch adds a runtime type check in mod_foundation_ur_Value_unwrap_bytes: it now raises a ValueError if the UR tag is not Bytes, instead of using MicroPython’s mp_check_self which would assert/crash. The connect_wallet_flow.py import_multisig_config_from_qr method is refactored to operate directly on the scan result (a ur.Value or str) rather than on scan_result.data, and it no longer silently accepts arbitrary UR types. read_multisig_config_from_qr now calls ScanQRFlow with explicit qr_types=[QR, UR2] and ur_types=[ur.Value.BYTES], limiting accepted input. A unit test verifies rejection of a PSBT UR and a passport crypto-request UR, plus malformed bytes and QR errors.
Changed components
extmod/foundation/modfoundation-ur.h (C UR value wrapper)ports/stm32/boards/Passport/modules/flows/connect_wallet_flow.py (multisig import flow)ports/stm32/boards/Passport/modules/wallets/multisig_import.py (QR reader helper)ports/stm32/boards/Passport/modules/tests/unit/multisig_qr_import.py (new unit test)Inspect captured patch +141 / −13
### extmod/foundation/modfoundation-ur.h
@@ -132,7 +132,9 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_foundation_ur_Value_ur_type_obj, mod_founda
/// """
STATIC mp_obj_t mod_foundation_ur_Value_unwrap_bytes(mp_obj_t self_in) {
mp_obj_Value_t *self = MP_OBJ_TO_PTR(self_in);
- mp_check_self(self->value.tag == Bytes);
+ if (self->value.tag != Bytes) {
+ mp_raise_msg(&mp_type_ValueError, MP_ERROR_TEXT("expected bytes UR"));
+ }
return mp_obj_new_bytearray_by_ref(self->value.bytes.len, (void *)self->value.bytes.data);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_foundation_ur_Value_unwrap_bytes_obj,
### ports/stm32/boards/Passport/modules/flows/connect_wallet_flow.py
@@ -399,20 +399,15 @@ async def import_multisig_config_from_qr(self):
# Retry
return
- if scan_result.error is not None:
- # Show error
+ if scan_result in (Error.QR_TOO_LARGE, Error.PSBT_OVERSIZED):
self.set_result(False)
return
try:
- # Mulitsig config should be a bytes-like object that we decode to a string
- if isinstance(scan_result.data, ur.Value):
- self.multisig_import_data = scan_result.data.unwrap_bytes().decode('utf-8')
- elif isinstance(scan_result.data, str):
- self.multisig_import_data = scan_result.data
-
- # from utils import to_str
- # print('MS Data: {}'.format(to_str(self.multisig_import_data)))
+ if isinstance(scan_result, ur.Value):
+ self.multisig_import_data = scan_result.unwrap_bytes().decode('utf-8')
+ elif isinstance(scan_result, str):
+ self.multisig_import_data = scan_result
except BaseException as e:
await ErrorPage(text='Unexpected data format: {}'.format(e)).show()
return
### ports/stm32/boards/Passport/modules/tests/test_unit.py
@@ -60,6 +60,10 @@ def test_ur_derived_key(test):
assert test('ur_derived_key.py') == b'OK'
+def test_multisig_qr_import(test):
+ assert test('multisig_qr_import.py') == b'OK'
+
+
def test_psbt_multisig_approval(test):
assert test('psbt_multisig_approval.py') == b'OK'
### ports/stm32/boards/Passport/modules/tests/unit/multisig_qr_import.py
@@ -0,0 +1,122 @@
+# SPDX-FileCopyrightText: © 2026 Foundation Devices, Inc. <hello@foundation.xyz>
+# SPDX-License-Identifier: GPL-3.0-or-later
+
+import uasyncio as asyncio
+import flows.scan_qr_flow as scan_module
+import flows.connect_wallet_flow as connect_module
+from foundation import ur
+from data_codecs.ur2_codec import UR2Decoder
+from pages.scan_qr_page import QRScanResult
+from wallets.multisig_import import read_multisig_config_from_qr
+
+
+class MockPage:
+ result = None
+ messages = []
+
+ def __init__(self, **kwargs):
+ if 'text' in kwargs:
+ self.messages.append(kwargs['text'])
+
+ async def show(self, **kwargs):
+ return self.result
+
+
+class MockInfoPage(MockPage):
+ result = True
+
+
+class MockConnectFlow:
+ sw_wallet = {'label': 'test wallet'}
+ do_multisig_config_import = 'import'
+
+ def __init__(self):
+ self.sig_type = {'import_qr': read_multisig_config_from_qr}
+ self.multisig_import_data = None
+ self.next_state = None
+ self.result = None
+
+ def get_custom_text(self, key, default):
+ return default
+
+ def goto(self, state):
+ self.next_state = state
+
+ def set_result(self, result):
+ self.result = result
+
+
+async def import_result(result):
+ MockPage.result = result
+ MockPage.messages = []
+ flow = MockConnectFlow()
+ await connect_module.ConnectWalletFlow.import_multisig_config_from_qr(flow)
+ return flow
+
+
+async def run_tests():
+ original_scan = scan_module.ScanQRPage
+ original_error = scan_module.ErrorPage
+ original_long_error = scan_module.LongErrorPage
+ original_info = connect_module.InfoPage
+ original_connect_error = connect_module.ErrorPage
+ scan_module.ScanQRPage = MockPage
+ scan_module.ErrorPage = MockPage
+ scan_module.LongErrorPage = MockPage
+ connect_module.InfoPage = MockInfoPage
+ connect_module.ErrorPage = MockPage
+ try:
+ config = 'Name: Test wallet\nPolicy: 2 of 3\n'
+ for data in (config, ur.new_bytes(config.encode())):
+ flow = await import_result(QRScanResult(data=data))
+ assert flow.multisig_import_data == config
+ assert flow.next_state == 'import'
+ assert len(MockPage.messages) == 1
+
+ # A model request exercises the UUID-bearing union variant from the report.
+ request_cbor = b'\xa2\x01\xd8\x25\x50' + bytes(16) + b'\x03\xd9\x02\xd0\xf5'
+ ur.encoder_start(ur.new_raw('crypto-request', request_cbor), 535)
+ decoder = UR2Decoder()
+ decoder.add_data(ur.encoder_next_part())
+ assert decoder.is_complete()
+ request = decoder.decode()
+ assert request.ur_type() == ur.Value.PASSPORT_REQUEST
+ for wrong_type in (ur.new_psbt(b'not a multisig configuration'), request):
+ try:
+ wrong_type.unwrap_bytes()
+ except ValueError:
+ pass
+ else:
+ raise AssertionError('wrong UR tag accepted by unwrap_bytes')
+
+ flow = await import_result(QRScanResult(data=wrong_type))
+ assert flow.next_state is None
+ assert flow.multisig_import_data is None
+ assert 'This type of UR is not expected' in MockPage.messages[-1]
+
+ flow = await import_result(None)
+ assert flow.next_state is None
+ assert flow.multisig_import_data is None
+ assert len(MockPage.messages) == 1
+
+ flow = await import_result(QRScanResult(data=ur.new_bytes(b'\xff')))
+ assert flow.next_state is None
+ assert 'Unexpected data format' in MockPage.messages[-1]
+
+ flow = await import_result(QRScanResult(error=ur.TooBigError()))
+ assert flow.next_state is None
+ assert flow.result is False
+
+ flow = await import_result(QRScanResult(error=ValueError('invalid QR')))
+ assert flow.next_state is None
+ assert 'Unable to scan QR code' in MockPage.messages[-1]
+ finally:
+ scan_module.ScanQRPage = original_scan
+ scan_module.ErrorPage = original_error
+ scan_module.LongErrorPage = original_long_error
+ connect_module.InfoPage = original_info
+ connect_module.ErrorPage = original_connect_error
+
+
+asyncio.run(run_tests())
+return_value.write(b'OK')
### ports/stm32/boards/Passport/modules/wallets/multisig_import.py
@@ -15,8 +15,13 @@
# connect_wallet_flow.py, and that probably needs to be modified during the refactoring.
async def read_multisig_config_from_qr():
- from pages import ScanQRPage
- return await ScanQRPage().show()
+ from data_codecs.qr_type import QRType
+ from flows import ScanQRFlow
+ from foundation import ur
+
+ return await ScanQRFlow(qr_types=[QRType.QR, QRType.UR2],
+ ur_types=[ur.Value.BYTES],
+ data_description='a multisig wallet configuration file').run()
async def read_multisig_config_from_microsd():Why this scored 47/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.