Skip to content

Commit 118e0a9

Browse files
committed
routerrpc: reject invoices missing secret/path
Ensure that a payment is only sent if the invoice includes either a payment address (payment secret) or at least one blinded path.
1 parent c01a667 commit 118e0a9

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

lnrpc/routerrpc/router_backend.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -990,6 +990,15 @@ func (r *RouterBackend) extractIntentFromSendRequest(
990990
return nil, err
991991
}
992992

993+
// An invoice must include either a payment address or
994+
// blinded paths.
995+
if payReq.PaymentAddr.IsNone() &&
996+
len(payReq.BlindedPaymentPaths) == 0 {
997+
998+
return nil, errors.New("payment request must contain " +
999+
"either a payment address or blinded paths")
1000+
}
1001+
9931002
// If the amount was not included in the invoice, then we let
9941003
// the payer specify the amount of satoshis they wish to send.
9951004
// We override the amount to pay with the amount provided from
@@ -1006,7 +1015,7 @@ func (r *RouterBackend) extractIntentFromSendRequest(
10061015
if reqAmt != 0 {
10071016
return nil, errors.New("amount must not be " +
10081017
"specified when paying a non-zero " +
1009-
" amount invoice")
1018+
"amount invoice")
10101019
}
10111020

10121021
payIntent.Amount = *payReq.MilliSat

lnrpc/routerrpc/router_backend_test.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -505,6 +505,13 @@ func TestExtractIntentFromSendRequest(t *testing.T) {
505505
"g6aykds4ydvf2x9lpngqcfux3hv8qlraan9v3s9296r5w5eh959yzadgh5ck" +
506506
"gjydgyfxdpumxtuk3p3caugmlqpz5necs"
507507

508+
const paymentReqMissingAddr = "lnbcrt100p1p70xwfzpp5qqqsyqcyq5rqwzqfq" +
509+
"qqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqypqdpl2pkx2ctnv5sxxmmwwd5kge" +
510+
"tjypeh2ursdae8g6twvus8g6rfwvs8qun0dfjkxaqnp4q0n326hr8v9zprg8" +
511+
"gsvezcch06gfaqqhde2aj730yg0durunfhv669qypqqqz3uu8wnr7883qzxr" +
512+
"566nuhled49fx6e6q0jn06w6gpgyznwzxwf8xdmye87kpx0y8lqtcgwywsau" +
513+
"0jkm66evelkw7cggwlegp4anv3cq62wusm"
514+
508515
destNodeBytes, err := hex.DecodeString(destKey)
509516
require.NoError(t, err)
510517

@@ -720,6 +727,23 @@ func TestExtractIntentFromSendRequest(t *testing.T) {
720727
valid: false,
721728
expectedErrorMsg: "invoice expired.",
722729
},
730+
{
731+
name: "Invoice missing payment address",
732+
backend: &RouterBackend{
733+
ShouldSetExpEndorsement: func() bool {
734+
return false
735+
},
736+
ActiveNetParams: &chaincfg.RegressionNetParams,
737+
MaxTotalTimelock: 1000,
738+
Clock: mockClock,
739+
},
740+
sendReq: &SendPaymentRequest{
741+
PaymentRequest: paymentReqMissingAddr,
742+
},
743+
valid: false,
744+
expectedErrorMsg: "payment request must contain " +
745+
"either a payment address or blinded paths",
746+
},
723747
{
724748
name: "Invalid dest vertex length",
725749
backend: &RouterBackend{

0 commit comments

Comments
 (0)