diff --git a/backend/server/api/protection/state.get.ts b/backend/server/api/protection/state.get.ts index d339de4..2d413f8 100644 --- a/backend/server/api/protection/state.get.ts +++ b/backend/server/api/protection/state.get.ts @@ -1,6 +1,7 @@ import { requireUser } from "../../utils/auth"; import { getActiveCooldown, resolveCooldown } from "../../db/cooldown"; import { getProfile } from "../../db/profile"; +import { usePrisma } from "../../utils/prisma"; /** * GET /api/protection/state @@ -18,11 +19,26 @@ export default defineEventHandler(async (event) => { let active = false; let remainingSeconds = 0; let cooldownEndsAt: string | null = null; + // True wenn dieser Request gerade einen abgelaufenen Cooldown resolved hat. + let cooldownJustResolved = false; if (cooldown) { const expired = now >= cooldown.cooldownEndsAt; if (expired) { await resolveCooldown(cooldown.id); + // Anti-Auto-Reactivation: Cooldown wurde durchgehalten → Schutz bleibt + // jetzt AUS, User muss explizit reaktivieren. MUSS hier passieren — + // dieser Endpoint wird alle 5s während Cooldown gepollt und gewinnt das + // Race gegen /api/cooldown/status fast immer. Ohne dieses Update bliebe + // protectionDisabledAt null → protectionShouldBeActive=true → Frontend- + // Bypass-Detection würde den Schutz automatisch wieder anschalten. + await usePrisma() + .profile.update({ + where: { id: user.id }, + data: { protectionDisabledAt: new Date() }, + }) + .catch(() => {}); + cooldownJustResolved = true; // After resolve: no active cooldown } else { active = true; @@ -42,7 +58,8 @@ export default defineEventHandler(async (event) => { // (protectionDisabledAt gesetzt) → Frontend macht KEINE Auto-Reactivation, // User muss explizit re-aktivieren via /api/protection/mark-active. // - true sonst (Normal-Zustand: Schutz sollte laufen) - const protectionShouldBeActive = !active && profile?.protectionDisabledAt === null; + const protectionShouldBeActive = + !active && profile?.protectionDisabledAt === null && !cooldownJustResolved; return { success: true,