mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-17 23:52:24 +00:00
feat(security): let an operator require a second factor
Wire the previously-unused mfaEnforced flag into a real policy. An admin can require a second factor instance-wide (an AppSettings toggle in the General section) or per user (a toggle in user management); the effective requirement is the OR of the two. When required and the account has no active factor — no confirmed TOTP, no registered security key, and no primary passkey — the user is walled behind a forced-enrollment interstitial after sign-in, with only the security settings and sign-out reachable until a factor is enrolled. The gate is surfaced like the onboarding gate: a hint cookie the proxy reads without a DB round-trip, recomputed from the database on every sign-in and on /api/auth/me so a tampered cookie self-corrects. Nobody is locked out — the enrollment surface stays reachable, and toggling the policy off (or the disable-mfa CLI) is the operator's recovery path.
This commit is contained in:
1 parent
135bb04f0d
commit
c8bef61344
22 files changed
+431
-8
No files matched your search
@@ -0,0 +1,62 @@
|
||||
"use client";
|
||||
|
||||
import { ShieldAlert, LogOut, Loader2 } from "lucide-react";
|
||||
|
||||
import { Logo } from "@/components/ui/logo";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { SecuritySection } from "@/components/settings/security-section";
|
||||
import { useLogout } from "@/hooks/use-auth";
|
||||
import { useTranslations } from "@/lib/i18n/context";
|
||||
|
||||
/**
|
||||
* v1.23 — forced second-factor enrollment interstitial.
|
||||
*
|
||||
* The proxy redirects here whenever the operator requires MFA and the account
|
||||
* has no active second factor (the `hl_mfa_enroll=required` hint cookie). It
|
||||
* reuses the security hub's enrollment cards (TOTP + security keys); the moment
|
||||
* a factor is confirmed the enrollment route clears the hint cookie and the
|
||||
* next navigation lands wherever the user was headed. A sign-out button keeps
|
||||
* the only other escape — the user is never trapped, and the operator's CLI
|
||||
* (`scripts/disable-mfa.ts`) / instance toggle is the recovery of last resort.
|
||||
*/
|
||||
export default function EnrollMfaPage() {
|
||||
const { t } = useTranslations();
|
||||
const logout = useLogout();
|
||||
|
||||
return (
|
||||
<div className="mx-auto flex w-full max-w-xl flex-col gap-6 px-4 py-10">
|
||||
<div className="flex flex-col items-center gap-3 text-center">
|
||||
<div className="bg-primary/10 flex h-12 w-12 items-center justify-center rounded-lg">
|
||||
<Logo className="text-primary" size={28} />
|
||||
</div>
|
||||
<div className="space-y-2">
|
||||
<div className="text-foreground inline-flex items-center gap-2 text-lg font-semibold">
|
||||
<ShieldAlert className="text-primary h-5 w-5" aria-hidden="true" />
|
||||
{t("auth.enrollMfa.title")}
|
||||
</div>
|
||||
<p className="text-muted-foreground text-sm">
|
||||
{t("auth.enrollMfa.body")}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<SecuritySection />
|
||||
|
||||
<div className="flex justify-center">
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
onClick={() => logout.mutate()}
|
||||
disabled={logout.isPending}
|
||||
>
|
||||
{logout.isPending ? (
|
||||
<Loader2 className="h-4 w-4 animate-spin motion-reduce:animate-none" />
|
||||
) : (
|
||||
<LogOut className="h-4 w-4" />
|
||||
)}
|
||||
{t("auth.enrollMfa.signOut")}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user