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
remove unused column
Thiago Araujo da Silvaf20311213a4d
diff --git a/backend/src/db/migrations/20260706120000_drop-user-mfa-methods.ts b/backend/src/db/migrations/20260706120000_drop-user-mfa-methods.tsnew file mode 100644index 0000000000..22e6536a39--- /dev/null+++ b/backend/src/db/migrations/20260706120000_drop-user-mfa-methods.ts@@ -0,0 +1,22 @@+import { Knex } from "knex";++import { TableName } from "../schemas";++// The users.mfaMethods text[] column is a leftover from the original MFA design. It was only+// ever written (to ["email"] / []) and never read anywhere; MFA logic keys off isMfaEnabled and+// selectedMfaMethod instead. Drop it.+export async function up(knex: Knex): Promise<void> {+ if (await knex.schema.hasColumn(TableName.Users, "mfaMethods")) {+ await knex.schema.alterTable(TableName.Users, (t) => {+ t.dropColumn("mfaMethods");+ });+ }+}++export async function down(knex: Knex): Promise<void> {+ if (!(await knex.schema.hasColumn(TableName.Users, "mfaMethods"))) {+ await knex.schema.alterTable(TableName.Users, (t) => {+ t.specificType("mfaMethods", "text[]");+ });+ }+}diff --git a/backend/src/db/sanitized-schema.yaml b/backend/src/db/sanitized-schema.yamlindex f5d05dd316..248cd73013 100644--- a/backend/src/db/sanitized-schema.yaml+++ b/backend/src/db/sanitized-schema.yaml@@ -1319,7 +1319,6 @@ tables:- lastName- isAccepted- isMfaEnabled- - mfaMethods- devices- createdAt- updatedAtdiff --git a/backend/src/db/schemas/users.ts b/backend/src/db/schemas/users.tsindex a7662775cc..b3a6ecd288 100644--- a/backend/src/db/schemas/users.ts+++ b/backend/src/db/schemas/users.ts@@ -16,7 +16,6 @@ export const UsersSchema = z.object({lastName: z.string().nullable().optional(),isAccepted: z.boolean().default(false).nullable().optional(),isMfaEnabled: z.boolean().default(false).nullable().optional(),- mfaMethods: z.string().array().nullable().optional(),devices: z.unknown().nullable().optional(),createdAt: z.date(),updatedAt: z.date(),diff --git a/backend/src/db/seed-ldap.ts b/backend/src/db/seed-ldap.tsindex 14fdb4cdf0..f0e2bc4f73 100644--- a/backend/src/db/seed-ldap.ts+++ b/backend/src/db/seed-ldap.ts@@ -172,7 +172,6 @@ const main = async () => {isAccepted: true,isEmailVerified: true,isMfaEnabled: false,- mfaMethods: null,devices: null}).returning("*");diff --git a/backend/src/db/seed-oidc.ts b/backend/src/db/seed-oidc.tsindex f7302802c6..6b8dd55eae 100644--- a/backend/src/db/seed-oidc.ts+++ b/backend/src/db/seed-oidc.ts@@ -169,7 +169,6 @@ const main = async () => {isAccepted: true,isEmailVerified: true,isMfaEnabled: false,- mfaMethods: null,devices: null}).returning("*");diff --git a/backend/src/db/seed-sso-shared.ts b/backend/src/db/seed-sso-shared.tsindex b319c4791b..791d7edce4 100644--- a/backend/src/db/seed-sso-shared.ts+++ b/backend/src/db/seed-sso-shared.ts@@ -91,7 +91,6 @@ export const seedAdminUser = async (isAccepted: true,isEmailVerified: true,isMfaEnabled: false,- mfaMethods: null,devices: null}).returning("*");diff --git a/backend/src/db/seeds/1-user.ts b/backend/src/db/seeds/1-user.tsindex eaed136ab9..1fdc3c447b 100644--- a/backend/src/db/seeds/1-user.ts+++ b/backend/src/db/seeds/1-user.ts@@ -64,7 +64,6 @@ export async function seed(knex: Knex): Promise<void> {isAccepted: true,isEmailVerified: true,isMfaEnabled: false,- mfaMethods: null,devices: null}])diff --git a/backend/src/server/routes/sanitizedSchemas.ts b/backend/src/server/routes/sanitizedSchemas.tsindex 3a994827f0..ce69cbd3e7 100644--- a/backend/src/server/routes/sanitizedSchemas.ts+++ b/backend/src/server/routes/sanitizedSchemas.ts@@ -128,12 +128,23 @@ export const sanitizedServiceTokenUserSchema = UsersSchema.pick({devices: true,email: true,firstName: true,- lastName: true,- mfaMethods: true+ lastName: true}).merge(z.object({__v: z.number().default(0),- _id: z.string()+ _id: z.string(),+ mfaMethods: z+ .string()+ .array()+ .nullable()+ .optional()+ .default(null)+ .describe(+ JSON.stringify({+ deprecated: true,+ description: "Deprecated: no longer used and always null. Use selectedMfaMethod instead."+ })+ )}));diff --git a/backend/src/server/routes/v2/user-router.ts b/backend/src/server/routes/v2/user-router.tsindex 2ecbbbe5fc..a0dda21e93 100644--- a/backend/src/server/routes/v2/user-router.ts+++ b/backend/src/server/routes/v2/user-router.ts@@ -311,7 +311,18 @@ export const registerUserRouter = async (server: FastifyZodProvider) => {lastName: z.string().nullable().optional(),isAccepted: z.boolean().default(false).nullable().optional(),isMfaEnabled: z.boolean().default(false).nullable().optional(),- mfaMethods: z.string().array().nullable().optional(),+ mfaMethods: z+ .string()+ .array()+ .nullable()+ .optional()+ .default(null)+ .describe(+ JSON.stringify({+ deprecated: true,+ description: "Deprecated: no longer used and always null. Use selectedMfaMethod instead."+ })+ ),devices: z.unknown().nullable().optional(),createdAt: z.date(),updatedAt: z.date(),diff --git a/backend/src/services/auth/auth-login-service.ts b/backend/src/services/auth/auth-login-service.tsindex 1e822c4f0d..b7416fe065 100644--- a/backend/src/services/auth/auth-login-service.ts+++ b/backend/src/services/auth/auth-login-service.ts@@ -174,13 +174,15 @@ export const authLoginServiceFactory = ({email,authMethod,organizationId,- requiredMfaMethod+ requiredMfaMethod,+ sendEmailCode = true}: {userId: string;email?: string | null;authMethod: AuthMethod;organizationId?: string;requiredMfaMethod: MfaMethod;+ sendEmailCode?: boolean;}) => {const appCfg = getConfig();@@ -197,7 +199,7 @@ export const authLoginServiceFactory = ({{ expiresIn: appCfg.JWT_MFA_LIFETIME });- if (requiredMfaMethod === MfaMethod.EMAIL && email) {+ if (requiredMfaMethod === MfaMethod.EMAIL && email && sendEmailCode) {await sendUserMfaCode({ userId, email });}@@ -1375,12 +1377,15 @@ export const authLoginServiceFactory = ({if (shouldTriggerMfa) {enforceUserLockStatus(Boolean(user.isLocked), user.temporaryLockDateEnd);+ const isPendingEmailEnrollment = requiredMfaMethod === MfaMethod.EMAIL && !user.isMfaEnabled;+const mfaToken = await issueMfaChallenge({userId: user.id,email: user.email,authMethod: userAuthMethod,requiredMfaMethod,- organizationId: rootOrg.id+ organizationId: rootOrg.id,+ sendEmailCode: !isPendingEmailEnrollment});return { isMfaEnabled: true, mfa: mfaToken, mfaMethod: requiredMfaMethod } as const;diff --git a/backend/src/services/user/user-service.ts b/backend/src/services/user/user-service.tsindex 1bab0081a4..a81811025a 100644--- a/backend/src/services/user/user-service.ts+++ b/backend/src/services/user/user-service.ts@@ -147,13 +147,6 @@ export const userServiceFactory = ({}}- let mfaMethods: string[] | undefined;- if (isMfaEnabled === undefined) {- mfaMethods = undefined;- } else {- mfaMethods = isMfaEnabled ? ["email"] : [];- }-let recoveryCodes: string[] | undefined;const updatedUser = await userDAL.transaction(async (tx) => {@@ -161,7 +154,6 @@ export const userServiceFactory = ({userId,{isMfaEnabled,- mfaMethods,selectedMfaMethod: isMfaEnabled === false ? MfaMethod.EMAIL : selectedMfaMethod},txdiff --git a/frontend/src/components/auth/Mfa.tsx b/frontend/src/components/auth/Mfa.tsxindex cadc3b6735..3e0ec7d8e8 100644--- a/frontend/src/components/auth/Mfa.tsx+++ b/frontend/src/components/auth/Mfa.tsx@@ -19,6 +19,7 @@ import {} from "@app/hooks/api/auth/queries";import { MfaMethod } from "@app/hooks/api/auth/types";import { getMfaTempToken } from "@app/hooks/api/reactQuery";+import { fetchUserDetails } from "@app/hooks/api/users/queries";import { useGenerateAuthenticationOptions, useVerifyAuthentication } from "@app/hooks/api/webauthn";// The style for the verification code input@@ -77,6 +78,7 @@ export const Mfa = ({ successCallback, closeMfa, hideLogo, email, method }: Propconst [triesLeft, setTriesLeft] = useState<number | undefined>(undefined);const [shouldShowTotpRegistration, setShouldShowTotpRegistration] = useState(false);const [shouldShowWebAuthnRegistration, setShouldShowWebAuthnRegistration] = useState(false);+ const [shouldShowEmailRegistration, setShouldShowEmailRegistration] = useState(false);const logout = useLogoutUser();const { mutateAsync: generateWebAuthnAuthenticationOptions } = useGenerateAuthenticationOptions();@@ -98,6 +100,16 @@ export const Mfa = ({ successCallback, closeMfa, hideLogo, email, method }: PropsetShouldShowWebAuthnRegistration(true);}});+ } else if (method === MfaMethod.EMAIL) {+ fetchUserDetails()+ .then((user) => {+ if (!user.isMfaEnabled) {+ setShouldShowEmailRegistration(true);+ }+ })+ .catch(() => {+ // If we can't determine enrollment state, fall back to the normal email challenge.+ });}}, [method]);@@ -252,7 +264,7 @@ export const Mfa = ({ successCallback, closeMfa, hideLogo, email, method }: Prop}};- if (shouldShowTotpRegistration || shouldShowWebAuthnRegistration) {+ if (shouldShowTotpRegistration || shouldShowWebAuthnRegistration || shouldShowEmailRegistration) {return (<div className="mx-auto w-max pt-4 pb-4 md:mb-16 md:px-8"><MfaEnrollment@@ -260,6 +272,7 @@ export const Mfa = ({ successCallback, closeMfa, hideLogo, email, method }: ProponComplete={async () => {setShouldShowTotpRegistration(false);setShouldShowWebAuthnRegistration(false);+ setShouldShowEmailRegistration(false);await successCallback();}}/>diff --git a/frontend/src/components/mfa/MfaEnrollment.tsx b/frontend/src/components/mfa/MfaEnrollment.tsxindex f607849d23..c2d85cf626 100644--- a/frontend/src/components/mfa/MfaEnrollment.tsx+++ b/frontend/src/components/mfa/MfaEnrollment.tsx@@ -31,41 +31,27 @@ export const MfaEnrollment = ({ method, onComplete }: Props) => {if (hasPrepared.current) return;hasPrepared.current = true;- const prepare = async () => {- // The enrollment endpoints authenticate with the regular access token, so- // clear the temporary MFA token first. Capture it so we can restore it if- // the request fails and the user needs to fall back to the login flow.- const mfaTempToken = getMfaTempToken();- SecurityClient.setMfaToken("");- try {- // Enabling is the single place recovery codes are minted; the response- // returns them once so we can show them after verification without a- // step-up MFA challenge (idempotent if MFA is already on, in which case- // no codes come back).- const { recoveryCodes: codes } = await updateUserMfa({ isMfaEnabled: true });- setRecoveryCodes(codes ?? []);- setPhase("verify");- } catch (error: any) {- // Restore the temp token so the user can reload and retry the normal- // login flow instead of being stuck on the preparing screen.- SecurityClient.setMfaToken(mfaTempToken);- createNotification({- text: error?.response?.data?.message || "Failed to start two-factor setup",- type: "error"- });- }- };-- prepare();- }, [updateUserMfa]);+ // The verification/enable endpoints authenticate with the base access token, so clear the+ // temporary MFA token before mounting the verify step (TOTP fires a registration request on+ // mount). MFA itself is enabled only once the method is verified — see handleVerified.+ SecurityClient.setMfaToken("");+ setPhase("verify");+ }, []);const handleVerified = async () => {try {- await updateUserMfa({ selectedMfaMethod: method });- } catch {- // preference update is best-effort+ const { recoveryCodes: codes } = await updateUserMfa({+ isMfaEnabled: true,+ selectedMfaMethod: method+ });+ setRecoveryCodes(codes ?? []);+ setPhase("recovery");+ } catch (error: any) {+ createNotification({+ text: error?.response?.data?.message || "Failed to enable two-factor authentication",+ type: "error"+ });}- setPhase("recovery");};const handleContinue = async () => {diff --git a/frontend/src/components/mfa/setup/RecoveryCodesStep.tsx b/frontend/src/components/mfa/setup/RecoveryCodesStep.tsxindex f4cea6604e..5965a046a5 100644--- a/frontend/src/components/mfa/setup/RecoveryCodesStep.tsx+++ b/frontend/src/components/mfa/setup/RecoveryCodesStep.tsx@@ -1,4 +1,4 @@-import { TriangleAlertIcon } from "lucide-react";+import { InfoIcon, TriangleAlertIcon } from "lucide-react";import { Alert, AlertDescription, AlertTitle } from "@app/components/v3";@@ -10,18 +10,19 @@ type Props = {};// Shared final step for the MFA enrollment and settings wizard: shows the newly-// minted recovery codes with a save prompt, or a danger fallback when enabling-// MFA returned no codes (e.g. MFA was already on) so the user knows to-// regenerate them from their security settings.+// 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.export const RecoveryCodesStep = ({ recoveryCodes, onSaved }: Props) => {if (recoveryCodes.length === 0) {return (- <Alert variant="danger">- <TriangleAlertIcon />- <AlertTitle>Couldn't load recovery codes</AlertTitle>+ <Alert variant="info">+ <InfoIcon />+ <AlertTitle>Two-factor authentication is already enabled</AlertTitle><AlertDescription>- Two-factor authentication is enabled, but we couldn't display your recovery codes.- Regenerate them from your security settings so you don't get locked out.+ 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>);diff --git a/frontend/src/components/mfa/setup/VerifyStep.tsx b/frontend/src/components/mfa/setup/VerifyStep.tsxindex e73db453b9..3164215bf3 100644--- a/frontend/src/components/mfa/setup/VerifyStep.tsx+++ b/frontend/src/components/mfa/setup/VerifyStep.tsx@@ -15,13 +15,15 @@ type Props = {};const TotpVerify = ({ onVerified }: { onVerified: Props["onVerified"] }) => {- const { data: registration, isPending } = useGetUserTotpRegistration();+ const [hasRegistered, setHasRegistered] = useState(false);+ const { data: registration, isPending } = useGetUserTotpRegistration({ enabled: !hasRegistered });const { mutateAsync: verifyTotp, isPending: isVerifying } = useVerifyUserTotpRegistration();const [qrCodeUrl, setQrCodeUrl] = useState("");const [totp, setTotp] = useState("");useEffect(() => {if (registration?.otpUrl) {+ setHasRegistered(true);QRCode.toDataURL(registration.otpUrl).then(setQrCodeUrl);}}, [registration?.otpUrl]);diff --git a/frontend/src/pages/auth/SignUpPage/SignUpPage.tsx b/frontend/src/pages/auth/SignUpPage/SignUpPage.tsxindex 3c0c0247d0..25d3a3fb70 100644--- a/frontend/src/pages/auth/SignUpPage/SignUpPage.tsx+++ b/frontend/src/pages/auth/SignUpPage/SignUpPage.tsx@@ -71,7 +71,16 @@ export const SignUpPage = ({ invite }: SignUpPageProps) => {const orgId = userOrgs[0]?.id;if (orgId) {- await selectOrganization({ organizationId: orgId });+ const { isMfaEnabled } = await selectOrganization({ organizationId: orgId });++ if (isMfaEnabled) {+ navigate({+ to: "/login/select-organization",+ search: { org_id: orgId }+ });+ return;+ }+navigate({to: "/organizations/$orgId/projects",params: { orgId }