Replace password comparison with timingSafeEqual
This commit is contained in:
@@ -122,7 +122,8 @@ export const app = new Elysia()
|
|||||||
|
|
||||||
// AUTHENTICATION
|
// AUTHENTICATION
|
||||||
.post("/auth/login", async ({ jwt, body, cookie: { auth } }) => {
|
.post("/auth/login", async ({ jwt, body, cookie: { auth } }) => {
|
||||||
if (body.password !== env.ADMIN_PASSWORD) throw status(401, "Invalid credentials");
|
const match = crypto.timingSafeEqual(Buffer.from(body.password, "hex"), Buffer.from(env.ADMIN_PASSWORD, "hex"));
|
||||||
|
if (!match) throw status(401, "Invalid credentials");
|
||||||
|
|
||||||
auth.set({
|
auth.set({
|
||||||
value: await jwt.sign({ sessionId: randomUUIDv7(), exp: JWT_EXP }),
|
value: await jwt.sign({ sessionId: randomUUIDv7(), exp: JWT_EXP }),
|
||||||
|
|||||||
Reference in New Issue
Block a user