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
feat(login): show login SMTP errors in case of misconfiguration (#6029)
Matheus Nogueira798f4c3dfca8
diff --git a/backend/src/services/auth/auth-login-service.ts b/backend/src/services/auth/auth-login-service.tsindex 1ff0e5cdf6..6f79587877 100644--- a/backend/src/services/auth/auth-login-service.ts+++ b/backend/src/services/auth/auth-login-service.ts@@ -37,7 +37,7 @@ import { TNotificationServiceFactory } from "../notification/notification-servicimport { NotificationType } from "../notification/notification-types";import { TOrgDALFactory } from "../org/org-dal";import { getDefaultOrgMembershipRole } from "../org/org-role-fns";-import { SmtpTemplates, TSmtpService } from "../smtp/smtp-service";+import { SmtpTemplates, throwIfSmtpError, TSmtpService } from "../smtp/smtp-service";import { LoginMethod } from "../super-admin/super-admin-types";import { TTotpServiceFactory } from "../totp/totp-service";import { TUserDALFactory } from "../user/user-dal";@@ -114,17 +114,21 @@ export const authLoginServiceFactory = ({]);if (user.email) {- await smtpService.sendMail({- template: SmtpTemplates.NewDeviceJoin,- subjectLine: "Successful login from new device",- recipients: [user.email],- substitutions: {- email: user.email,- timestamp: new Date().toString(),- ip,- userAgent- }- });+ await smtpService+ .sendMail({+ template: SmtpTemplates.NewDeviceJoin,+ subjectLine: "Successful login from new device",+ recipients: [user.email],+ substitutions: {+ email: user.email,+ timestamp: new Date().toString(),+ ip,+ userAgent+ }+ })+ // Intentionally not rethrowing: this is an informational notification and the login already+ // succeeded. Blocking the user over a failed notification email would be worse than missing it.+ .catch((err) => logger.error(err, `Failed to send new device login email [userId=${user.id}]`));}}};@@ -139,14 +143,16 @@ export const authLoginServiceFactory = ({userId});- await smtpService.sendMail({- template: SmtpTemplates.EmailMfa,- subjectLine: "Infisical MFA code",- recipients: [email],- substitutions: {- code- }- });+ await smtpService+ .sendMail({+ template: SmtpTemplates.EmailMfa,+ subjectLine: "Infisical MFA code",+ recipients: [email],+ substitutions: {+ code+ }+ })+ .catch((err) => throwIfSmtpError(err, `Failed to send MFA code email [userId=${userId}]`));};/*@@ -730,19 +736,25 @@ export const authLoginServiceFactory = ({})));- await smtpService.sendMail({- recipients: adminEmails,- subjectLine: "Security Alert: SSO Bypass",- substitutions: {- email: user.email,- timestamp: new Date().toISOString(),- ip: ipAddress,- userAgent,- siteUrl: removeTrailingSlash(cfg.SITE_URL || "https://app.infisical.com"),- orgId: organizationId- },- template: SmtpTemplates.OrgAdminBreakglassAccess- });+ await smtpService+ .sendMail({+ recipients: adminEmails,+ subjectLine: "Security Alert: SSO Bypass",+ substitutions: {+ email: user.email,+ timestamp: new Date().toISOString(),+ ip: ipAddress,+ userAgent,+ siteUrl: removeTrailingSlash(cfg.SITE_URL || "https://app.infisical.com"),+ orgId: organizationId+ },+ template: SmtpTemplates.OrgAdminBreakglassAccess+ })+ // Intentionally not rethrowing: this is an informational security alert and the SSO bypass+ // already succeeded. Blocking the user over a failed alert email would be worse than missing it.+ .catch((err) =>+ logger.error(err, `Failed to send SSO bypass alert email [orgId=${organizationId}] [userId=${user.id}]`)+ );}}diff --git a/backend/src/services/auth/auth-signup-service.ts b/backend/src/services/auth/auth-signup-service.tsindex 613911c113..2da0afa3a6 100644--- a/backend/src/services/auth/auth-signup-service.ts+++ b/backend/src/services/auth/auth-signup-service.ts@@ -7,6 +7,7 @@ import { getConfig } from "@app/lib/config/env";import { crypto } from "@app/lib/crypto/cryptography";import { BadRequestError, ForbiddenRequestError, NotFoundError } from "@app/lib/errors";import { getMinExpiresIn } from "@app/lib/fn";+import { logger } from "@app/lib/logger";import { isDisposableEmail } from "@app/lib/validator";import { TProjectDALFactory } from "@app/services/project/project-dal";import { TProjectBotDALFactory } from "@app/services/project-bot/project-bot-dal";@@ -17,7 +18,7 @@ import { TokenType } from "../auth-token/auth-token-types";import { TMembershipGroupDALFactory } from "../membership-group/membership-group-dal";import { TOrgDALFactory } from "../org/org-dal";import { TOrgServiceFactory } from "../org/org-service";-import { SmtpTemplates, TSmtpService } from "../smtp/smtp-service";+import { SmtpTemplates, throwIfSmtpError, TSmtpService } from "../smtp/smtp-service";import { getServerCfg } from "../super-admin/super-admin-service";import { TUserDALFactory } from "../user/user-dal";import { UserEncryption } from "../user/user-types";@@ -79,16 +80,22 @@ export const authSignupServiceFactory = ({// Send informational email for existing accounts instead of throwing error// This prevents user enumeration vulnerabilityconst appCfg = getConfig();- await smtpService.sendMail({- template: SmtpTemplates.SignupExistingAccount,- subjectLine: "Sign-up Request for Your Infisical Account",- recipients: [sanitizedEmail],- substitutions: {- email: sanitizedEmail,- loginUrl: `${appCfg.SITE_URL}/login`,- resetPasswordUrl: `${appCfg.SITE_URL}/account-recovery`- }- });+ await smtpService+ .sendMail({+ template: SmtpTemplates.SignupExistingAccount,+ subjectLine: "Sign-up Request for Your Infisical Account",+ recipients: [sanitizedEmail],+ substitutions: {+ email: sanitizedEmail,+ loginUrl: `${appCfg.SITE_URL}/login`,+ resetPasswordUrl: `${appCfg.SITE_URL}/account-recovery`+ }+ })+ .catch((err) => {+ // Intentionally not rethrowing: this email is an anti-enumeration measure.+ // Surfacing an SMTP error would reveal that the account already exists.+ logger.error(err, `Failed to send existing account signup email [email=${sanitizedEmail}]`);+ });return;}if (!user) {@@ -106,14 +113,16 @@ export const authSignupServiceFactory = ({userId: user.id});- await smtpService.sendMail({- template: SmtpTemplates.SignupEmailVerification,- subjectLine: "Infisical confirmation code",- recipients: [sanitizedEmail],- substitutions: {- code: token- }- });+ await smtpService+ .sendMail({+ template: SmtpTemplates.SignupEmailVerification,+ subjectLine: "Infisical confirmation code",+ recipients: [sanitizedEmail],+ substitutions: {+ code: token+ }+ })+ .catch((err) => throwIfSmtpError(err, `Failed to send signup verification email [email=${sanitizedEmail}]`));};const verifyEmailSignup = async (email: string, code: string) => {diff --git a/backend/src/services/smtp/smtp-service.ts b/backend/src/services/smtp/smtp-service.tsindex 3449029836..25400d2243 100644--- a/backend/src/services/smtp/smtp-service.ts+++ b/backend/src/services/smtp/smtp-service.ts@@ -4,6 +4,7 @@ import SMTPTransport from "nodemailer/lib/smtp-transport";import React from "react";import { getConfig } from "@app/lib/config/env";+import { InternalServerError } from "@app/lib/errors";import { logger } from "@app/lib/logger";import {@@ -155,6 +156,19 @@ const EmailTemplateMap: Record<SmtpTemplates, React.FC<any>> = {[SmtpTemplates.AuditLogMigrationAlert]: AuditLogMigrationAlertTemplate};+export const throwIfSmtpError = (err: unknown, logMessage: string) => {+ logger.error(err, logMessage);+ const { isCloud } = getConfig();+ // We must always throw so the user is not left waiting for an email that never arrives.+ // On cloud, we show a generic message to avoid exposing internal misconfiguration details.+ throw new InternalServerError({+ message: isCloud+ ? "We could not send you an email. Please try again later."+ : "Failed to send email. This is likely due to a misconfigured SMTP server. Please check your SMTP settings and try again.",+ name: "SmtpError"+ });+};+export const smtpServiceFactory = (cfg: TSmtpConfig) => {const smtp = createTransport(cfg);const isSmtpOn = Boolean(cfg.host);diff --git a/frontend/src/pages/auth/LoginPage/components/InitialStep/InitialStep.tsx b/frontend/src/pages/auth/LoginPage/components/InitialStep/InitialStep.tsxindex a118bd5d20..61c3148233 100644--- a/frontend/src/pages/auth/LoginPage/components/InitialStep/InitialStep.tsx+++ b/frontend/src/pages/auth/LoginPage/components/InitialStep/InitialStep.tsx@@ -164,10 +164,6 @@ export const InitialStep = ({if (isLoginSuccessful && isLoginSuccessful.success) {saveLastLogin({ method: LoginMethod.EMAIL });navigateToSelectOrganization(undefined, isAdmin);- createNotification({- text: "Successfully logged in",- type: "success"- });}}} catch (err: any) {diff --git a/frontend/src/pages/auth/LoginPage/components/PasswordStep/PasswordStep.tsx b/frontend/src/pages/auth/LoginPage/components/PasswordStep/PasswordStep.tsxindex 938a131715..c51d186ccb 100644--- a/frontend/src/pages/auth/LoginPage/components/PasswordStep/PasswordStep.tsx+++ b/frontend/src/pages/auth/LoginPage/components/PasswordStep/PasswordStep.tsx@@ -110,6 +110,10 @@ export const PasswordStep = ({}// case: no orgs found, so we navigate the user to create an orgelse {+ createNotification({+ text: "Successfully logged in",+ type: "success"+ });await navigateUserToOrg({ navigate });}} catch (err: any) {@@ -125,6 +129,12 @@ export const PasswordStep = ({return;}+ // React Query's global MutationCache.onError already shows the SmtpError toast.+ // Return early so we don't also show the misleading "check your password" message.+ if (err.response.data.error === "SmtpError") {+ return;+ }+createNotification({text: "Login unsuccessful. Double-check your master password and try again.",type: "error"@@ -225,13 +235,13 @@ export const PasswordStep = ({if (loginAttempt && loginAttempt.success) {// case: login was successfulsetIsLoading(false);- createNotification({- text: "Successfully logged in",- type: "success"- });// case: organization ID is present from the provider auth token -- navigate directly to the orgif (organizationId) {+ createNotification({+ text: "Successfully logged in",+ type: "success"+ });await navigateUserToOrg({ navigate, organizationId });}// case: no organization ID is present -- navigate to the select org page IF the user has any orgs@@ -242,6 +252,10 @@ export const PasswordStep = ({if (userOrgs.length > 0) {navigateToSelectOrganization(undefined, isAdminLogin);} else {+ createNotification({+ text: "Successfully logged in",+ type: "success"+ });await navigateUserToOrg({ navigate });}}@@ -265,6 +279,12 @@ export const PasswordStep = ({return;}+ // React Query's global MutationCache.onError already shows the SmtpError toast.+ // Return early so we don't also show the misleading "check your password" message.+ if (err.response.data.error === "SmtpError") {+ return;+ }+createNotification({text: "Login unsuccessful. Double-check your master password and try again.",type: "error"diff --git a/frontend/src/pages/auth/SelectOrgPage/SelectOrgSection.tsx b/frontend/src/pages/auth/SelectOrgPage/SelectOrgSection.tsxindex 967b59e1de..c645c04324 100644--- a/frontend/src/pages/auth/SelectOrgPage/SelectOrgSection.tsx+++ b/frontend/src/pages/auth/SelectOrgPage/SelectOrgSection.tsx@@ -168,6 +168,11 @@ export const SelectOrganizationSection = () => {await handleLogout();return;}+ // React Query already shows a bad request toast; just log out silently.+ if (error?.response?.data?.error === "SmtpError") {+ await handleLogout();+ return;+ }throw error;} finally {setIsInitialOrgCheckLoading(false);@@ -214,6 +219,10 @@ export const SelectOrganizationSection = () => {});navigate({ to: "/cli-redirect" });} else {+ createNotification({+ text: "Successfully logged in",+ type: "success"+ });navigateUserToOrg({ navigate, organizationId: organization.id });}},