From 28087cdcc410a3c7b13873319f221e649adf78cd Mon Sep 17 00:00:00 2001 From: Sheen Capadngan Date: Wed, 24 Jul 2024 00:55:02 +0800 Subject: [PATCH 1/2] misc: added email self-host conditionals --- backend/src/services/smtp/smtp-service.ts | 7 +++++-- .../services/smtp/templates/emailMfa.handlebars | 14 +++++++------- .../services/smtp/templates/newDevice.handlebars | 14 +++++++------- .../smtp/templates/passwordReset.handlebars | 2 +- 4 files changed, 20 insertions(+), 17 deletions(-) diff --git a/backend/src/services/smtp/smtp-service.ts b/backend/src/services/smtp/smtp-service.ts index 151127484..5e090b4c6 100644 --- a/backend/src/services/smtp/smtp-service.ts +++ b/backend/src/services/smtp/smtp-service.ts @@ -5,6 +5,7 @@ import handlebars from "handlebars"; import { createTransport } from "nodemailer"; import SMTPTransport from "nodemailer/lib/smtp-transport"; +import { getConfig } from "@app/lib/config/env"; import { logger } from "@app/lib/logger"; export type TSmtpConfig = SMTPTransport.Options; @@ -12,7 +13,7 @@ export type TSmtpSendMail = { template: SmtpTemplates; subjectLine: string; recipients: string[]; - substitutions: unknown; + substitutions: object; }; export type TSmtpService = ReturnType; @@ -47,9 +48,11 @@ export const smtpServiceFactory = (cfg: TSmtpConfig) => { const isSmtpOn = Boolean(cfg.host); const sendMail = async ({ substitutions, recipients, template, subjectLine }: TSmtpSendMail) => { + const appCfg = getConfig(); const html = await fs.readFile(path.resolve(__dirname, "./templates/", template), "utf8"); const temp = handlebars.compile(html); - const htmlToSend = temp(substitutions); + const htmlToSend = temp({ ...substitutions, isCloud: appCfg.isCloud }); + if (isSmtpOn) { await smtp.sendMail({ from: cfg.from, diff --git a/backend/src/services/smtp/templates/emailMfa.handlebars b/backend/src/services/smtp/templates/emailMfa.handlebars index 489c9dd30..936195c34 100644 --- a/backend/src/services/smtp/templates/emailMfa.handlebars +++ b/backend/src/services/smtp/templates/emailMfa.handlebars @@ -1,19 +1,19 @@ - - - + + + MFA Code - + - +

Infisical

Sign in attempt requires further verification

Your MFA code is below — enter it where you started signing in to Infisical.

{{code}}

The MFA code will be valid for 2 minutes.

-

Not you? Contact Infisical or your administrator immediately.

- +

Not you? Contact {{#if isCloud}}Infisical{{else}}your administrator{{/if}} immediately.

+ \ No newline at end of file diff --git a/backend/src/services/smtp/templates/newDevice.handlebars b/backend/src/services/smtp/templates/newDevice.handlebars index 654bb1ba3..6c7f2e9f6 100644 --- a/backend/src/services/smtp/templates/newDevice.handlebars +++ b/backend/src/services/smtp/templates/newDevice.handlebars @@ -1,19 +1,19 @@ - - - + + + Successful login for {{email}} from new device - + - +

Infisical

We're verifying a recent login for {{email}}:

Timestamp: {{timestamp}}

IP address: {{ip}}

User agent: {{userAgent}}

-

If you believe that this login is suspicious, please contact Infisical or reset your password immediately.

- +

If you believe that this login is suspicious, please contact {{#if isCloud}}Infisical{{else}}your administrator{{/if}} or reset your password immediately.

+ \ No newline at end of file diff --git a/backend/src/services/smtp/templates/passwordReset.handlebars b/backend/src/services/smtp/templates/passwordReset.handlebars index 3b136e859..6499a629c 100644 --- a/backend/src/services/smtp/templates/passwordReset.handlebars +++ b/backend/src/services/smtp/templates/passwordReset.handlebars @@ -9,6 +9,6 @@

Reset your password

Someone requested a password reset.

Reset password -

If you didn't initiate this request, please contact us immediately at team@infisical.com

+

If you didn't initiate this request, please contact {{#if isCloud}}us immediately at team@infisical.com.{{else}}your administrator immediately.{{/if}}

\ No newline at end of file From 8e373fe9bfb17858324a50d33161104884408515 Mon Sep 17 00:00:00 2001 From: Sheen Capadngan Date: Wed, 24 Jul 2024 16:33:41 +0800 Subject: [PATCH 2/2] misc: added email formatting for remaining templates --- backend/src/services/smtp/smtp-service.ts | 2 +- .../smtp/templates/historicalSecretLeakIncident.handlebars | 4 ++-- .../src/services/smtp/templates/secretLeakIncident.handlebars | 4 ++-- .../smtp/templates/signupEmailVerification.handlebars | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/backend/src/services/smtp/smtp-service.ts b/backend/src/services/smtp/smtp-service.ts index 5e090b4c6..95407d0b0 100644 --- a/backend/src/services/smtp/smtp-service.ts +++ b/backend/src/services/smtp/smtp-service.ts @@ -51,7 +51,7 @@ export const smtpServiceFactory = (cfg: TSmtpConfig) => { const appCfg = getConfig(); const html = await fs.readFile(path.resolve(__dirname, "./templates/", template), "utf8"); const temp = handlebars.compile(html); - const htmlToSend = temp({ ...substitutions, isCloud: appCfg.isCloud }); + const htmlToSend = temp({ isCloud: appCfg.isCloud, siteUrl: appCfg.SITE_URL, ...substitutions }); if (isSmtpOn) { await smtp.sendMail({ diff --git a/backend/src/services/smtp/templates/historicalSecretLeakIncident.handlebars b/backend/src/services/smtp/templates/historicalSecretLeakIncident.handlebars index 3cb517a57..0798538fb 100644 --- a/backend/src/services/smtp/templates/historicalSecretLeakIncident.handlebars +++ b/backend/src/services/smtp/templates/historicalSecretLeakIncident.handlebars @@ -9,12 +9,12 @@

Infisical has uncovered {{numberOfSecrets}} secret(s) from historical commits to your repo

-

View leaked secrets

+

View leaked secrets

If these are production secrets, please rotate them immediately.

Once you have taken action, be sure to update the status of the risk in your Infisical + href="{{siteUrl}}">Infisical dashboard.

diff --git a/backend/src/services/smtp/templates/secretLeakIncident.handlebars b/backend/src/services/smtp/templates/secretLeakIncident.handlebars index 1bf2d3175..c3c5f353a 100644 --- a/backend/src/services/smtp/templates/secretLeakIncident.handlebars +++ b/backend/src/services/smtp/templates/secretLeakIncident.handlebars @@ -9,7 +9,7 @@

Infisical has uncovered {{numberOfSecrets}} secret(s) from your recent push

-

View leaked secrets

+

View leaked secrets

You are receiving this notification because one or more secret leaks have been detected in a recent commit pushed by {{pusher_name}} ({{pusher_email}}). If these are test secrets, please add `infisical-scan:ignore` at the end of the line containing the secret as comment @@ -18,7 +18,7 @@

If these are production secrets, please rotate them immediately.

Once you have taken action, be sure to update the status of the risk in your Infisical + href="{{siteUrl}}">Infisical dashboard.

diff --git a/backend/src/services/smtp/templates/signupEmailVerification.handlebars b/backend/src/services/smtp/templates/signupEmailVerification.handlebars index fc738d202..3ba18619f 100644 --- a/backend/src/services/smtp/templates/signupEmailVerification.handlebars +++ b/backend/src/services/smtp/templates/signupEmailVerification.handlebars @@ -11,7 +11,7 @@

Confirm your email address

Your confirmation code is below — enter it in the browser window where you've started signing up for Infisical.

{{code}}

-

Questions about setting up Infisical? Email us at support@infisical.com

+

Questions about setting up Infisical? {{#if isCloud}}Email us at support@infisical.com{{else}}Contact your administrator{{/if}}.

\ No newline at end of file