Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.
TypeScript acmeagentsai-agentscertificate-managementdevsecopsenvironment-variableskubernetesopen-sourcepampkipostgresprivate-caprivileged-access-managementsecret-managementsecret-managersecretssecrets-managementsecuritysecurity-toolsvault
use checkbox on first recovery code shown
Thiago Araujo da Silva9bd5c2e04118
diff --git a/backend/src/server/routes/v1/user-router.ts b/backend/src/server/routes/v1/user-router.tsindex 8a000d8892..ea29c9b220 100644--- a/backend/src/server/routes/v1/user-router.ts+++ b/backend/src/server/routes/v1/user-router.ts@@ -306,7 +306,7 @@ export const registerUserRouter = async (server: FastifyZodProvider) => {})}},- onRequest: verifyAuth([AuthMode.JWT], { requireOrg: false }),+ onRequest: verifyAuth([AuthMode.JWT]),handler: async (req) => {await ensureStepUpMfa(server, {userId: req.permission.id,@@ -340,7 +340,7 @@ export const registerUserRouter = async (server: FastifyZodProvider) => {})}},- onRequest: verifyAuth([AuthMode.JWT], { requireOrg: false }),+ onRequest: verifyAuth([AuthMode.JWT]),handler: async (req) => {await ensureStepUpMfa(server, {userId: req.permission.id,diff --git a/backend/src/server/routes/v2/user-router.ts b/backend/src/server/routes/v2/user-router.tsindex 4d8122e90a..94b9258231 100644--- a/backend/src/server/routes/v2/user-router.ts+++ b/backend/src/server/routes/v2/user-router.ts@@ -53,7 +53,7 @@ export const registerUserRouter = async (server: FastifyZodProvider) => {})}},- preHandler: verifyAuth([AuthMode.JWT], { requireOrg: false }),+ preHandler: verifyAuth([AuthMode.JWT]),handler: async (req) => {const user = await server.services.user.setSelectedMfaMethod({userId: req.permission.id,@@ -222,7 +222,7 @@ export const registerUserRouter = async (server: FastifyZodProvider) => {})}},- preHandler: verifyAuth([AuthMode.JWT], { requireOrg: false }),+ preHandler: verifyAuth([AuthMode.JWT]),handler: async (req) => {await ensureStepUpMfa(server, {userId: req.permission.id,diff --git a/backend/src/services/user/user-service.ts b/backend/src/services/user/user-service.tsindex 3d14a74ced..5491efafa7 100644--- a/backend/src/services/user/user-service.ts+++ b/backend/src/services/user/user-service.ts@@ -189,12 +189,12 @@ export const userServiceFactory = ({}}- const updatedUser = await userDAL.updateById(userId, {- isMfaEnabled: false+ const updatedUser = await userDAL.transaction(async (tx) => {+ const updated = await userDAL.updateById(userId, { isMfaEnabled: false }, tx);+ await mfaRecoveryCodeService.deleteRecoveryCodes({ userId, tx });+ return updated;});- await mfaRecoveryCodeService.deleteRecoveryCodes({ userId });-return updatedUser;};diff --git a/frontend/src/components/auth/Mfa.tsx b/frontend/src/components/auth/Mfa.tsxindex 41c4f23b06..0263faa572 100644--- a/frontend/src/components/auth/Mfa.tsx+++ b/frontend/src/components/auth/Mfa.tsx@@ -9,6 +9,7 @@ import { MfaEnrollment } from "@app/components/mfa/MfaEnrollment";import { createNotification } from "@app/components/notifications";import SecurityClient from "@app/components/utilities/SecurityClient";import { Button, Tooltip } from "@app/components/v2";+import { Checkbox, FieldLabel } from "@app/components/v3";import { isInfisicalCloud } from "@app/helpers/platform";import { useActivateMfa, useLogoutUser, useSendMfaToken } from "@app/hooks/api";import {@@ -283,17 +284,20 @@ export const Mfa = ({ successCallback, closeMfa, hideLogo, email, method }: Propif (newRecoveryCodes) {return (<div className="mx-auto flex w-full max-w-md flex-col gap-4 pt-4 pb-4 md:mb-16 md:px-8">- <div className="text-center">- <h2 className="text-xl font-medium text-bunker-100">Save your recovery codes</h2>- <p className="mt-2 text-sm text-bunker-300">- Store these somewhere safe. Each code can be used once if you lose access to your second- factor. This is the only time they are shown.- </p>+ <RecoveryCodesStep recoveryCodes={newRecoveryCodes} />+ <div className="flex items-center gap-2">+ <Checkbox+ id="acknowledge-recovery-codes"+ isChecked={hasSavedRecoveryCodes}+ onCheckedChange={(checked) => setHasSavedRecoveryCodes(checked === true)}+ />+ <FieldLabel+ htmlFor="acknowledge-recovery-codes"+ className="cursor-pointer text-sm font-normal text-bunker-200"+ >+ I have saved my recovery codes in a safe place+ </FieldLabel></div>- <RecoveryCodesStep- recoveryCodes={newRecoveryCodes}- onSaved={() => setHasSavedRecoveryCodes(true)}- /><ButtoncolorSchema="primary"isFullWidthdiff --git a/frontend/src/components/mfa/setup/MethodStep.tsx b/frontend/src/components/mfa/setup/MethodStep.tsxdeleted file mode 100644index 6d4b7fc75d..0000000000--- a/frontend/src/components/mfa/setup/MethodStep.tsx+++ /dev/null@@ -1,47 +0,0 @@-import {- Field,- FieldContent,- FieldDescription,- FieldLabel,- FieldTitle,- RadioGroup,- RadioGroupItem-} from "@app/components/v3";-import { MfaMethod } from "@app/hooks/api/auth/types";--import { MFA_METHOD_OPTIONS } from "./types";--type Props = {- selectedMethod: MfaMethod;- onSelect: (method: MfaMethod) => void;-};--export const MethodStep = ({ selectedMethod, onSelect }: Props) => {- return (- <div className="flex flex-col gap-4">- <p className="text-sm text-muted">Choose the method you want to use as your second factor.</p>- <RadioGroup- value={selectedMethod}- onValueChange={(value) => onSelect(value as MfaMethod)}- className="gap-3"- >- {MFA_METHOD_OPTIONS.map((option) => {- const Icon = option.icon;- const id = `mfa-method-${option.value}`;- return (- <FieldLabel key={option.value} htmlFor={id}>- <Field orientation="horizontal">- <Icon />- <FieldContent>- <FieldTitle>{option.label}</FieldTitle>- <FieldDescription>{option.description}</FieldDescription>- </FieldContent>- <RadioGroupItem value={option.value} id={id} />- </Field>- </FieldLabel>- );- })}- </RadioGroup>- </div>- );-};diff --git a/frontend/src/components/mfa/setup/RecoveryCodesStep.tsx b/frontend/src/components/mfa/setup/RecoveryCodesStep.tsxindex 5965a046a5..5440753773 100644--- a/frontend/src/components/mfa/setup/RecoveryCodesStep.tsx+++ b/frontend/src/components/mfa/setup/RecoveryCodesStep.tsx@@ -1,4 +1,4 @@-import { InfoIcon, TriangleAlertIcon } from "lucide-react";+import { TriangleAlertIcon } from "lucide-react";import { Alert, AlertDescription, AlertTitle } from "@app/components/v3";@@ -6,28 +6,12 @@ import { RecoveryCodesView } from "./RecoveryCodesView";type Props = {recoveryCodes: string[];- onSaved: () => void;+ onSaved?: () => void;};-// Shared final step for the MFA enrollment and settings wizard: shows the newly-// minted recovery codes with a save prompt. When enabling MFA returned no codes-// (it was already on, so codes were generated during the original setup), show an-// informational note pointing to personal settings instead of an error.+// Shared final step of MFA setup: shows the newly minted recovery codes with a+// save prompt.export const RecoveryCodesStep = ({ recoveryCodes, onSaved }: Props) => {- if (recoveryCodes.length === 0) {- return (- <Alert variant="info">- <InfoIcon />- <AlertTitle>Two-factor authentication is already enabled</AlertTitle>- <AlertDescription>- Your recovery codes were generated when you first set up two-factor authentication. You- can view or regenerate them anytime from the Authentication section of your personal- settings.- </AlertDescription>- </Alert>- );- }-return (<><Alert variant="warning">diff --git a/frontend/src/components/mfa/setup/RecoveryCodesView.tsx b/frontend/src/components/mfa/setup/RecoveryCodesView.tsxindex 1e5135f1ac..5d8b1d5195 100644--- a/frontend/src/components/mfa/setup/RecoveryCodesView.tsx+++ b/frontend/src/components/mfa/setup/RecoveryCodesView.tsx@@ -1,6 +1,7 @@import { useState } from "react";import { CopyIcon, DownloadIcon } from "lucide-react";+import { createNotification } from "@app/components/notifications";import { Button } from "@app/components/v3";type Props = {@@ -32,7 +33,10 @@ export const RecoveryCodesView = ({ recoveryCodes, onSaved }: Props) => {setTimeout(() => setCopied(false), 2000);onSaved?.();} catch {- // ignore clipboard failures+ createNotification({+ text: "Failed to copy recovery codes. Please download them instead.",+ type: "error"+ });}};diff --git a/frontend/src/components/mfa/setup/VerifyStep.tsx b/frontend/src/components/mfa/setup/VerifyStep.tsxindex d9e83bec8e..ab7d054128 100644--- a/frontend/src/components/mfa/setup/VerifyStep.tsx+++ b/frontend/src/components/mfa/setup/VerifyStep.tsx@@ -87,10 +87,13 @@ const TotpVerify = ({ onVerified }: { onVerified: Props["onVerified"] }) => {);};+const RESEND_COOLDOWN_SECONDS = 60;+const EmailVerify = ({ onVerified }: { onVerified: Props["onVerified"] }) => {const { mutateAsync: sendCode } = useSendMfaEnrollmentEmailCode();const { mutateAsync: enrollMfa, isPending: isVerifying } = useEnrollMfa();const [code, setCode] = useState("");+ const [cooldown, setCooldown] = useState(RESEND_COOLDOWN_SECONDS);const hasSentInitialCode = useRef(false);// Send the first code automatically when the step mounts.@@ -102,6 +105,22 @@ const EmailVerify = ({ onVerified }: { onVerified: Props["onVerified"] }) => {});}, [sendCode]);+ useEffect(() => {+ if (cooldown <= 0) return undefined;+ const timer = setTimeout(() => setCooldown((prev) => prev - 1), 1000);+ return () => clearTimeout(timer);+ }, [cooldown]);++ const handleResend = async () => {+ try {+ await sendCode();+ setCooldown(RESEND_COOLDOWN_SECONDS);+ createNotification({ text: "Sent a new verification code", type: "success" });+ } catch {+ createNotification({ text: "Failed to send verification code", type: "error" });+ }+ };+const handleVerify = async () => {try {await enrollMfa({ method: MfaMethod.EMAIL, code: code.trim() });@@ -139,6 +158,9 @@ const EmailVerify = ({ onVerified }: { onVerified: Props["onVerified"] }) => {>Verify Code</Button>+ <Button variant="ghost" isDisabled={cooldown > 0} onClick={handleResend}>+ {cooldown > 0 ? `Resend code in ${cooldown}s` : "Resend code"}+ </Button></div></div>);diff --git a/frontend/src/components/mfa/setup/index.ts b/frontend/src/components/mfa/setup/index.tsindex 1baf22dcd6..3b43fb0b62 100644--- a/frontend/src/components/mfa/setup/index.ts+++ b/frontend/src/components/mfa/setup/index.ts@@ -1,6 +1,4 @@-export { MethodStep } from "./MethodStep";export { RecoveryCodesStep } from "./RecoveryCodesStep";export { RecoveryCodesView } from "./RecoveryCodesView";-export type { MfaMethodOption, WizardStep } from "./types";-export { MFA_METHOD_ICONS, MFA_METHOD_LABELS, MFA_METHOD_OPTIONS, WIZARD_STEPS } from "./types";+export { MFA_METHOD_ICONS, MFA_METHOD_LABELS } from "./types";export { VerifyStep } from "./VerifyStep";diff --git a/frontend/src/components/mfa/setup/types.ts b/frontend/src/components/mfa/setup/types.tsindex 8e2137d3fd..190a27f8b8 100644--- a/frontend/src/components/mfa/setup/types.ts+++ b/frontend/src/components/mfa/setup/types.ts@@ -2,30 +2,20 @@ import { FingerprintIcon, LucideIcon, MailIcon, SmartphoneIcon } from "lucide-reimport { MfaMethod } from "@app/hooks/api/auth/types";-export type MfaMethodOption = {- value: MfaMethod;- label: string;- description: string;- icon: LucideIcon;-};--export const MFA_METHOD_OPTIONS: MfaMethodOption[] = [+const MFA_METHOD_OPTIONS: { value: MfaMethod; label: string; icon: LucideIcon }[] = [{value: MfaMethod.TOTP,label: "Authenticator app",- description: "Use a TOTP app like 1Password or Authy.",icon: SmartphoneIcon},{value: MfaMethod.EMAIL,label: "Email",- description: "Receive one-time codes by email.",icon: MailIcon},{value: MfaMethod.WEBAUTHN,label: "Passkey",- description: "Use Face ID, Touch ID, a security key, or your device.",icon: FingerprintIcon}];@@ -39,15 +29,3 @@ export const MFA_METHOD_ICONS = MFA_METHOD_OPTIONS.reduce((acc, option) => ({ ...acc, [option.value]: option.icon }),{} as Record<MfaMethod, LucideIcon>);--export type WizardStep = {- key: "method" | "verify" | "recovery";- title: string;- description: string;-};--export const WIZARD_STEPS: WizardStep[] = [- { key: "method", title: "Method", description: "Choose method" },- { key: "verify", title: "Verify", description: "Confirm it works" },- { key: "recovery", title: "Recovery", description: "Save backup codes" }-];diff --git a/frontend/src/pages/user/PersonalSettingsPage/components/SecuritySection/MFASection.tsx b/frontend/src/pages/user/PersonalSettingsPage/components/SecuritySection/MFASection.tsxindex 214fea32c2..b8bae9c3d0 100644--- a/frontend/src/pages/user/PersonalSettingsPage/components/SecuritySection/MFASection.tsx+++ b/frontend/src/pages/user/PersonalSettingsPage/components/SecuritySection/MFASection.tsx@@ -15,6 +15,8 @@ import {AlertDialogTitle,Badge,Button,+ Checkbox,+ FieldLabel,Select,SelectContent,SelectItem,@@ -23,6 +25,7 @@ import {Sheet,SheetContent,SheetDescription,+ SheetFooter,SheetHeader,SheetTitle} from "@app/components/v3";@@ -52,6 +55,14 @@ export const MFASection = () => {const [isDisableOpen, setIsDisableOpen] = useState(false);// Holds the fresh recovery codes returned on enable so they can be shown once.const [newRecoveryCodes, setNewRecoveryCodes] = useState<string[] | null>(null);+ // Gate closing the "save your codes" sheet until the user acknowledges they+ // saved them, since this is the only time the freshly minted codes are shown.+ const [hasAcknowledgedCodes, setHasAcknowledgedCodes] = useState(false);++ const closeRecoveryCodesSheet = () => {+ setNewRecoveryCodes(null);+ setHasAcknowledgedCodes(false);+ };if (isPending || !user) {return <ContentLoader />;@@ -234,9 +245,17 @@ export const MFASection = () => {<Sheetopen={newRecoveryCodes !== null}- onOpenChange={(open) => !open && setNewRecoveryCodes(null)}+ onOpenChange={(open) => {+ if (!open && hasAcknowledgedCodes) closeRecoveryCodesSheet();+ }}>- <SheetContent side="right" className="flex flex-col gap-0 sm:max-w-lg">+ <SheetContent+ side="right"+ className="flex flex-col gap-0 sm:max-w-lg"+ // Block accidental dismissal so the one-time codes aren't lost.+ onInteractOutside={(e) => !hasAcknowledgedCodes && e.preventDefault()}+ onEscapeKeyDown={(e) => !hasAcknowledgedCodes && e.preventDefault()}+ ><SheetHeader className="border-b"><SheetTitle>Save your recovery codes</SheetTitle><SheetDescription>@@ -247,6 +266,29 @@ export const MFASection = () => {<div className="min-h-0 flex-1 overflow-y-auto px-4 py-5"><RecoveryCodesView recoveryCodes={newRecoveryCodes ?? []} /></div>+ <SheetFooter className="flex-col items-stretch gap-3 border-t">+ <div className="flex items-center gap-2">+ <Checkbox+ id="acknowledge-recovery-codes"+ isChecked={hasAcknowledgedCodes}+ onCheckedChange={(checked) => setHasAcknowledgedCodes(checked === true)}+ />+ <FieldLabel+ htmlFor="acknowledge-recovery-codes"+ className="cursor-pointer text-sm font-normal text-foreground"+ >+ I have saved my recovery codes in a safe place+ </FieldLabel>+ </div>+ <Button+ variant="org"+ isFullWidth+ isDisabled={!hasAcknowledgedCodes}+ onClick={closeRecoveryCodesSheet}+ >+ Done+ </Button>+ </SheetFooter></SheetContent></Sheet></>