Skip to content

Commit 0fcb45d

Browse files
committed
Fix heartbeat ownership check: compare user_id not pubkey hash
The JWT claims.user_id is a hash (e.g. "5e38e312...") which matches the node_id from the join flow. The previous code ran it through normalize_pubkey() producing "ed25519:5e38e312..." which never matches the node's mgmt_pubkey ("ed25519:L9LKzhu..."). Now simply checks claims.user_id == hb_node_id.
1 parent 2a22da8 commit 0fcb45d

File tree

1 file changed

+5
-12
lines changed

1 file changed

+5
-12
lines changed

projects/LemonadeNexus/src/Api/MeshApiHandler.cpp

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -232,18 +232,11 @@ void MeshApiHandler::do_register_routes([[maybe_unused]] httplib::Server& pub,
232232
return;
233233
}
234234

235-
// Verify the caller owns this node via management pubkey (defense in depth)
236-
auto caller_pubkey = normalize_pubkey(claims.user_id);
237-
if (node_opt->mgmt_pubkey != caller_pubkey) {
238-
spdlog::warn("[MeshAPI] Heartbeat ownership mismatch: caller={} node_mgmt={}",
239-
caller_pubkey, node_opt->mgmt_pubkey);
240-
error_response(res, "insufficient permissions", 403);
241-
return;
242-
}
243-
244-
// Also verify the caller has EditNode permission (belt and suspenders)
245-
if (!ctx_.tree.check_permission(caller_pubkey, hb_node_id,
246-
acl::Permission::EditNode)) {
235+
// Verify the caller owns this node: the JWT user_id must match the
236+
// node_id being heartbeated (the node_id IS the user_id from join).
237+
if (claims.user_id != hb_node_id) {
238+
spdlog::warn("[MeshAPI] Heartbeat ownership mismatch: caller={} node={}",
239+
claims.user_id, hb_node_id);
247240
error_response(res, "insufficient permissions", 403);
248241
return;
249242
}

0 commit comments

Comments
 (0)