Skip to content

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

feat: corrected the backend template

=7719cf1948b1
diff --git a/backend/src/services/account-recovery/account-recovery-service.ts b/backend/src/services/account-recovery/account-recovery-service.ts
index 87f6331479..05fbd258fd 100644
--- a/backend/src/services/account-recovery/account-recovery-service.ts
+++ b/backend/src/services/account-recovery/account-recovery-service.ts
@@ -40,6 +40,12 @@ export const accountRecoveryServiceFactory = ({
const cfg = getConfig();
const hasEmailAuth = user.authMethods?.includes(AuthMethod.EMAIL);
+ const substitutions: Record<string, unknown> = {
+ email,
+ isCloud: cfg.isCloud,
+ siteUrl: cfg.SITE_URL || "",
+ hasEmailAuth
+ };
if (!hasEmailAuth) {
const orgMemberships = await membershipUserDAL.find({
@@ -51,41 +57,26 @@ export const accountRecoveryServiceFactory = ({
.filter((membership) => membership.lastLoginAuthMethod)
.sort((a, b) => (b.updatedAt || new Date(0)).getTime() - (a.updatedAt || new Date(0)).getTime())[0]
?.lastLoginAuthMethod || null;
- const substitutions = {
- email,
- lastLoginMethod,
- isCloud: cfg.isCloud,
- siteUrl: cfg.SITE_URL || ""
- };
-
- await smtpService.sendMail({
- template: SmtpTemplates.OAuthPasswordReset,
- recipients: [email],
- subjectLine: "Password reset not available",
- substitutions
- });
- } else {
- const token = await tokenService.createTokenForUser({
- type: TokenType.TOKEN_EMAIL_PASSWORD_RESET,
- userId: user.id
- });
-
- await smtpService.sendMail({
- template: SmtpTemplates.ResetPassword,
- recipients: [email],
- subjectLine: "Infisical password reset",
- substitutions: {
- email,
- token,
- callback_url: cfg.SITE_URL ? `${cfg.SITE_URL}/password-reset` : ""
- }
- });
+ substitutions.lastLoginMethod = lastLoginMethod;
}
+
+ const token = await tokenService.createTokenForUser({
+ type: TokenType.TOKEN_EMAIL_PASSWORD_RESET,
+ userId: user.id
+ });
+
+ substitutions.token = token;
+ await smtpService.sendMail({
+ template: SmtpTemplates.ResetPassword,
+ recipients: [email],
+ subjectLine: "Infisical account recovery",
+ substitutions
+ });
}
};
// note(daniel): run in background to prevent timing attacks
- void sendEmail().catch((err) => logger.error(err, "Failed to send password reset email"));
+ void sendEmail().catch((err) => logger.error(err, "Failed to send account recovery email"));
};
/*
diff --git a/backend/src/services/auth-token/auth-token-service.ts b/backend/src/services/auth-token/auth-token-service.ts
index ec60f7e8ce..0dbfc4d4d6 100644
--- a/backend/src/services/auth-token/auth-token-service.ts
+++ b/backend/src/services/auth-token/auth-token-service.ts
@@ -59,7 +59,7 @@ export const getTokenConfig = (tokenType: TokenType) => {
}
case TokenType.TOKEN_EMAIL_PASSWORD_RESET: {
// generate random hex
- const token = crypto.randomBytes(16).toString("hex");
+ const token = crypto.randomBytes(32).toString("hex");
const expiresAt = new Date(new Date().getTime() + 86400000);
return { token, expiresAt };
}
diff --git a/backend/src/services/smtp/emails/PasswordResetTemplate.tsx b/backend/src/services/smtp/emails/PasswordResetTemplate.tsx
index 2cfa005087..b99372e38d 100644
--- a/backend/src/services/smtp/emails/PasswordResetTemplate.tsx
+++ b/backend/src/services/smtp/emails/PasswordResetTemplate.tsx
@@ -10,20 +10,58 @@ interface PasswordResetTemplateProps extends Omit<BaseEmailWrapperProps, "title"
callback_url: string;
token: string;
isCloud: boolean;
+ lastLoginMethod?: string | null;
+ hasEmailAuth?: boolean;
}
-export const PasswordResetTemplate = ({ email, isCloud, siteUrl, callback_url, token }: PasswordResetTemplateProps) => {
+export const PasswordResetTemplate = ({
+ email,
+ isCloud,
+ siteUrl,
+ callback_url,
+ token,
+ lastLoginMethod,
+ hasEmailAuth
+}: PasswordResetTemplateProps) => {
+ const getAuthMethodDisplayName = (method: string) => {
+ return method
+ .split("-")
+ .map((word) => {
+ const upperWord = word.toUpperCase();
+ if (["SAML", "LDAP", "OIDC", "SSO"].includes(upperWord)) {
+ return upperWord;
+ }
+ return word.charAt(0).toUpperCase() + word.slice(1);
+ })
+ .join(" ");
+ };
+
+ const getAuthMethodMessage = () => {
+ if (hasEmailAuth) {
+ return "";
+ }
+
+ if (lastLoginMethod) {
+ const displayName = getAuthMethodDisplayName(lastLoginMethod);
+ return `Our records indicate your last login was via ${displayName}. If you have lost access to this authentication method, you may proceed with account recovery below.`;
+ }
+ return "Our records indicate your last login was via a non-email authentication method (e.g., SSO, SAML, OIDC, or LDAP). If you have lost access to this authentication method, you may proceed with account recovery below.";
+ };
+
+ const authMethodMessage = getAuthMethodMessage();
+
return (
<BaseEmailWrapper
title="Account Recovery"
- preview="A password reset was requested for your Infisical account."
+ preview="A request was made to recover access to your Infisical account."
siteUrl={siteUrl}
>
<Heading className="text-black text-[18px] leading-[28px] text-center font-normal p-0 mx-0">
<strong>Account Recovery</strong>
</Heading>
<Section className="px-[24px] mb-[28px] mt-[36px] pt-[12px] pb-[8px] border border-solid border-gray-200 rounded-md bg-gray-50">
- <Text className="text-[14px]">A password reset was requested for your Infisical account.</Text>
+ <Text className="text-[14px]">A request was made to recover access to your Infisical account.</Text>
+ {authMethodMessage && <Text className="text-[14px]">{authMethodMessage}</Text>}
<Text className="text-[14px]">
If you did not initiate this request, please contact{" "}
{isCloud ? (
@@ -37,7 +75,7 @@ export const PasswordResetTemplate = ({ email, isCloud, siteUrl, callback_url, t
</Text>
</Section>
<Section className="text-center">
- <BaseButton href={`${callback_url}?token=${token}&to=${encodeURIComponent(email)}`}>Reset Password</BaseButton>
+ <BaseButton href={`${callback_url}?token=${token}&to=${encodeURIComponent(email)}`}>Restore Access</BaseButton>
</Section>
</BaseEmailWrapper>
);
@@ -50,5 +88,7 @@ PasswordResetTemplate.PreviewProps = {
callback_url: "https://app.infisical.com",
isCloud: true,
token: "preview-token",
- siteUrl: "https://infisical.com"
+ siteUrl: "https://infisical.com",
+ lastLoginMethod: "",
+ hasEmailAuth: true
} as PasswordResetTemplateProps;