This commit is contained in:
Spidershield-contrib 2026-07-07 00:50:58 +04:00 committed by GitHub
commit 4739107329
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -3,6 +3,17 @@
*/
import { IncomingMessage, ServerResponse } from "http";
import { timingSafeEqual, createHash } from "crypto";
function safeEqual(a: string, b: string): boolean {
try {
const hashA = createHash("sha256").update(a).digest();
const hashB = createHash("sha256").update(b).digest();
return timingSafeEqual(hashA, hashB);
} catch {
return false;
}
}
export class AuthMiddleware {
constructor(private authToken: string) {}
@ -19,7 +30,7 @@ export class AuthMiddleware {
if (!parsed) {
return false;
}
return parsed.token === this.authToken;
return safeEqual(parsed.token, this.authToken);
}
/**