Skip to content

Commit 4a7cfe3

Browse files
committed
keysend: enforce BOLT11 description length limit
The keysend plugin previously used `> 1023` as the cutoff for description length when inserting an invoice. This was inconsistent with invoice.c, which enforces the BOLT11 description field limit defined in `common/bolt11.h`. This patch switches to using `BOLT11_FIELD_BYTE_LIMIT` directly. As a result, keysend no longer fails on descriptions between 641–1023 bytes, which previously caused unexpected failures. A new regression test (`test_keysend_description_size_limit`) exercises boundary cases just below, at, and above the limit. Changelog-None Signed-off-by: Wes Payne <[email protected]>
1 parent 49c2f29 commit 4a7cfe3

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

plugins/keysend.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <ccan/asort/asort.h>
55
#include <ccan/cast/cast.h>
66
#include <ccan/tal/str/str.h>
7+
#include <common/bolt11.h>
78
#include <common/gossmap.h>
89
#include <common/json_param.h>
910
#include <common/json_stream.h>
@@ -563,7 +564,7 @@ static struct command_result *htlc_accepted_call(struct command *cmd,
563564
(const char *)desc_field->value);
564565
json_add_string(req->js, "description", desc);
565566
/* Don't exceed max possible desc length! */
566-
if (strlen(desc) > 1023)
567+
if (strlen(desc) >= BOLT11_FIELD_BYTE_LIMIT)
567568
json_add_bool(req->js, "deschashonly", true);
568569
} else {
569570
json_add_string(req->js, "description", "keysend");

tests/test_pay.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
tu64_encode
1212
)
1313
import copy
14+
import json
1415
import os
1516
import pytest
1617
import random
@@ -3697,6 +3698,30 @@ def test_keysend_maxfee(node_factory):
36973698
assert len(l3.rpc.listinvoices()['invoices']) == 1
36983699

36993700

3701+
@pytest.mark.parametrize("tlv_payload_length", [638, 639, 640, 641, 1022, 1023, 1024])
3702+
def test_keysend_description_size_limit(node_factory, tlv_payload_length):
3703+
"""
3704+
Test keysend description handling near BOLT11 field size limits.
3705+
3706+
Checks boundary conditions where the payload length is just below,
3707+
exactly at, and just above the maximum allowed tagged-field size.
3708+
3709+
See common/bolt11.h: BOLT11_FIELD_BYTE_LIMIT.
3710+
"""
3711+
l1, l2 = node_factory.line_graph(2, wait_for_announce=True)
3712+
amt = 10000
3713+
prefix = 'keysend: {"message": ""}'
3714+
base_len = len(prefix)
3715+
3716+
# Prep TLV payload with test length
3717+
body_len = tlv_payload_length - base_len
3718+
tlv_payload = json.dumps({"message": "a" * body_len}).encode().hex()
3719+
3720+
# Send keysend payment with test payload
3721+
l1.rpc.keysend(l2.info["id"], amt, extratlvs={7629169: tlv_payload})
3722+
assert len(l2.rpc.listinvoices()["invoices"]) == 1
3723+
3724+
37003725
def test_invalid_onion_channel_update(node_factory):
37013726
'''
37023727
Some onion failures "should" send a `channel_update`.

0 commit comments

Comments
 (0)