Refresh HiveGrid Cloud reference snapshot
This commit is contained in:
1 parent
5e99e14772
commit
7f88026f79
5955 files changed
+1177325
-188362
No files matched your search
+41
-7
@@ -1,5 +1,8 @@
|
||||
import { hashIp, lookupCountry } from "~/modules/ipAddress/services/geoip.server";
|
||||
import { getClientIPAddress } from "~/utils/server/IpUtils";
|
||||
import { getTrustedClientIpOrNull } from "~/utils/server/IpUtils";
|
||||
import { loadRequiredWebConfig } from "@hivegrid/config";
|
||||
import { createAdminSession, revokeAdminSessionByToken } from "@hivegrid/db/admin-sessions.server";
|
||||
import { getHostRoutingContext, getRequestRoutingHost } from "~/utils/app/HostRouting.server";
|
||||
|
||||
import { createUserSession as createServerSessionRow, revokeSessionByToken } from "./sessionStore.server";
|
||||
|
||||
@@ -8,7 +11,7 @@ import { createUserSession as createServerSessionRow, revokeSessionByToken } fro
|
||||
// gefuehrt, damit Geraeteliste, Revoke und "ueberall abmelden" greifen.
|
||||
|
||||
export function extractRawClientIp(request: Request): string | null {
|
||||
return getClientIPAddress(request.headers)?.toString() ?? null;
|
||||
return getTrustedClientIpOrNull(request);
|
||||
}
|
||||
|
||||
// AD-22: persistiert KEINE Klartext-IP. Die IP wird gehasht (hashIp, Wiedererkennung "gleiches
|
||||
@@ -23,15 +26,46 @@ export async function buildSessionDeviceContext(request: Request): Promise<{ ipH
|
||||
};
|
||||
}
|
||||
|
||||
// Beim Login/Signup aufgerufen: legt die Session-Zeile mit (pseudonymisiertem) Geraete-Kontext an und
|
||||
// liefert den rohen Token zurueck, der ins Cookie wandert. Best-effort: ein Store-Fehler darf den Login
|
||||
// nicht verhindern (Cookie ist Source-of-Truth fuer die Identitaet).
|
||||
export async function startServerSession({ request, userId }: { request: Request; userId: string }): Promise<string | null> {
|
||||
// Every authenticated cookie is backed by this row. Store failures propagate
|
||||
// so callers cannot issue an unrevocable fallback cookie.
|
||||
export async function startServerSession({
|
||||
request,
|
||||
userId,
|
||||
adminAuthenticationMethods,
|
||||
adminMfaAssuredAt,
|
||||
}: {
|
||||
request: Request;
|
||||
userId: string;
|
||||
adminAuthenticationMethods?: readonly string[];
|
||||
adminMfaAssuredAt?: Date;
|
||||
}): Promise<string> {
|
||||
const context = await buildSessionDeviceContext(request);
|
||||
const routing = loadRequiredWebConfig().routing;
|
||||
const host = getRequestRoutingHost(request, new URL(request.url), routing);
|
||||
if (getHostRoutingContext(host, routing) === "admin") {
|
||||
if (!adminAuthenticationMethods || !adminMfaAssuredAt) {
|
||||
throw new Error("Admin server session requires Authentik MFA assurance");
|
||||
}
|
||||
const { rawToken } = await createAdminSession({
|
||||
adminUserId: userId,
|
||||
authenticationMethods: adminAuthenticationMethods,
|
||||
mfaAssuredAt: adminMfaAssuredAt,
|
||||
...context,
|
||||
});
|
||||
return rawToken;
|
||||
}
|
||||
const { rawToken } = await createServerSessionRow({ userId, ...context });
|
||||
return rawToken;
|
||||
}
|
||||
|
||||
export async function endServerSession(rawToken: string | undefined | null): Promise<void> {
|
||||
export async function endServerSession(rawToken: string | undefined | null, request?: Request): Promise<void> {
|
||||
if (request) {
|
||||
const routing = loadRequiredWebConfig().routing;
|
||||
const host = getRequestRoutingHost(request, new URL(request.url), routing);
|
||||
if (getHostRoutingContext(host, routing) === "admin") {
|
||||
await revokeAdminSessionByToken(rawToken);
|
||||
return;
|
||||
}
|
||||
}
|
||||
await revokeSessionByToken(rawToken);
|
||||
}
|
||||
Reference in new issue
Block a user