added the worst kind of security ever

This commit is contained in:
didier committed 2024-07-02 19:43:24 -04:00
1 parent cd45813228
commit 95a8ed5ffa
1 file changed
+18 -2
+18 -2
View File
@@ -15,13 +15,18 @@ const officialUsers: User[] = [
export class LoginService {
private readonly users: User[];
private readonly sessionKey: string;
constructor(users: User[]) {
constructor(users: User[], sessionKey: string) {
this.users = users;
this.sessionKey = sessionKey;
}
public static officialLoginService(): LoginService {
return new LoginService(officialUsers);
return new LoginService(
officialUsers,
Deno.env.get("SESSION_KEY") || "dev-only",
);
}
private async hashMessage(message: string): Promise<string> {
@@ -74,10 +79,21 @@ export class LoginService {
await ctx.cookies.set("phenix-session", `${maxUnixEpoch}`, {
maxAge: maxAgesInSecond,
});
await ctx.cookies.set(
"phenix-session-sign",
await this.shittyHmac(`${maxUnixEpoch}`, this.sessionKey),
{
maxAge: maxAgesInSecond,
},
);
}
async isLoggedIn(ctx: any): Promise<boolean> {
const expiration = await ctx.cookies.get("phenix-session");
const signature = await ctx.cookies.get("phenix-session-sign");
if (signature !== (await this.shittyHmac(expiration, this.sessionKey))) {
return false;
}
if (!expiration || !/^\d+$/.test(expiration)) {
return false;
}