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 { export class LoginService {
private readonly users: User[]; private readonly users: User[];
private readonly sessionKey: string;
constructor(users: User[]) { constructor(users: User[], sessionKey: string) {
this.users = users; this.users = users;
this.sessionKey = sessionKey;
} }
public static officialLoginService(): LoginService { 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> { private async hashMessage(message: string): Promise<string> {
@@ -74,10 +79,21 @@ export class LoginService {
await ctx.cookies.set("phenix-session", `${maxUnixEpoch}`, { await ctx.cookies.set("phenix-session", `${maxUnixEpoch}`, {
maxAge: maxAgesInSecond, maxAge: maxAgesInSecond,
}); });
await ctx.cookies.set(
"phenix-session-sign",
await this.shittyHmac(`${maxUnixEpoch}`, this.sessionKey),
{
maxAge: maxAgesInSecond,
},
);
} }
async isLoggedIn(ctx: any): Promise<boolean> { async isLoggedIn(ctx: any): Promise<boolean> {
const expiration = await ctx.cookies.get("phenix-session"); 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)) { if (!expiration || !/^\d+$/.test(expiration)) {
return false; return false;
} }