In order to minimise the window of opportunity to steal a session, automatically rotate it onto a new session on a frequent basis. This makes a session cookie older than the automatic rollover time less likely to grant access and more likely to be detected. Should a stolen session cookie get rotated while the attacker is using it, the user will be notificed that their session has been taken the next time they open the app if the user re-visits the website before the session is discarded.
24 lines
717 B
TypeScript
24 lines
717 B
TypeScript
/*
|
|
SPDX-FileCopyrightText: © 2025 Hornwitser <code@hornwitser.no>
|
|
SPDX-License-Identifier: AGPL-3.0-or-later
|
|
*/
|
|
import { readSubscriptions, readUsers } from "~/server/database";
|
|
import type { ApiSession } from "~/shared/types/api";
|
|
|
|
export default defineEventHandler(async (event): Promise<ApiSession | undefined> => {
|
|
const session = await getServerSession(event, false);
|
|
if (!session)
|
|
return;
|
|
const users = await readUsers();
|
|
const account = users.find(user => user.id === session.accountId);
|
|
const subscriptions = await readSubscriptions();
|
|
const push = Boolean(
|
|
subscriptions.find(sub => sub.type === "push" && sub.sessionId === session.id)
|
|
);
|
|
|
|
return {
|
|
id: session.id,
|
|
account,
|
|
push,
|
|
};
|
|
})
|