Skip to content

Commit 79928ba

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 79928ba

File tree

2 files changed

+38
-6
lines changed

2 files changed

+38
-6
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

+29-5
Original file line numberDiff line numberDiff line change
@@ -497,11 +497,18 @@ type extractIntentTestCase struct {
497497
func TestExtractIntentFromSendRequest(t *testing.T) {
498498
const paymentAmount = btcutil.Amount(300_000)
499499

500-
const paymentReq = "lnbcrt500u1pnh0xflpp56w08q26t896vg2e9mtdkrem320tp" +
501-
"wws9z9sfr7dw86dx97d90u4sdqqcqzzsxqyz5vqsp5z9945kvfy5g9afmakz" +
502-
"yrur2t4hhn2tr87un8j0r0e6l5m5zm0fus9qxpqysgqk98c6j7qefdpdmzt4" +
503-
"g6aykds4ydvf2x9lpngqcfux3hv8qlraan9v3s9296r5w5eh959yzadgh5ck" +
504-
"gjydgyfxdpumxtuk3p3caugmlqpz5necs"
500+
const paymentReq = "lnbcrt500u1pnh0xflpp56w08q26t896vg2e9mtdkr" +
501+
"em320tpwws9z9sfr7dw86dx97d90u4sdqqcqzzsxqyz5vqsp5z9945kvfy5g" +
502+
"9afmakzyrur2t4hhn2tr87un8j0r0e6l5m5zm0fus9qxpqysgqk98c6j7qef" +
503+
"dpdmzt4g6aykds4ydvf2x9lpngqcfux3hv8qlraan9v3s9296r5w5eh959yz" +
504+
"adgh5ckgjydgyfxdpumxtuk3p3caugmlqpz5necs"
505+
506+
const paymentReqMissingAddr = "lnbcrt100p1p70xwfzpp5qqqsyqcyq5rqwzqfq" +
507+
"qqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqypqdpl2pkx2ctnv5sxxmmwwd5kge" +
508+
"tjypeh2ursdae8g6twvus8g6rfwvs8qun0dfjkxaqnp4q0n326hr8v9zprg8" +
509+
"gsvezcch06gfaqqhde2aj730yg0durunfhv669qypqqqz3uu8wnr7883qzxr" +
510+
"566nuhled49fx6e6q0jn06w6gpgyznwzxwf8xdmye87kpx0y8lqtcgwywsau" +
511+
"0jkm66evelkw7cggwlegp4anv3cq62wusm"
505512

506513
destNodeBytes, err := hex.DecodeString(destKey)
507514
require.NoError(t, err)
@@ -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)