diff --git a/plugins/keysend.c b/plugins/keysend.c index 24743389d..ef6533440 100644 --- a/plugins/keysend.c +++ b/plugins/keysend.c @@ -171,13 +171,19 @@ static struct command_result *json_keysend(struct command *cmd, const char *buf, p->deadline = timeabs_add(time_now(), time_from_sec(*retryfor)); p->getroute->riskfactorppm = 10000000; + if (node_id_eq(&my_id, p->destination)) { + return command_fail( + cmd, JSONRPC2_INVALID_PARAMS, + "We are the destination. Keysend cannot be used to send funds to yourself"); + } + if (!amount_msat_fee(&p->constraints.fee_budget, p->amount, 0, *maxfee_pct_millionths / 100)) { - tal_free(p); return command_fail( cmd, JSONRPC2_INVALID_PARAMS, "Overflow when computing fee budget, fee rate too high."); } + p->constraints.cltv_budget = *maxdelay; payment_mod_exemptfee_get_data(p)->amount = *exemptfee; diff --git a/tests/test_pay.py b/tests/test_pay.py index 6dfd92b4e..356b5f7aa 100644 --- a/tests/test_pay.py +++ b/tests/test_pay.py @@ -3030,6 +3030,10 @@ def test_keysend(node_factory): features = l1.rpc.listnodes(l4.info['id'])['nodes'][0]['features'] assert(int(features, 16) >> 55 & 0x01 == 0) + # Self-sends are not allowed (see #4438) + with pytest.raises(RpcError, match=r'We are the destination.'): + l1.rpc.keysend(l1.info['id'], amt) + # Send an indirect one from l1 to l3 l1.rpc.keysend(l3.info['id'], amt) invs = l3.rpc.listinvoices()['invoices']