Skip to content

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

gate when SMTP is not available

Thiago Araujo da Silva69ef6dfb71dc
diff --git a/backend/src/services/user/user-service.ts b/backend/src/services/user/user-service.ts
index 3ce2117092..ca63546ff5 100644
--- a/backend/src/services/user/user-service.ts
+++ b/backend/src/services/user/user-service.ts
@@ -113,9 +113,16 @@ export const userServiceFactory = ({
};
// A method can only be selected/activated once the user has actually configured
- // that factor. EMAIL is always available since it uses the account email.
+ // that factor. EMAIL uses the account email, so it needs no enrollment, but it
+ // delivers codes over SMTP — which self-hosted instances may not have configured.
const assertMfaMethodConfigured = async (userId: string, method: MfaMethod) => {
- if (method === MfaMethod.TOTP) {
+ if (method === MfaMethod.EMAIL) {
+ if (!getConfig().isSmtpConfigured) {
+ throw new BadRequestError({
+ message: "Cannot use email two-factor authentication because SMTP is not configured for this instance"
+ });
+ }
+ } else if (method === MfaMethod.TOTP) {
const totpConfig = await totpConfigDAL.findOne({ userId, isVerified: true });
if (!totpConfig) {
throw new BadRequestError({
diff --git a/frontend/src/pages/user/PersonalSettingsPage/components/SecuritySection/MFASection.tsx b/frontend/src/pages/user/PersonalSettingsPage/components/SecuritySection/MFASection.tsx
index b7b3f7726d..2d118d0447 100644
--- a/frontend/src/pages/user/PersonalSettingsPage/components/SecuritySection/MFASection.tsx
+++ b/frontend/src/pages/user/PersonalSettingsPage/components/SecuritySection/MFASection.tsx
@@ -28,6 +28,7 @@ import {
} from "@app/components/v3";
import { useActivateMfa, useGetOrganizations, useGetUser, useSetMfaMethod } from "@app/hooks/api";
import { MfaMethod } from "@app/hooks/api/auth/types";
+import { useFetchServerStatus } from "@app/hooks/api/serverDetails";
import { useGetUserTotpConfiguration } from "@app/hooks/api/users";
import { AuthMethod } from "@app/hooks/api/users/types";
import { useGetWebAuthnCredentials } from "@app/hooks/api/webauthn";
@@ -46,8 +47,10 @@ export const MFASection = () => {
const { data: totpConfiguration } = useGetUserTotpConfiguration();
const { data: webAuthnCredentials = [] } = useGetWebAuthnCredentials();
const { data: organizations = [] } = useGetOrganizations();
+ const { data: serverDetails } = useFetchServerStatus();
const isMfaEnforced = organizations.some((org) => org.enforceMfa);
+ const isEmailMfaAvailable = Boolean(serverDetails?.emailConfigured);
const [isEnableOpen, setIsEnableOpen] = useState(false);
const [isDisableOpen, setIsDisableOpen] = useState(false);
@@ -78,7 +81,7 @@ export const MFASection = () => {
}
const availableMethods = [
- MfaMethod.EMAIL,
+ ...(isEmailMfaAvailable ? [MfaMethod.EMAIL] : []),
...(totpConfiguration?.isVerified ? [MfaMethod.TOTP] : []),
...(webAuthnCredentials.length > 0 ? [MfaMethod.WEBAUTHN] : [])
];
@@ -88,8 +91,8 @@ export const MFASection = () => {
? preferredMethod
: availableMethods[0];
- // Recovery codes are issued on enable and wiped on disable, so they exist iff
- // MFA is currently enabled.
+ const canEnable = availableMethods.length > 0;
+
const hasRecoveryCodes = user.isMfaEnabled;
const handleEnable = async () => {
@@ -204,9 +207,15 @@ export const MFASection = () => {
) : (
<>
<p className="text-sm text-muted">
- Choose your preferred method above, then enable two-factor authentication.
+ {canEnable
+ ? "Choose your preferred method above, then enable two-factor authentication."
+ : "Set up an authenticator app or passkey below to enable two-factor authentication. Email codes are unavailable because SMTP is not configured for this instance."}
</p>
- <Button variant="org" isDisabled={isEnabling} onClick={() => setIsEnableOpen(true)}>
+ <Button
+ variant="org"
+ isDisabled={isEnabling || !canEnable}
+ onClick={() => setIsEnableOpen(true)}
+ >
<ShieldCheckIcon /> Enable two-factor authentication
</Button>
</>
diff --git a/frontend/src/pages/user/PersonalSettingsPage/components/SecuritySection/MfaMethodsCard.tsx b/frontend/src/pages/user/PersonalSettingsPage/components/SecuritySection/MfaMethodsCard.tsx
index 5a919c3787..16ff602ae2 100644
--- a/frontend/src/pages/user/PersonalSettingsPage/components/SecuritySection/MfaMethodsCard.tsx
+++ b/frontend/src/pages/user/PersonalSettingsPage/components/SecuritySection/MfaMethodsCard.tsx
@@ -18,6 +18,7 @@ import {
} from "@app/components/v3";
import { userKeys } from "@app/hooks/api";
import { MfaMethod } from "@app/hooks/api/auth/types";
+import { useFetchServerStatus } from "@app/hooks/api/serverDetails";
import { useDeleteUserTotpConfiguration, useGetUserTotpConfiguration } from "@app/hooks/api/users";
import { useGetWebAuthnCredentials } from "@app/hooks/api/webauthn";
@@ -52,8 +53,11 @@ export const MfaMethodsCard = () => {
const queryClient = useQueryClient();
const { data: totpConfiguration } = useGetUserTotpConfiguration();
const { data: webAuthnCredentials = [] } = useGetWebAuthnCredentials();
+ const { data: serverDetails } = useFetchServerStatus();
const { mutateAsync: deleteTotp, isPending: isDeletingTotp } = useDeleteUserTotpConfiguration();
+ const isEmailMfaAvailable = Boolean(serverDetails?.emailConfigured);
+
const [setupMethod, setSetupMethod] = useState<MfaMethod | null>(null);
const [isPasskeyManagerOpen, setIsPasskeyManagerOpen] = useState(false);
const [isRemoveTotpOpen, setIsRemoveTotpOpen] = useState(false);
@@ -81,8 +85,18 @@ export const MfaMethodsCard = () => {
<MethodRow
icon={MFA_METHOD_ICONS[MfaMethod.EMAIL]}
title={MFA_METHOD_LABELS[MfaMethod.EMAIL]}
- description="Receive one-time codes at your account email address to complete sign-in."
- badge={<Badge variant="success">Configured</Badge>}
+ description={
+ isEmailMfaAvailable
+ ? "Receive one-time codes at your account email address to complete sign-in."
+ : "Unavailable because SMTP is not configured for this instance. Use an authenticator app or passkey instead."
+ }
+ badge={
+ isEmailMfaAvailable ? (
+ <Badge variant="success">Configured</Badge>
+ ) : (
+ <Badge variant="neutral">Unavailable</Badge>
+ )
+ }
action={null}
/>