Skip to content

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

fix(pam): address review bot findings for slack notifications

bernie-gbf51614ae6a7
diff --git a/backend/src/ee/services/pam-access-request/pam-access-request-fns.ts b/backend/src/ee/services/pam-access-request/pam-access-request-fns.ts
index 2bb20c1335..daa140071c 100644
--- a/backend/src/ee/services/pam-access-request/pam-access-request-fns.ts
+++ b/backend/src/ee/services/pam-access-request/pam-access-request-fns.ts
@@ -24,8 +24,8 @@ export type TFolderNotificationConfigRow = {
workflowIntegrationId: string;
integration: string;
status: string;
- channels: unknown;
- events: unknown;
+ channels?: unknown;
+ events?: unknown;
};
// Channel ids are merged per integration so overlapping configs can't post the same message twice
@@ -37,14 +37,15 @@ export const getSlackSendTargets = (configs: TFolderNotificationConfigRow[], eve
config.integration === WorkflowIntegration.SLACK &&
config.status === WorkflowIntegrationStatus.INSTALLED &&
parseNotificationEvents(config.events).includes(event);
- if (!isSubscribed) continue;
- const channelIds = parseNotificationChannels(config.channels).map((channel) => channel.id);
- if (!channelIds.length) continue;
-
- const existing = channelIdsByIntegration.get(config.workflowIntegrationId) ?? new Set<string>();
- channelIds.forEach((id) => existing.add(id));
- channelIdsByIntegration.set(config.workflowIntegrationId, existing);
+ if (isSubscribed) {
+ const channelIds = parseNotificationChannels(config.channels).map((channel) => channel.id);
+ if (channelIds.length) {
+ const existing = channelIdsByIntegration.get(config.workflowIntegrationId) ?? new Set<string>();
+ channelIds.forEach((id) => existing.add(id));
+ channelIdsByIntegration.set(config.workflowIntegrationId, existing);
+ }
+ }
}
return [...channelIdsByIntegration.entries()].map(([workflowIntegrationId, channelIds]) => ({
diff --git a/backend/src/ee/services/pam-access-request/pam-access-request-service.ts b/backend/src/ee/services/pam-access-request/pam-access-request-service.ts
index c51cbcdde7..e40479acbc 100644
--- a/backend/src/ee/services/pam-access-request/pam-access-request-service.ts
+++ b/backend/src/ee/services/pam-access-request/pam-access-request-service.ts
@@ -768,25 +768,25 @@ export const pamAccessRequestServiceFactory = ({
} catch (err) {
logger.error(err, `Failed to send approval emails for PAM access request [requestId=${request.id}]`);
}
+ }
- void triggerFolderSlackNotifications({
- folderId: account.folderId,
- event: PamNotificationEvent.AccessRequested,
- orgId: ctx.actorOrgId,
- notification: {
- type: TriggerFeature.PAM_ACCESS_REQUESTED,
- payload: {
- requesterFullName: requesterName || "Unknown",
- requesterEmail: user.email ?? "",
- accountName: account.name,
- folderName: account.folderName ?? "",
- accessDuration: formatDuration(duration),
- reason: trimmedReason,
- approvalUrl
- }
+ void triggerFolderSlackNotifications({
+ folderId: account.folderId,
+ event: PamNotificationEvent.AccessRequested,
+ orgId: ctx.actorOrgId,
+ notification: {
+ type: TriggerFeature.PAM_ACCESS_REQUESTED,
+ payload: {
+ requesterFullName: requesterName || "Unknown",
+ requesterEmail: user.email ?? "",
+ accountName: account.name,
+ folderName: account.folderName ?? "",
+ accessDuration: formatDuration(duration),
+ reason: trimmedReason,
+ approvalUrl
}
- });
- }
+ }
+ });
return { request, accountId: account.id, folderId: account.folderId };
};
diff --git a/backend/src/services/license-client/dual-read/feature-mapping/core.ts b/backend/src/services/license-client/dual-read/feature-mapping/core.ts
index 78267a8d01..de2524e199 100644
--- a/backend/src/services/license-client/dual-read/feature-mapping/core.ts
+++ b/backend/src/services/license-client/dual-read/feature-mapping/core.ts
@@ -46,6 +46,11 @@ export const coreMappings: TFeatureMapping[] = [
v1Field: "eventSubscriptions",
extractV1: (p) => p.eventSubscriptions
},
+ {
+ v2Key: "pam_slack_notifications",
+ v1Field: "pamSlackNotifications",
+ extractV1: (p) => p.pamSlackNotifications
+ },
{
v2Key: "machine_identity_auth_templates",
v1Field: "machineIdentityAuthTemplates",
diff --git a/backend/src/services/slack/slack-fns.ts b/backend/src/services/slack/slack-fns.ts
index 133e96d67c..2519d9cdc6 100644
--- a/backend/src/services/slack/slack-fns.ts
+++ b/backend/src/services/slack/slack-fns.ts
@@ -11,6 +11,10 @@ import { TSendSlackNotificationDTO } from "./slack-types";
const COMPANY_BRAND_COLOR = "#e0ed34";
const ERROR_COLOR = "#e74c3c";
+// Escapes Slack control sequences in user-supplied text so a requester can't inject
+// mentions (<!channel>) or disguised links (<url|label>) into notification channels
+const escapeSlackMrkdwn = (text: string) => text.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
+
export const fetchSlackChannels = async (botKey: string) => {
const slackChannels: {
name: string;
@@ -257,9 +261,14 @@ const buildSlackPayload = (notification: TNotification) => {
}
case TriggerFeature.PAM_ACCESS_REQUESTED: {
const { payload } = notification;
-
- const messageBody = `${payload.requesterFullName} (${payload.requesterEmail}) has requested access to ${payload.accountName} in the ${payload.folderName} folder.\n\nDuration: ${payload.accessDuration}${
- payload.reason ? `\n\nReason: ${payload.reason}` : ""
+ const requesterFullName = escapeSlackMrkdwn(payload.requesterFullName);
+ const requesterEmail = escapeSlackMrkdwn(payload.requesterEmail);
+ const accountName = escapeSlackMrkdwn(payload.accountName);
+ const folderName = escapeSlackMrkdwn(payload.folderName);
+ const reason = payload.reason ? escapeSlackMrkdwn(payload.reason) : undefined;
+
+ const messageBody = `${requesterFullName} (${requesterEmail}) has requested access to ${accountName} in the ${folderName} folder.\n\nDuration: ${payload.accessDuration}${
+ reason ? `\n\nReason: ${reason}` : ""
}`;
const headerBlocks = [
@@ -278,8 +287,8 @@ const buildSlackPayload = (notification: TNotification) => {
type: "section",
text: {
type: "mrkdwn",
- text: `*${payload.requesterFullName}* (${payload.requesterEmail}) has requested access to *${payload.accountName}* in the *${payload.folderName}* folder.\n\n*Duration:* ${payload.accessDuration}${
- payload.reason ? `\n\n*Reason:* ${payload.reason}` : ""
+ text: `*${requesterFullName}* (${requesterEmail}) has requested access to *${accountName}* in the *${folderName}* folder.\n\n*Duration:* ${payload.accessDuration}${
+ reason ? `\n\n*Reason:* ${reason}` : ""
}`
}
},
@@ -312,9 +321,14 @@ const buildSlackPayload = (notification: TNotification) => {
const { payload } = notification;
const isApproved = notification.type === TriggerFeature.PAM_ACCESS_REQUEST_APPROVED;
const decision = isApproved ? "approved" : "denied";
-
- const messageBody = `The access request from ${payload.requesterFullName} (${payload.requesterEmail}) for ${payload.accountName} in the ${payload.folderName} folder has been ${decision}.${
- payload.comment ? `\n\nReviewer comment: ${payload.comment}` : ""
+ const requesterFullName = escapeSlackMrkdwn(payload.requesterFullName);
+ const requesterEmail = escapeSlackMrkdwn(payload.requesterEmail);
+ const accountName = escapeSlackMrkdwn(payload.accountName);
+ const folderName = escapeSlackMrkdwn(payload.folderName);
+ const comment = payload.comment ? escapeSlackMrkdwn(payload.comment) : undefined;
+
+ const messageBody = `The access request from ${requesterFullName} (${requesterEmail}) for ${accountName} in the ${folderName} folder has been ${decision}.${
+ comment ? `\n\nReviewer comment: ${comment}` : ""
}`;
const headerBlocks = [
@@ -333,8 +347,8 @@ const buildSlackPayload = (notification: TNotification) => {
type: "section",
text: {
type: "mrkdwn",
- text: `The access request from *${payload.requesterFullName}* (${payload.requesterEmail}) for *${payload.accountName}* in the *${payload.folderName}* folder has been *${decision}*.${
- payload.comment ? `\n\n*Reviewer comment:* ${payload.comment}` : ""
+ text: `The access request from *${requesterFullName}* (${requesterEmail}) for *${accountName}* in the *${folderName}* folder has been *${decision}*.${
+ comment ? `\n\n*Reviewer comment:* ${comment}` : ""
}`
}
},