From 137ca9afdf5fdf8bc9e2d7d479cd2a20c21d6e5b Mon Sep 17 00:00:00 2001 From: Roei Erez Date: Mon, 5 Aug 2024 15:21:02 +0300 Subject: [PATCH 1/4] validate invoice expiration --- libs/sdk-core/src/breez_services.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/libs/sdk-core/src/breez_services.rs b/libs/sdk-core/src/breez_services.rs index e3233b0b6..9648b740b 100644 --- a/libs/sdk-core/src/breez_services.rs +++ b/libs/sdk-core/src/breez_services.rs @@ -261,6 +261,12 @@ impl BreezServices { ) -> Result { self.start_node().await?; let parsed_invoice = parse_invoice(req.bolt11.as_str())?; + let invoice_expiration = parsed_invoice.timestamp + parsed_invoice.expiry; + if invoice_expiration < SystemTime::now().duration_since(UNIX_EPOCH)?.as_secs() { + return Err(SendPaymentError::InvoiceExpired { + err: format!("Invoice expired at {}", parsed_invoice.expiry).into(), + }); + } let invoice_amount_msat = parsed_invoice.amount_msat.unwrap_or_default(); let provided_amount_msat = req.amount_msat.unwrap_or_default(); From 3d285ea29a34a48a1404a8e8ded818647099f118 Mon Sep 17 00:00:00 2001 From: Roei Erez Date: Mon, 5 Aug 2024 15:42:21 +0300 Subject: [PATCH 2/4] fix clippy --- libs/sdk-core/src/breez_services.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/sdk-core/src/breez_services.rs b/libs/sdk-core/src/breez_services.rs index 9648b740b..72f0ee671 100644 --- a/libs/sdk-core/src/breez_services.rs +++ b/libs/sdk-core/src/breez_services.rs @@ -264,7 +264,7 @@ impl BreezServices { let invoice_expiration = parsed_invoice.timestamp + parsed_invoice.expiry; if invoice_expiration < SystemTime::now().duration_since(UNIX_EPOCH)?.as_secs() { return Err(SendPaymentError::InvoiceExpired { - err: format!("Invoice expired at {}", parsed_invoice.expiry).into(), + err: format!("Invoice expired at {}", parsed_invoice.expiry), }); } let invoice_amount_msat = parsed_invoice.amount_msat.unwrap_or_default(); From 5040acfd1739f34aa7ee91f2384523c83633ce9a Mon Sep 17 00:00:00 2001 From: Roei Erez Date: Tue, 6 Aug 2024 09:05:57 +0300 Subject: [PATCH 3/4] show correct invoice_expiration --- libs/sdk-core/src/breez_services.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/sdk-core/src/breez_services.rs b/libs/sdk-core/src/breez_services.rs index 72f0ee671..60da1333b 100644 --- a/libs/sdk-core/src/breez_services.rs +++ b/libs/sdk-core/src/breez_services.rs @@ -264,7 +264,7 @@ impl BreezServices { let invoice_expiration = parsed_invoice.timestamp + parsed_invoice.expiry; if invoice_expiration < SystemTime::now().duration_since(UNIX_EPOCH)?.as_secs() { return Err(SendPaymentError::InvoiceExpired { - err: format!("Invoice expired at {}", parsed_invoice.expiry), + err: format!("Invoice expired at {}", invoice_expiration), }); } let invoice_amount_msat = parsed_invoice.amount_msat.unwrap_or_default(); From eaa86fbfaefb94d11b25197f61169a81cc0f6be9 Mon Sep 17 00:00:00 2001 From: Roei Erez Date: Tue, 6 Aug 2024 14:45:45 +0300 Subject: [PATCH 4/4] cosmetic change for better readable code --- libs/sdk-core/src/breez_services.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libs/sdk-core/src/breez_services.rs b/libs/sdk-core/src/breez_services.rs index 60da1333b..d92133692 100644 --- a/libs/sdk-core/src/breez_services.rs +++ b/libs/sdk-core/src/breez_services.rs @@ -262,7 +262,8 @@ impl BreezServices { self.start_node().await?; let parsed_invoice = parse_invoice(req.bolt11.as_str())?; let invoice_expiration = parsed_invoice.timestamp + parsed_invoice.expiry; - if invoice_expiration < SystemTime::now().duration_since(UNIX_EPOCH)?.as_secs() { + let current_time = SystemTime::now().duration_since(UNIX_EPOCH)?.as_secs(); + if invoice_expiration < current_time { return Err(SendPaymentError::InvoiceExpired { err: format!("Invoice expired at {}", invoice_expiration), });