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
fix(reminders): keep chosen recipients on legacy updates and cap reminder channels
Calvineb3b254942f3
diff --git a/backend/src/services/reminder/reminder-service.test.ts b/backend/src/services/reminder/reminder-service.test.tsindex 9c53576957..daee9f7e2d 100644--- a/backend/src/services/reminder/reminder-service.test.ts+++ b/backend/src/services/reminder/reminder-service.test.ts@@ -358,10 +358,45 @@ describe("reminder alert sync", () => {test("resolving recipients refuses a list with nobody left in the project", async () => {const { service } = buildWriteService({ projectUserIds: [] });await expect(- service.resolveReminderRecipients({ actorOrgId: "org-1", projectId: "proj-1", recipients: ["user-gone"] })+ service.resolveReminderRecipients({+ actorOrgId: "org-1",+ projectId: "proj-1",+ secretId: "secret-1",+ recipients: ["user-gone"]+ })).rejects.toThrow(/None of the selected reminder recipients/);});+ test("refuses more email recipients than fit beside the alert's other channels", async () => {+ const webhookOnly = {+ id: "alert-1",+ name: "Reminder for DB_PASSWORD",+ resourceId: "secret-1",+ channels: [{ id: "ch-hook", name: "Webhook", channelType: "webhook", enabled: true }]+ };+ const { service, calls } = buildWriteService({ existingAlert: webhookOnly });+ const recipients = Array.from({ length: 200 }, (_, i) => `user-${i}`);++ await expect(saveReminder(service, { recipients })).rejects.toThrow(+ "This reminder already sends to 1 other channels, so it can email at most 180 recipients."+ );+ expect(calls).toEqual([]);+ });++ test("accepts as many email recipients as fit beside the alert's other channels", async () => {+ const webhookOnly = {+ id: "alert-1",+ name: "Reminder for DB_PASSWORD",+ resourceId: "secret-1",+ channels: [{ id: "ch-hook", name: "Webhook", channelType: "webhook", enabled: true }]+ };+ const { service, updated } = buildWriteService({ existingAlert: webhookOnly });+ const recipients = Array.from({ length: 180 }, (_, i) => `user-${i}`);++ await saveReminder(service, { recipients });+ expect(updated[0].channels).toHaveLength(10);+ });+test("given channels, saves them as the alert's complete channel list", async () => {const channels = [{diff --git a/backend/src/services/reminder/reminder-service.ts b/backend/src/services/reminder/reminder-service.tsindex a7a4149a85..a49bb0dec3 100644--- a/backend/src/services/reminder/reminder-service.ts+++ b/backend/src/services/reminder/reminder-service.ts@@ -13,7 +13,7 @@ import { TGenericPermission } from "@app/lib/types";import { TAlertChannelInput, TChannelRecipientInput } from "../alert/alert-channel-service-types";import { AlertChannelType } from "../alert/alert-channel-types";import { TAlertServiceFactory } from "../alert/alert-service";-import { AlertPrincipalType, MAX_RECIPIENTS_PER_CHANNEL } from "../alert/alert-types";+import { AlertPrincipalType, MAX_CHANNELS_PER_ALERT, MAX_RECIPIENTS_PER_CHANNEL } from "../alert/alert-types";import { ActorAuthMethod, ActorType } from "../auth/auth-type";import { TEventEmitter } from "../event-outbox/event-outbox-types";import { TSecretFolderDALFactory } from "../secret-folder/secret-folder-dal";@@ -85,6 +85,7 @@ export const reminderServiceFactory = ({const resolveReminderRecipients: TReminderServiceFactory["resolveReminderRecipients"] = async ({actorOrgId,projectId,+ secretId,recipients}) => {// Reminder recipients were never pruned when someone left the project, so drop them rather than fail.@@ -100,7 +101,28 @@ export const reminderServiceFactory = ({message: "None of the selected reminder recipients are members of this project. Choose recipients again."});}- return inScope.length ? inScope : [{ principalType: AlertPrincipalType.PROJECT_MEMBERS, principalId: projectId }];+ const emailRecipients: TChannelRecipientInput[] = inScope.length+ ? inScope+ : [{ principalType: AlertPrincipalType.PROJECT_MEMBERS, principalId: projectId }];++ // The email channels sit beside the alert's other channels (Slack, webhook, PagerDuty), and the alert+ // API refuses to save more than MAX_CHANNELS_PER_ALERT in total. Writing past it here would leave an+ // alert nobody can edit until a channel is removed.+ const [existing] = await alertService.findAlertChannelSummariesForResources({+ resourceType: SECRET_REMINDER_RESOURCE_TYPE,+ resourceIds: [secretId]+ });+ const otherChannelCount =+ existing?.channels.filter((channel) => channel.channelType !== AlertChannelType.EMAIL).length ?? 0;+ const emailChannelCount = Math.ceil(emailRecipients.length / MAX_RECIPIENTS_PER_CHANNEL);+ if (otherChannelCount + emailChannelCount > MAX_CHANNELS_PER_ALERT) {+ const maxRecipients = Math.max(MAX_CHANNELS_PER_ALERT - otherChannelCount, 0) * MAX_RECIPIENTS_PER_CHANNEL;+ throw new BadRequestError({+ message: `This reminder already sends to ${otherChannelCount} other channels, so it can email at most ${maxRecipients} recipients. Remove recipients or channels and try again.`+ });+ }++ return emailRecipients;};// Given `channels`, they are the alert's complete channel list. Otherwise the reminder API only knows@@ -249,7 +271,8 @@ export const reminderServiceFactory = ({}const emailRecipients =- resolvedRecipients ?? (await resolveReminderRecipients({ actorOrgId: actor.actorOrgId, projectId, recipients }));+ resolvedRecipients ??+ (await resolveReminderRecipients({ actorOrgId: actor.actorOrgId, projectId, secretId, recipients }));// The alert goes first, outside any transaction because encrypting channel config can call out to// KMS. If the reminder write then fails, an alert with no reminder never fires and is reused next time.diff --git a/backend/src/services/reminder/reminder-types.ts b/backend/src/services/reminder/reminder-types.tsindex 9126407aec..97bc7b4a55 100644--- a/backend/src/services/reminder/reminder-types.ts+++ b/backend/src/services/reminder/reminder-types.ts@@ -45,6 +45,7 @@ export interface TReminderServiceFactory {resolveReminderRecipients: (input: {actorOrgId: string;projectId: string;+ secretId: string;recipients?: string[] | null;}) => Promise<TChannelRecipientInput[]>;diff --git a/backend/src/services/secret-v2-bridge/secret-v2-bridge-service.ts b/backend/src/services/secret-v2-bridge/secret-v2-bridge-service.tsindex 820127b147..bafdd53497 100644--- a/backend/src/services/secret-v2-bridge/secret-v2-bridge-service.ts+++ b/backend/src/services/secret-v2-bridge/secret-v2-bridge-service.ts@@ -803,6 +803,7 @@ export const secretV2BridgeServiceFactory = ({? await reminderService.resolveReminderRecipients({actorOrgId,projectId,+ secretId,recipients: inputSecret.secretReminderRecipients}): undefined;diff --git a/backend/src/services/secret/secret-service.ts b/backend/src/services/secret/secret-service.tsindex 6fbaa9bb8d..8b43280248 100644--- a/backend/src/services/secret/secret-service.ts+++ b/backend/src/services/secret/secret-service.ts@@ -2080,6 +2080,7 @@ export const secretServiceFactory = ({metadata,secretReminderRepeatDays,secretReminderNote,+ secretReminderRecipients,newSecretName,secretKeyIV: secretKeyEncrypted.iv,secretKeyTag: secretKeyEncrypted.tag,diff --git a/backend/src/services/secret/secret-types.ts b/backend/src/services/secret/secret-types.tsindex 09cecf0930..6130d4ab8d 100644--- a/backend/src/services/secret/secret-types.ts+++ b/backend/src/services/secret/secret-types.ts@@ -103,6 +103,7 @@ export type TUpdateSecretDTO = {skipMultilineEncoding?: boolean | null;secretReminderRepeatDays?: number | null;secretReminderNote?: string | null;+ secretReminderRecipients?: string[] | null;metadata?: {source?: string;};