mirror of
https://github.com/Elysola/WebHooker.git
synced 2026-11-21 01:23:40 +00:00
fix(admin): guard revisions and tenant targets
Read-time authorization alone cannot protect concurrent edits. Guard revisions, current roles and destination ownership in the write transaction, and use per-group endpoints for isolated changes.
This commit is contained in:
1 parent
4fc784ab9f
commit
2ec541ad7c
10 files changed
+2615
-300
No files matched your search
@@ -1,7 +1,7 @@
|
||||
import type { H3Event } from "h3";
|
||||
import { createError, getHeader } from "h3";
|
||||
import type { Group, GroupRole } from "../types";
|
||||
import { getAdminSession, isDebugMode, type AdminSession } from "./session";
|
||||
import { authLogin, getAdminSession, isDebugMode, type AdminSession } from "./session";
|
||||
import {
|
||||
loadGroups,
|
||||
resolveScope,
|
||||
@@ -28,14 +28,15 @@ const AUTH_KEY = "auth";
|
||||
export async function loadAuth(event: H3Event): Promise<AuthContext | null> {
|
||||
const env = cfEnv(event);
|
||||
initConfigStore(env);
|
||||
const groups = await loadGroups(env.KV);
|
||||
if (isDebugMode(env)) {
|
||||
const session: AdminSession = { userId: "debug", login: "debug" };
|
||||
return { session, scope: resolveScope(env, groups, session.userId, session.login), groups };
|
||||
}
|
||||
const session = await getAdminSession(env.KV, getHeader(event, "cookie"));
|
||||
// The session first: a request without one reads no configuration.
|
||||
const session: AdminSession | null = isDebugMode(env)
|
||||
? { userId: "debug", login: "debug" }
|
||||
: await getAdminSession(env.KV, getHeader(event, "cookie"), env.DB);
|
||||
if (!session) return null;
|
||||
const scope = resolveScope(env, groups, session.userId, session.login);
|
||||
// Access checks read the authoritative store: a membership revoked in
|
||||
// another isolate must not linger in this one's cache.
|
||||
const groups = await loadGroups(env.KV, { fresh: true });
|
||||
const scope = resolveScope(env, groups, session.userId, authLogin(session));
|
||||
return { session, scope, groups };
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user