mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 23:18:28 +00:00
fix(security): harden hook and device token auth
This commit is contained in:
16
src/security/secret-equal.ts
Normal file
16
src/security/secret-equal.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
import { timingSafeEqual } from "node:crypto";
|
||||
|
||||
export function safeEqualSecret(
|
||||
provided: string | undefined | null,
|
||||
expected: string | undefined | null,
|
||||
): boolean {
|
||||
if (typeof provided !== "string" || typeof expected !== "string") {
|
||||
return false;
|
||||
}
|
||||
const providedBuffer = Buffer.from(provided);
|
||||
const expectedBuffer = Buffer.from(expected);
|
||||
if (providedBuffer.length !== expectedBuffer.length) {
|
||||
return false;
|
||||
}
|
||||
return timingSafeEqual(providedBuffer, expectedBuffer);
|
||||
}
|
||||
Reference in New Issue
Block a user