check_swap_memo(): require is_swap to be set if memo present in transaction

Fixes a vulnerability whereby an attacker with access to the online machine
could bypass the address-belongs-to-wallet test performed by the offline signer
by crafting a transaction file containing a swap memo but with the “is_swap”
field unset or set to false.
This commit is contained in:
The MMGen Project 2026-11-22 09:28:48 +00:00
commit 1be9184b56
Signed by: mmgen
GPG key ID: 3F8B1861E32B7DA2

View file

@ -101,10 +101,13 @@ class Completed(Base):
tokensym = r.tokensym,
need_amt = True)
if not (self.is_swap or self.is_deposit):
raise ValueError(
'Swap memo present in transaction but ‘is_swap’ field not set. '
'Your online installation may be compromised!')
if mmid := getattr(self, 'swap_recv_addr_mmid', None):
return self.Output(proto, addr=p.address, mmid=mmid, amt=proto.coin_amt('0'))
elif not self.is_swap:
pass
elif self.cfg.allow_non_wallet_swap:
ymsg('Warning: allowing swap to non-wallet address (--allow-non-wallet-swap)')
return self.Output(proto, addr=p.address, mmid=None, amt=proto.coin_amt('0'))