Skip to content

Commit 6efacd6

Browse files
committed
routerrpc: reject payment to invoice that don't have payment secret or blinded paths
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 c9fe051 commit 6efacd6

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

lnrpc/routerrpc/router_backend.go

+9-1
Original file line numberDiff line numberDiff line change
@@ -985,6 +985,14 @@ func (r *RouterBackend) extractIntentFromSendRequest(
985985
return nil, err
986986
}
987987

988+
// An invoice must include either a payment address or
989+
// blinded paths.
990+
if payReq.PaymentAddr.IsNone() &&
991+
len(payReq.BlindedPaymentPaths) == 0 {
992+
return nil, errors.New("payment request must contain " +
993+
"either a payment address or blinded paths")
994+
}
995+
988996
// If the amount was not included in the invoice, then we let
989997
// the payer specify the amount of satoshis they wish to send.
990998
// We override the amount to pay with the amount provided from
@@ -1001,7 +1009,7 @@ func (r *RouterBackend) extractIntentFromSendRequest(
10011009
if reqAmt != 0 {
10021010
return nil, errors.New("amount must not be " +
10031011
"specified when paying a non-zero " +
1004-
" amount invoice")
1012+
"amount invoice")
10051013
}
10061014

10071015
payIntent.Amount = *payReq.MilliSat

lnrpc/routerrpc/router_backend_test.go

+24
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,13 @@ func TestExtractIntentFromSendRequest(t *testing.T) {
503503
"g6aykds4ydvf2x9lpngqcfux3hv8qlraan9v3s9296r5w5eh959yzadgh5ck" +
504504
"gjydgyfxdpumxtuk3p3caugmlqpz5necs"
505505

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

@@ -714,6 +721,23 @@ func TestExtractIntentFromSendRequest(t *testing.T) {
714721
valid: false,
715722
expectedErrorMsg: "invoice expired.",
716723
},
724+
{
725+
name: "Invoice missing payment address",
726+
backend: &RouterBackend{
727+
ShouldSetExpEndorsement: func() bool {
728+
return false
729+
},
730+
ActiveNetParams: &chaincfg.RegressionNetParams,
731+
MaxTotalTimelock: 1000,
732+
},
733+
sendReq: &SendPaymentRequest{
734+
PaymentRequest: paymentReqMissingAddr,
735+
CltvLimit: 22,
736+
},
737+
valid: false,
738+
expectedErrorMsg: "payment request must contain " +
739+
"either a payment address or blinded paths",
740+
},
717741
{
718742
name: "Invalid dest vertex length",
719743
backend: &RouterBackend{

0 commit comments

Comments
 (0)