From 58252606a63cec56ad6b2daca43b765961dc44c9 Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Wed, 7 Dec 2022 02:29:20 -0500 Subject: [PATCH] *Change logic to abort if the signature fails --- src/index.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/index.ts b/src/index.ts index 0d790c8..2509959 100644 --- a/src/index.ts +++ b/src/index.ts @@ -319,11 +319,13 @@ export default class DHTCache extends EventEmitter { let bufId = b4a.from(toId as Uint8Array) as Buffer; - if (signature && crypto.verify(bufData, signature, id)) { - this._addEntityConnection(id, bufId as Buffer); - this._setEntity(bufId as Buffer, { heartbeat: Date.now() }); + if (!(signature && crypto.verify(bufData, signature, id))) { + return; } + this._addEntityConnection(id, bufId as Buffer); + this._setEntity(bufId as Buffer, { heartbeat: Date.now() }); + this.log.debug( `Bootstrap response received from ${bufId.toString("hex")}` );