Skip to content

Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.

fix lint

Thiago Araujo da Silva409d06f12c96
diff --git a/backend/src/server/routes/v2/user-router.ts b/backend/src/server/routes/v2/user-router.ts
index 94b9258231..ec299f150f 100644
--- a/backend/src/server/routes/v2/user-router.ts
+++ b/backend/src/server/routes/v2/user-router.ts
@@ -70,6 +70,9 @@ export const registerUserRouter = async (server: FastifyZodProvider) => {
// the org-required MFA is actually completed (on the first successful verifyMfaToken,
// or via POST /me/mfa/activate from a full authenticated session). This keeps a
// password-only, pre-MFA session from bootstrapping recovery codes.
+ //
+ // Email is not an enrollable factor here: it is always available (it uses the
+ // account email) and needs no per-user setup, so only TOTP and WebAuthn are enrolled.
server.route({
method: "POST",
url: "/me/mfa/enroll",
@@ -79,10 +82,6 @@ export const registerUserRouter = async (server: FastifyZodProvider) => {
schema: {
operationId: "enrollUserMfa",
body: z.discriminatedUnion("method", [
- z.object({
- method: z.literal(MfaMethod.EMAIL),
- code: z.string().trim()
- }),
z.object({
method: z.literal(MfaMethod.TOTP),
totp: z.string().trim()
@@ -112,12 +111,7 @@ export const registerUserRouter = async (server: FastifyZodProvider) => {
},
preHandler: verifyAuth([AuthMode.JWT], { requireOrg: false }),
handler: async (req) => {
- if (req.body.method === MfaMethod.EMAIL) {
- await server.services.user.verifyMfaEnrollmentEmailCode({
- userId: req.permission.id,
- code: req.body.code
- });
- } else if (req.body.method === MfaMethod.TOTP) {
+ if (req.body.method === MfaMethod.TOTP) {
await server.services.totp.verifyUserTotpConfig({
userId: req.permission.id,
totp: req.body.totp
@@ -134,32 +128,6 @@ export const registerUserRouter = async (server: FastifyZodProvider) => {
}
});
- // Email enrollment begin: emails a one-time code the user submits to POST
- // /me/mfa/enroll to prove control of the account inbox before codes are minted.
- server.route({
- method: "POST",
- url: "/me/mfa/enroll/email/code",
- config: {
- rateLimit: smtpRateLimit({
- keyGenerator: (req) => req.permission?.id ?? req.realIp
- })
- },
- schema: {
- operationId: "sendMfaEnrollmentEmailCode",
- response: {
- 200: z.object({})
- }
- },
- preHandler: verifyAuth([AuthMode.JWT], { requireOrg: false }),
- handler: async (req) => {
- await server.services.user.sendMfaEnrollmentEmailCode({
- userId: req.permission.id
- });
-
- return {};
- }
- });
-
// Enable MFA from a fully authenticated session (personal settings). Issues a
// fresh recovery-code pool (invalidating any prior codes), returned once so the
// client can surface them.
diff --git a/backend/src/services/auth-token/auth-token-service.ts b/backend/src/services/auth-token/auth-token-service.ts
index 32d44dd1fb..50253279be 100644
--- a/backend/src/services/auth-token/auth-token-service.ts
+++ b/backend/src/services/auth-token/auth-token-service.ts
@@ -70,8 +70,7 @@ export const getTokenConfig = (tokenType: TokenType) => {
const expiresAt = new Date(new Date().getTime() + 600000);
return { token, triesLeft, expiresAt };
}
- case TokenType.TOKEN_EMAIL_MFA:
- case TokenType.TOKEN_EMAIL_MFA_ENROLLMENT: {
+ case TokenType.TOKEN_EMAIL_MFA: {
const token = generateSixDigitToken();
const triesLeft = 3;
const expiresAt = new Date(new Date().getTime() + 300000);
diff --git a/backend/src/services/auth-token/auth-token-types.ts b/backend/src/services/auth-token/auth-token-types.ts
index 4d9ded865a..69423ebded 100644
--- a/backend/src/services/auth-token/auth-token-types.ts
+++ b/backend/src/services/auth-token/auth-token-types.ts
@@ -5,7 +5,6 @@ export enum TokenType {
TOKEN_EMAIL_CHANGE_OTP = "emailChangeOtp",
TOKEN_EMAIL_CHANGE_CURRENT_OTP = "emailChangeCurrentOtp",
TOKEN_EMAIL_MFA = "emailMfa",
- TOKEN_EMAIL_MFA_ENROLLMENT = "emailMfaEnrollment",
TOKEN_EMAIL_ORG_INVITATION = "organizationInvitation",
TOKEN_EMAIL_PASSWORD_RESET = "passwordReset",
TOKEN_EMAIL_PASSWORD_SETUP = "passwordSetup",
diff --git a/backend/src/services/user/user-service.ts b/backend/src/services/user/user-service.ts
index 5491efafa7..5fc74b33f9 100644
--- a/backend/src/services/user/user-service.ts
+++ b/backend/src/services/user/user-service.ts
@@ -26,11 +26,9 @@ import {
TActivateUserMfaDTO,
TDeactivateUserMfaDTO,
TListUserGroupsDTO,
- TSendMfaEnrollmentEmailCodeDTO,
TSetSelectedMfaMethodDTO,
TUpdateUserEmailDTO,
- TVerifyCurrentEmailOTPDTO,
- TVerifyMfaEnrollmentEmailCodeDTO
+ TVerifyCurrentEmailOTPDTO
} from "./user-types";
type TUserServiceFactoryDep = {
@@ -208,41 +206,6 @@ export const userServiceFactory = ({
return userDAL.updateById(userId, { selectedMfaMethod });
};
- // Email enrollment begin: sends a one-time code to the account email so control
- // of the inbox can be proven before recovery codes are minted (mirrors the login
- // MFA email code, but scoped to a dedicated enrollment token type).
- const sendMfaEnrollmentEmailCode = async ({ userId }: TSendMfaEnrollmentEmailCodeDTO) => {
- const user = await userDAL.findById(userId);
- if (!user || !user.email) throw new BadRequestError({ name: "Failed to send MFA enrollment code" });
-
- const code = await tokenService.createTokenForUser({
- type: TokenType.TOKEN_EMAIL_MFA_ENROLLMENT,
- userId
- });
-
- await smtpService.sendMail({
- template: SmtpTemplates.EmailMfa,
- subjectLine: "Infisical MFA code",
- recipients: [user.email],
- substitutions: {
- code
- }
- });
- };
-
- // Email enrollment proof: throws unless the code matches the one emailed above.
- const verifyMfaEnrollmentEmailCode = async ({ userId, code }: TVerifyMfaEnrollmentEmailCodeDTO) => {
- try {
- await tokenService.validateTokenForUser({
- type: TokenType.TOKEN_EMAIL_MFA_ENROLLMENT,
- userId,
- code
- });
- } catch (error) {
- throw new BadRequestError({ message: "Invalid verification code", name: "VerifyMfaEnrollmentEmailCode" });
- }
- };
-
const updateUserName = async (userId: string, firstName: string, lastName: string) => {
const updatedUser = await userDAL.updateById(userId, {
firstName,
@@ -672,8 +635,6 @@ export const userServiceFactory = ({
activateMfa,
deactivateMfa,
setSelectedMfaMethod,
- sendMfaEnrollmentEmailCode,
- verifyMfaEnrollmentEmailCode,
updateUserName,
updateAuthMethods,
requestEmailChangeOTP,
diff --git a/backend/src/services/user/user-types.ts b/backend/src/services/user/user-types.ts
index 1041fb90da..bd522d108e 100644
--- a/backend/src/services/user/user-types.ts
+++ b/backend/src/services/user/user-types.ts
@@ -25,15 +25,6 @@ export type TSetSelectedMfaMethodDTO = {
selectedMfaMethod: MfaMethod;
};
-export type TSendMfaEnrollmentEmailCodeDTO = {
- userId: string;
-};
-
-export type TVerifyMfaEnrollmentEmailCodeDTO = {
- userId: string;
- code: string;
-};
-
export type TUpdateUserEmailDTO = {
userId: string;
newEmail: string;
diff --git a/frontend/src/components/mfa/setup/RecoveryCodesView.tsx b/frontend/src/components/mfa/setup/RecoveryCodesView.tsx
index 5d8b1d5195..de3c39bc66 100644
--- a/frontend/src/components/mfa/setup/RecoveryCodesView.tsx
+++ b/frontend/src/components/mfa/setup/RecoveryCodesView.tsx
@@ -45,7 +45,7 @@ export const RecoveryCodesView = ({ recoveryCodes, onSaved }: Props) => {
<div className="rounded-lg border border-border bg-container p-4">
<div className="grid grid-cols-2 gap-x-6 gap-y-2 font-mono text-sm">
{recoveryCodes.map((code, index) => (
- <div key={`${code}-${index}`} className="flex items-center text-foreground">
+ <div key={code} className="flex items-center text-foreground">
<span className="w-6 text-right text-muted">{index + 1}.</span>
<span className="pl-2">{code}</span>
</div>
diff --git a/frontend/src/components/mfa/setup/VerifyStep.tsx b/frontend/src/components/mfa/setup/VerifyStep.tsx
index ab7d054128..50ba50082b 100644
--- a/frontend/src/components/mfa/setup/VerifyStep.tsx
+++ b/frontend/src/components/mfa/setup/VerifyStep.tsx
@@ -1,16 +1,12 @@
-import { useEffect, useRef, useState } from "react";
-import { FingerprintIcon, MailIcon } from "lucide-react";
+import { useEffect, useState } from "react";
+import { FingerprintIcon } from "lucide-react";
import QRCode from "qrcode";
import { createNotification } from "@app/components/notifications";
import { ContentLoader } from "@app/components/v2";
import { Button, Input } from "@app/components/v3";
import { MfaMethod } from "@app/hooks/api/auth/types";
-import {
- useEnrollMfa,
- useGetUserTotpRegistration,
- useSendMfaEnrollmentEmailCode
-} from "@app/hooks/api/users";
+import { useEnrollMfa, useGetUserTotpRegistration } from "@app/hooks/api/users";
import { useRegisterPasskey } from "@app/hooks/api/webauthn";
type Props = {
@@ -87,85 +83,6 @@ 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.
- useEffect(() => {
- if (hasSentInitialCode.current) return;
- hasSentInitialCode.current = true;
- sendCode().catch(() => {
- createNotification({ text: "Failed to send verification code", type: "error" });
- });
- }, [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() });
- createNotification({ text: "Email authentication configured", type: "success" });
- await onVerified();
- } catch (error: any) {
- createNotification({
- text: error?.response?.data?.message || "Invalid verification code",
- type: "error"
- });
- }
- };
-
- return (
- <div className="flex flex-col gap-4">
- <div className="flex items-start gap-3 rounded-lg border border-border bg-container p-4">
- <MailIcon className="mt-0.5 text-muted" />
- <p className="text-sm text-muted">
- We sent a one-time code to your account email. Enter it below to confirm you can receive
- codes. A code will be sent the same way each time you sign in.
- </p>
- </div>
- <Input
- value={code}
- onChange={(e) => setCode(e.target.value.replace(/\D/g, "").slice(0, 6))}
- placeholder="Enter 6-digit code"
- maxLength={6}
- />
- <div className="flex items-center gap-3">
- <Button
- variant="org"
- isPending={isVerifying}
- isDisabled={code.trim().length !== 6}
- onClick={handleVerify}
- >
- Verify Code
- </Button>
- <Button variant="ghost" isDisabled={cooldown > 0} onClick={handleResend}>
- {cooldown > 0 ? `Resend code in ${cooldown}s` : "Resend code"}
- </Button>
- </div>
- </div>
- );
-};
-
const WebAuthnVerify = ({ onVerified }: { onVerified: Props["onVerified"] }) => {
const { registerPasskey, isRegistering } = useRegisterPasskey();
const { mutateAsync: enrollMfa } = useEnrollMfa();
@@ -204,6 +121,5 @@ const WebAuthnVerify = ({ onVerified }: { onVerified: Props["onVerified"] }) =>
export const VerifyStep = ({ method, onVerified }: Props) => {
if (method === MfaMethod.TOTP) return <TotpVerify onVerified={onVerified} />;
- if (method === MfaMethod.EMAIL) return <EmailVerify onVerified={onVerified} />;
return <WebAuthnVerify onVerified={onVerified} />;
};
diff --git a/frontend/src/hooks/api/users/index.tsx b/frontend/src/hooks/api/users/index.tsx
index 98fc60a9ac..24768dd50b 100644
--- a/frontend/src/hooks/api/users/index.tsx
+++ b/frontend/src/hooks/api/users/index.tsx
@@ -30,7 +30,6 @@ export {
useLogoutUser,
useRegisterUserAction,
useRevokeMySessions,
- useSendMfaEnrollmentEmailCode,
useSetMfaMethod,
useUpdateOrgMembership,
useUpdateUserAuthMethods
diff --git a/frontend/src/hooks/api/users/queries.tsx b/frontend/src/hooks/api/users/queries.tsx
index ba740224d7..0079b8f58c 100644
--- a/frontend/src/hooks/api/users/queries.tsx
+++ b/frontend/src/hooks/api/users/queries.tsx
@@ -416,7 +416,6 @@ export const useEnrollMfa = () => {
return useMutation({
mutationFn: async (
dto:
- | { method: MfaMethod.EMAIL; code: string }
| { method: MfaMethod.TOTP; totp: string }
| {
method: MfaMethod.WEBAUTHN;
@@ -436,15 +435,6 @@ export const useEnrollMfa = () => {
});
};
-// Email enrollment begin: emails a one-time code to the account address that the
-// user submits via useEnrollMfa to prove inbox control before codes are minted.
-export const useSendMfaEnrollmentEmailCode = () =>
- useMutation({
- mutationFn: async () => {
- await apiRequest.post("/api/v2/users/me/mfa/enroll/email/code");
- }
- });
-
// Enable MFA. Issues a fresh recovery-code pool (invalidating any prior codes)
// and returns it once so the caller can display it to the user.
export const useActivateMfa = () => {