Authentifizierung mit serverseitigen Sitzungen, CSRF und Rollen

Passwoerter mit Argon2id, im Cookie steht nur ein Token und in der Datenbank
dessen Hash. Das CSRF-Token wird per HMAC aus dem Sitzungstoken abgeleitet
statt separat gespeichert - ohne das httpOnly-Cookie ist es nicht herstellbar.

TOTP ist optional und wird erst nach einem bestaetigten Code scharf geschaltet,
damit sich niemand bei der Einrichtung aussperrt.
This commit is contained in:
2026-09-18 11:33:25 +02:00
parent a1b764155a
commit 3d2b87297e
7 changed files with 336 additions and 0 deletions
+18
View File
@@ -0,0 +1,18 @@
export class AppError extends Error {
constructor(
readonly statusCode: number,
readonly code: string,
message: string,
) {
super(message);
this.name = 'AppError';
}
}
export const badRequest = (code: string, message: string) => new AppError(400, code, message);
export const unauthorized = (message = 'Nicht angemeldet') =>
new AppError(401, 'UNAUTHORIZED', message);
export const forbidden = (message = 'Keine Berechtigung fuer diese Aktion') =>
new AppError(403, 'FORBIDDEN', message);
export const notFound = (what: string) => new AppError(404, 'NOT_FOUND', `${what} nicht gefunden`);
export const conflict = (code: string, message: string) => new AppError(409, code, message);