Skip to content

Commit 1c67e50

Browse files
fixup: Fix vulnerability where a webhook update could be used to reset the last_used field
1 parent 8f23464 commit 1c67e50

File tree

1 file changed

+18
-11
lines changed

1 file changed

+18
-11
lines changed

lightning-liquidity/src/lsps5/service.rs

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -209,21 +209,23 @@ where
209209
});
210210
}
211211

212+
let (last_used, last_notification_sent) = if no_change {
213+
let existing_webhook = client_webhooks.get(&params.app_name).unwrap();
214+
(existing_webhook.last_used.clone(), existing_webhook.last_notification_sent.clone())
215+
} else {
216+
(now, new_hash_map())
217+
};
218+
212219
let stored_webhook = StoredWebhook {
213220
_app_name: params.app_name.clone(),
214221
url: params.webhook.clone(),
215222
_counterparty_node_id: counterparty_node_id,
216-
last_used: now,
217-
last_notification_sent: new_hash_map(),
223+
last_used,
224+
last_notification_sent,
218225
};
219226

220227
client_webhooks.insert(params.app_name.clone(), stored_webhook);
221228

222-
let response = SetWebhookResponse {
223-
num_webhooks: client_webhooks.len() as u32,
224-
max_webhooks: self.config.max_webhooks_per_client,
225-
no_change,
226-
};
227229
event_queue_notifier.enqueue(LSPS5ServiceEvent::WebhookRegistered {
228230
counterparty_node_id,
229231
app_name: params.app_name.clone(),
@@ -232,9 +234,6 @@ where
232234
no_change,
233235
});
234236

235-
// Send webhook_registered notification if needed
236-
// According to spec:
237-
// "The LSP MUST send this notification to this webhook before sending any other notifications to this webhook."
238237
if !no_change {
239238
self.send_webhook_registered_notification(
240239
counterparty_node_id,
@@ -243,7 +242,15 @@ where
243242
);
244243
}
245244

246-
let msg = LSPS5Message::Response(request_id, LSPS5Response::SetWebhook(response)).into();
245+
let msg = LSPS5Message::Response(
246+
request_id,
247+
LSPS5Response::SetWebhook(SetWebhookResponse {
248+
num_webhooks: client_webhooks.len() as u32,
249+
max_webhooks: self.config.max_webhooks_per_client,
250+
no_change,
251+
}),
252+
)
253+
.into();
247254
self.pending_messages.enqueue(&counterparty_node_id, msg);
248255
Ok(())
249256
}

0 commit comments

Comments
 (0)