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
Revert "feat(login): show login SMTP errors in case of misconfiguration (#6029)"
Akhil Mohan4dc3260daec6
diff --git a/backend/src/services/auth/auth-login-service.ts b/backend/src/services/auth/auth-login-service.tsindex 6f79587877..1ff0e5cdf6 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, throwIfSmtpError, TSmtpService } from "../smtp/smtp-service";+import { SmtpTemplates, 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,21 +114,17 @@ 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- }- })- // 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}]`));+ 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+ }+ });}}};@@ -143,16 +139,14 @@ export const authLoginServiceFactory = ({userId});- 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}]`));+ await smtpService.sendMail({+ template: SmtpTemplates.EmailMfa,+ subjectLine: "Infisical MFA code",+ recipients: [email],+ substitutions: {+ code+ }+ });};/*@@ -736,25 +730,19 @@ 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- })- // 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}]`)- );+ 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+ });}}diff --git a/backend/src/services/auth/auth-signup-service.ts b/backend/src/services/auth/auth-signup-service.tsindex 2da0afa3a6..613911c113 100644--- a/backend/src/services/auth/auth-signup-service.ts+++ b/backend/src/services/auth/auth-signup-service.ts@@ -7,7 +7,6 @@ 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";@@ -18,7 +17,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, throwIfSmtpError, TSmtpService } from "../smtp/smtp-service";+import { SmtpTemplates, 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";@@ -80,22 +79,16 @@ 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`- }- })- .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}]`);- });+ 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`+ }+ });return;}if (!user) {@@ -113,16 +106,14 @@ export const authSignupServiceFactory = ({userId: user.id});- 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}]`));+ await smtpService.sendMail({+ template: SmtpTemplates.SignupEmailVerification,+ subjectLine: "Infisical confirmation code",+ recipients: [sanitizedEmail],+ substitutions: {+ code: token+ }+ });};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 25400d2243..3449029836 100644--- a/backend/src/services/smtp/smtp-service.ts+++ b/backend/src/services/smtp/smtp-service.ts@@ -4,7 +4,6 @@ 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 {@@ -156,19 +155,6 @@ 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 61c3148233..a118bd5d20 100644--- a/frontend/src/pages/auth/LoginPage/components/InitialStep/InitialStep.tsx+++ b/frontend/src/pages/auth/LoginPage/components/InitialStep/InitialStep.tsx@@ -164,6 +164,10 @@ 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 c51d186ccb..938a131715 100644--- a/frontend/src/pages/auth/LoginPage/components/PasswordStep/PasswordStep.tsx+++ b/frontend/src/pages/auth/LoginPage/components/PasswordStep/PasswordStep.tsx@@ -110,10 +110,6 @@ 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) {@@ -129,12 +125,6 @@ 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"@@ -235,13 +225,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@@ -252,10 +242,6 @@ export const PasswordStep = ({if (userOrgs.length > 0) {navigateToSelectOrganization(undefined, isAdminLogin);} else {- createNotification({- text: "Successfully logged in",- type: "success"- });await navigateUserToOrg({ navigate });}}@@ -279,12 +265,6 @@ 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 c645c04324..967b59e1de 100644--- a/frontend/src/pages/auth/SelectOrgPage/SelectOrgSection.tsx+++ b/frontend/src/pages/auth/SelectOrgPage/SelectOrgSection.tsx@@ -168,11 +168,6 @@ 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);@@ -219,10 +214,6 @@ export const SelectOrganizationSection = () => {});navigate({ to: "/cli-redirect" });} else {- createNotification({- text: "Successfully logged in",- type: "success"- });navigateUserToOrg({ navigate, organizationId: organization.id });}},