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
PKI alerting payload fix
Carlos Monastyrski07547852fb34
diff --git a/backend/src/services/pki-alert-v2/pki-alert-v2-channel-email-fns.ts b/backend/src/services/pki-alert-v2/pki-alert-v2-channel-email-fns.tsindex 39b22e6df9..8671094f8a 100644--- a/backend/src/services/pki-alert-v2/pki-alert-v2-channel-email-fns.ts+++ b/backend/src/services/pki-alert-v2/pki-alert-v2-channel-email-fns.ts@@ -1,3 +1,4 @@+import { getConfig } from "@app/lib/config/env";import { delay } from "@app/lib/delay";import { logger } from "@app/lib/logger";import { SmtpTemplates, TSmtpService } from "@app/services/smtp/smtp-service";@@ -6,10 +7,12 @@ import { PKI_ALERT_RETRY_CONFIG, RETRYABLE_NETWORK_ERRORS } from "./pki-alert-v2import {getRevocationReasonLabel,PkiAlertEventType,+ TAlertInfo,TCertificatePreview,TChannelResult,TEmailChannelConfig} from "./pki-alert-v2-types";+import { buildAlertViewUrl } from "./pki-alert-v2-url-fns";const getEmailEventLabel = (eventType: PkiAlertEventType): string => {switch (eventType) {@@ -36,21 +39,22 @@ const isEmailErrorRetryable = (err: Error): boolean => {export const sendEmailNotification = async (smtpService: Pick<TSmtpService, "sendMail">,config: TEmailChannelConfig,- alertName: string,+ alert: TAlertInfo,alertBeforeDays: number,- projectId: string,matchingCertificates: TCertificatePreview[],eventType: PkiAlertEventType = PkiAlertEventType.EXPIRATION): Promise<void> => {const eventLabel = getEmailEventLabel(eventType);+ const appCfg = getConfig();+ const viewUrl = buildAlertViewUrl(appCfg.SITE_URL ?? "https://app.infisical.com", alert);await smtpService.sendMail({recipients: config.recipients,- subjectLine: `Infisical Certificate ${eventLabel} Alert - ${alertName}`,+ subjectLine: `Infisical Certificate ${eventLabel} Alert - ${alert.name}`,substitutions: {- alertName,+ alertName: alert.name,alertBeforeDays,- projectId,+ viewUrl,eventLabel,items: matchingCertificates.map((cert) => ({type: "Certificate",@@ -69,9 +73,8 @@ export const sendEmailNotification = async (export const sendEmailNotificationWithRetry = async (smtpService: Pick<TSmtpService, "sendMail">,config: TEmailChannelConfig,- alertName: string,+ alert: TAlertInfo,alertBeforeDays: number,- projectId: string,matchingCertificates: TCertificatePreview[],channelId: string,eventType: PkiAlertEventType = PkiAlertEventType.EXPIRATION@@ -82,15 +85,7 @@ export const sendEmailNotificationWithRetry = async (for (let attempt = 1; attempt <= maxRetries; attempt += 1) {try {// eslint-disable-next-line no-await-in-loop- await sendEmailNotification(- smtpService,- config,- alertName,- alertBeforeDays,- projectId,- matchingCertificates,- eventType- );+ await sendEmailNotification(smtpService, config, alert, alertBeforeDays, matchingCertificates, eventType);return { success: true };} catch (err) {lastError = err instanceof Error ? err : new Error(String(err));diff --git a/backend/src/services/pki-alert-v2/pki-alert-v2-channel-pagerduty-fns.ts b/backend/src/services/pki-alert-v2/pki-alert-v2-channel-pagerduty-fns.tsindex 487546ffdd..064267b5c9 100644--- a/backend/src/services/pki-alert-v2/pki-alert-v2-channel-pagerduty-fns.ts+++ b/backend/src/services/pki-alert-v2/pki-alert-v2-channel-pagerduty-fns.ts@@ -17,6 +17,7 @@ import {TPagerDutyChannelConfig,TPagerDutyPayload} from "./pki-alert-v2-types";+import { buildAlertViewUrl } from "./pki-alert-v2-url-fns";const PAGERDUTY_EVENTS_URL = "https://events.pagerduty.com/v2/enqueue";const PAGERDUTY_TIMEOUT = 7 * 1000;@@ -112,7 +113,7 @@ export const buildPagerDutyPayload = ({const displayCertificates = sortedCertificates.slice(0, MAX_CERTIFICATES_IN_PAYLOAD);- const viewUrl = `${appUrl}/projects/cert-manager/${alert.projectId}/policies`;+ const viewUrl = buildAlertViewUrl(appUrl, alert);const summary =eventType === PkiAlertEventType.EXPIRATIONdiff --git a/backend/src/services/pki-alert-v2/pki-alert-v2-channel-slack-fns.ts b/backend/src/services/pki-alert-v2/pki-alert-v2-channel-slack-fns.tsindex a80f719c85..668a47c564 100644--- a/backend/src/services/pki-alert-v2/pki-alert-v2-channel-slack-fns.ts+++ b/backend/src/services/pki-alert-v2/pki-alert-v2-channel-slack-fns.ts@@ -19,6 +19,7 @@ import {TSlackChannelConfig,TSlackPayload} from "./pki-alert-v2-types";+import { buildAlertViewUrl } from "./pki-alert-v2-url-fns";const SLACK_WEBHOOK_TIMEOUT = 7 * 1000;@@ -96,7 +97,7 @@ export const buildSlackPayload = ({const displayCertificates = sortedCertificates.slice(0, 2);const remainingCount = totalCertificates - displayCertificates.length;- const viewUrl = `${appUrl}/projects/cert-manager/${alert.projectId}/policies`;+ const viewUrl = buildAlertViewUrl(appUrl, alert);const headerText = `${label} Alert: ${alert.name}`;diff --git a/backend/src/services/pki-alert-v2/pki-alert-v2-channel-webhook-fns.ts b/backend/src/services/pki-alert-v2/pki-alert-v2-channel-webhook-fns.tsindex c21e71277d..6c082bc6b5 100644--- a/backend/src/services/pki-alert-v2/pki-alert-v2-channel-webhook-fns.ts+++ b/backend/src/services/pki-alert-v2/pki-alert-v2-channel-webhook-fns.ts@@ -19,6 +19,7 @@ import {TPkiWebhookPayload,TWebhookChannelConfig} from "./pki-alert-v2-types";+import { buildAlertViewUrl } from "./pki-alert-v2-url-fns";const PKI_WEBHOOK_TIMEOUT = 7 * 1000;@@ -94,15 +95,6 @@ const WEBHOOK_EVENT_SUBJECT: Record<PkiWebhookEventType, string> = {[PkiWebhookEventType.CERTIFICATE_TEST]: "certificate-test"};-const buildViewUrl = (params: { appUrl: string; alert: TAlertInfo }): string => {- const { appUrl, alert } = params;- const projectBase = `${appUrl}/organizations/${alert.orgId}/projects/cert-manager/${alert.projectId}`;- if (alert.applicationId && alert.applicationName) {- return `${projectBase}/applications/${alert.applicationName}`;- }- return `${projectBase}/inventory`;-};-const buildEventData = (params: {alert: TAlertInfo;certificates: TCertificatePreview[];@@ -120,7 +112,7 @@ const buildEventData = (params: {certificates: transformCertificates(params.certificates),metadata: {totalCertificates: params.certificates.length,- viewUrl: buildViewUrl({ appUrl: params.appUrl, alert: params.alert })+ viewUrl: buildAlertViewUrl(params.appUrl, params.alert)}}});diff --git a/backend/src/services/pki-alert-v2/pki-alert-v2-service.ts b/backend/src/services/pki-alert-v2/pki-alert-v2-service.tsindex 79661b47b1..b13dc935d2 100644--- a/backend/src/services/pki-alert-v2/pki-alert-v2-service.ts+++ b/backend/src/services/pki-alert-v2/pki-alert-v2-service.ts@@ -715,9 +715,8 @@ export const pkiAlertV2ServiceFactory = ({const result = await sendEmailNotificationWithRetry(smtpService,config,- alertName,+ alertData,alertBeforeDays,- projectId,matchingCertificates,channel.id,eventTypediff --git a/backend/src/services/pki-alert-v2/pki-alert-v2-url-fns.ts b/backend/src/services/pki-alert-v2/pki-alert-v2-url-fns.tsnew file mode 100644index 0000000000..b4b0431b4e--- /dev/null+++ b/backend/src/services/pki-alert-v2/pki-alert-v2-url-fns.ts@@ -0,0 +1,9 @@+import { TAlertInfo } from "./pki-alert-v2-types";++export const buildAlertViewUrl = (appUrl: string, alert: TAlertInfo): string => {+ const projectBase = `${appUrl}/organizations/${alert.orgId}/projects/cert-manager/${alert.projectId}`;+ if (alert.applicationId && alert.applicationName) {+ return `${projectBase}/applications/${alert.applicationName}`;+ }+ return `${projectBase}/inventory`;+};diff --git a/backend/src/services/smtp/emails/PkiExpirationAlertTemplate.tsx b/backend/src/services/smtp/emails/PkiExpirationAlertTemplate.tsxindex 927411f14c..287ba2a520 100644--- a/backend/src/services/smtp/emails/PkiExpirationAlertTemplate.tsx+++ b/backend/src/services/smtp/emails/PkiExpirationAlertTemplate.tsx@@ -6,7 +6,7 @@ import { BaseEmailWrapper, BaseEmailWrapperProps } from "./BaseEmailWrapper";interface PkiExpirationAlertTemplateProps extends Omit<BaseEmailWrapperProps, "title" | "preview" | "children"> {alertName: string;alertBeforeDays: number;- projectId: string;+ viewUrl: string;eventLabel?: string;items: { type: string; friendlyName: string; serialNumber: string; expiryDate: string; revocationReason?: string }[];}@@ -28,7 +28,7 @@ export const PkiExpirationAlertTemplate = ({alertName,siteUrl,alertBeforeDays,- projectId,+ viewUrl,eventLabel = "Expiration",items}: PkiExpirationAlertTemplateProps) => {@@ -102,7 +102,7 @@ export const PkiExpirationAlertTemplate = ({</Section><Section className="text-center mt-[32px] mb-[16px]">- <BaseButton href={`${siteUrl}/projects/cert-manager/${projectId}/policies`}>View Certificate Alerts</BaseButton>+ <BaseButton href={viewUrl}>View Certificate Alerts</BaseButton></Section></BaseEmailWrapper>);@@ -127,6 +127,6 @@ PkiExpirationAlertTemplate.PreviewProps = {}],alertName: "Production SSL Certificate Expiration Alert",- projectId: "c3b0ef29-915b-4cb1-8684-65b91b7fe02d",+ viewUrl: "https://infisical.com/organizations/org-1/projects/cert-manager/proj-1/inventory",siteUrl: "https://infisical.com"} as PkiExpirationAlertTemplateProps;