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 verIA comments
Thiago Araujo da Silva8484141524dd
diff --git a/backend/src/services/alert/channels/alert-channel-slack-fns.ts b/backend/src/services/alert/channels/alert-channel-slack-fns.tsindex fbc1db3819..841efd7ff7 100644--- a/backend/src/services/alert/channels/alert-channel-slack-fns.ts+++ b/backend/src/services/alert/channels/alert-channel-slack-fns.ts@@ -12,6 +12,9 @@ import { deliverWithRetry, isAxiosErrorRetryable } from "./alert-channel-retry-fconst MAX_ITEMS_DISPLAYED = 2;+const escapeSlackText = (value: string): string =>+ value.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");+const SEVERITY_COLOR: Record<TAlertSeverity, string> = {critical: "#da3633",error: "#da3633",@@ -30,11 +33,12 @@ export const buildSlackPayload = (payload: TAlertPayload): TSlackPayload => {const itemBlocks: TSlackBlock[] = [];displayItems.forEach((item, index) => {const fields: Array<{ type: "mrkdwn"; text: string }> = [- { type: "mrkdwn", text: `*Name:*\n${item.title || "N/A"}` }+ { type: "mrkdwn", text: `*Name:*\n${item.title ? escapeSlackText(item.title) : "N/A"}` }];- if (item.identifier) fields.push({ type: "mrkdwn", text: `*Identifier:*\n\`${item.identifier}\`` });+ if (item.identifier)+ fields.push({ type: "mrkdwn", text: `*Identifier:*\n\`${escapeSlackText(item.identifier)}\`` });(item.fields ?? []).forEach((field) => {- fields.push({ type: "mrkdwn", text: `*${field.label}:*\n${field.value}` });+ fields.push({ type: "mrkdwn", text: `*${escapeSlackText(field.label)}:*\n${escapeSlackText(field.value)}` });});itemBlocks.push({ type: "section", fields });@@ -42,16 +46,16 @@ export const buildSlackPayload = (payload: TAlertPayload): TSlackPayload => {});const alertInfoFields: Array<{ type: "mrkdwn"; text: string }> = [- { type: "mrkdwn", text: `*Alert:*\n${payload.alert.name}` }+ { type: "mrkdwn", text: `*Alert:*\n${escapeSlackText(payload.alert.name)}` }];if (payload.alert.condition) {- alertInfoFields.push({ type: "mrkdwn", text: `*Alert Before:*\n${payload.alert.condition}` });+ alertInfoFields.push({ type: "mrkdwn", text: `*Alert Before:*\n${escapeSlackText(payload.alert.condition)}` });}const attachmentBlocks: TSlackBlock[] = [{ type: "section", fields: alertInfoFields },{ type: "divider" },- { type: "section", text: { type: "mrkdwn", text: payload.summary } },+ { type: "section", text: { type: "mrkdwn", text: escapeSlackText(payload.summary) } },...itemBlocks];@@ -75,7 +79,7 @@ export const buildSlackPayload = (payload: TAlertPayload): TSlackPayload => {});return {- text: `${headerText} - ${payload.summary}`,+ text: escapeSlackText(`${headerText} - ${payload.summary}`),blocks: [{ type: "header", text: { type: "plain_text", text: headerText, emoji: true } }],attachments: [{ color, blocks: attachmentBlocks }]};diff --git a/backend/src/services/alert/channels/alert-channels.test.ts b/backend/src/services/alert/channels/alert-channels.test.tsindex 7d7f466f81..9b981f06f9 100644--- a/backend/src/services/alert/channels/alert-channels.test.ts+++ b/backend/src/services/alert/channels/alert-channels.test.ts@@ -99,6 +99,24 @@ describe("buildSlackPayload", () => {const contextBlock = slack.attachments?.[0].blocks.find((b) => b.type === "context");expect(contextBlock).toBeDefined();});++ test("escapes Slack control characters in resource-controlled values", () => {+ const payload = samplePayload();+ payload.alert.name = "<!channel> ping";+ payload.items[0].title = "<https://evil.com|View in Infisical>";+ payload.items[0].fields = [{ label: "Note", value: "a & b < c > d" }];++ const slack = buildSlackPayload(payload);+ // Everything mrkdwn-interpreted: the notification fallback + the attachment blocks.+ const mrkdwn = JSON.stringify({ text: slack.text, attachments: slack.attachments });++ expect(mrkdwn).not.toContain("<!channel>");+ expect(mrkdwn).not.toContain("<https://evil.com|");+ expect(mrkdwn).toContain("<!channel>");+ expect(mrkdwn).toContain("a & b < c > d");+ // The plain_text header does not parse markup, so it keeps the raw value.+ expect(slack.blocks[0].text?.text).toContain("<!channel> ping");+ });});describe("buildPagerDutyEvent", () => {diff --git a/backend/src/services/alert/providers/identity-credential-alert-provider.test.ts b/backend/src/services/alert/providers/identity-credential-alert-provider.test.tsindex 176f872cf4..ed67f15248 100644--- a/backend/src/services/alert/providers/identity-credential-alert-provider.test.ts+++ b/backend/src/services/alert/providers/identity-credential-alert-provider.test.ts@@ -4,8 +4,8 @@ import { vi } from "vitest";import { AlertPermissionAction, TAlertContext } from "../alert-types";import { TExpiringUaClientSecret } from "./identity-credential-alert-dal";import {+ IDENTITY_AUTHENTICATION_EXPIRY_EVENT,IDENTITY_AUTHENTICATION_RESOURCE_TYPE,- IDENTITY_CREDENTIAL_EXPIRY_EVENT,identityCredentialAlertProviderFactory,TIdentityCredentialAlertProviderDep} from "./identity-credential-alert-provider";@@ -32,7 +32,7 @@ const alertContext = (overrides: Partial<TAlertContext> = {}): TAlertContext =>orgId: "org-1",resourceType: IDENTITY_AUTHENTICATION_RESOURCE_TYPE,resourceId: null,- eventType: IDENTITY_CREDENTIAL_EXPIRY_EVENT,+ eventType: IDENTITY_AUTHENTICATION_EXPIRY_EVENT,condition: { alertBefore: "30d" },...overrides});@@ -98,7 +98,7 @@ describe("identity credential alert provider", () => {const targets = await provider.findDueTargets({orgId: "org-1",resourceId: "ident-1",- eventType: IDENTITY_CREDENTIAL_EXPIRY_EVENT,+ eventType: IDENTITY_AUTHENTICATION_EXPIRY_EVENT,condition: { alertBefore: "30d" }});@@ -120,7 +120,7 @@ describe("identity credential alert provider", () => {orgId: "org-1",projectId: "proj-1",resourceId: null,- eventType: IDENTITY_CREDENTIAL_EXPIRY_EVENT,+ eventType: IDENTITY_AUTHENTICATION_EXPIRY_EVENT,condition: { alertBefore: "30d" }});@@ -134,7 +134,7 @@ describe("identity credential alert provider", () => {const viewUrl = await provider.buildViewUrl(alertContext());const payload = provider.buildPayload(alertContext(), [target], viewUrl);- expect(payload.eventKey).toBe(IDENTITY_CREDENTIAL_EXPIRY_EVENT);+ expect(payload.eventKey).toBe(IDENTITY_AUTHENTICATION_EXPIRY_EVENT);expect(payload.severity).toBe("critical"); // 3 days outexpect(payload.alert.viewUrl).toBe(viewUrl);@@ -213,9 +213,13 @@ describe("identity credential alert provider", () => {test("assertPermission passes identityId into the subject for resource-bound project alerts", async () => {// Custom role / additional privilege scoped to a single identity. The check must// supply the identity id so CASL can match the conditioned rule; a bare subject- // would be rejected.+ // would be rejected. Edit-scoped alerts deliver credential metadata, so the role+ // must hold read on the same identity in addition to edit.const provider = buildProvider({- abilityRules: [{ action: "edit", subject: "identity", conditions: { identityId: "ident-1" } }]+ abilityRules: [+ { action: "edit", subject: "identity", conditions: { identityId: "ident-1" } },+ { action: "read", subject: "identity", conditions: { identityId: "ident-1" } }+ ]});await expect(provider.assertPermission({@@ -250,10 +254,64 @@ describe("identity credential alert provider", () => {).rejects.toThrow();});- test("assertPermission allows a filter-based project alert with an unconditional project-wide identity grant", async () => {+ test("assertPermission allows a filter-based project alert with unconditional project-wide identity edit + read", async () => {+ const provider = buildProvider({+ abilityRules: [+ { action: "edit", subject: "identity" },+ { action: "read", subject: "identity" }+ ]+ });+ await expect(+ provider.assertPermission({ action: AlertPermissionAction.Edit, orgId: "org-1", projectId: "proj-1", actor })+ ).resolves.toBeUndefined();+ });++ test("assertPermission denies create/edit when identity edit is granted but read is missing (org scope)", async () => {+ // The alert fans out identity credential metadata, which normally requires identity read.+ // An edit-only role must not be able to stand up that data feed.+ const provider = buildProvider({ abilityRules: [{ action: "edit", subject: "identity" }] });+ await expect(+ provider.assertPermission({ action: AlertPermissionAction.Create, orgId: "org-1", actor })+ ).rejects.toThrow();+ await expect(+ provider.assertPermission({ action: AlertPermissionAction.Edit, orgId: "org-1", actor })+ ).rejects.toThrow();+ });++ test("assertPermission denies a resource-bound create/edit when read on that identity is missing", async () => {+ const provider = buildProvider({+ abilityRules: [{ action: "edit", subject: "identity", conditions: { identityId: "ident-1" } }]+ });+ await expect(+ provider.assertPermission({+ action: AlertPermissionAction.Edit,+ orgId: "org-1",+ projectId: "proj-1",+ resourceId: "ident-1",+ actor+ })+ ).rejects.toThrow();+ });++ test("assertPermission denies a filter-based create/edit with project-wide edit but no read", async () => {const provider = buildProvider({ abilityRules: [{ action: "edit", subject: "identity" }] });await expect(provider.assertPermission({ action: AlertPermissionAction.Edit, orgId: "org-1", projectId: "proj-1", actor })+ ).rejects.toThrow();+ });++ test("assertPermission allows delete with identity edit only (delete delivers no data)", async () => {+ const provider = buildProvider({ abilityRules: [{ action: "edit", subject: "identity" }] });+ await expect(+ provider.assertPermission({ action: AlertPermissionAction.Delete, orgId: "org-1", actor })+ ).resolves.toBeUndefined();+ await expect(+ provider.assertPermission({+ action: AlertPermissionAction.Delete,+ orgId: "org-1",+ projectId: "proj-1",+ actor+ })).resolves.toBeUndefined();});diff --git a/backend/src/services/alert/providers/identity-credential-alert-provider.ts b/backend/src/services/alert/providers/identity-credential-alert-provider.tsindex fbe34d0c2e..a8fe23025f 100644--- a/backend/src/services/alert/providers/identity-credential-alert-provider.ts+++ b/backend/src/services/alert/providers/identity-credential-alert-provider.ts@@ -21,7 +21,7 @@ import {import { TExpiringUaClientSecret, TIdentityCredentialAlertDALFactory } from "./identity-credential-alert-dal";export const IDENTITY_AUTHENTICATION_RESOURCE_TYPE = "identity.authentication";-export const IDENTITY_CREDENTIAL_EXPIRY_EVENT = "identity.credential.expiry";+export const IDENTITY_AUTHENTICATION_EXPIRY_EVENT = "identity.authentication.expiry";const alertBeforeRegex = new RE2("^\\d+[dwmy]$");@@ -145,14 +145,14 @@ export const identityCredentialAlertProviderFactory = ({...(alertBefore ? { condition: alertBefore } : {}),viewUrl},- eventKey: IDENTITY_CREDENTIAL_EXPIRY_EVENT,+ eventKey: IDENTITY_AUTHENTICATION_EXPIRY_EVENT,eventLabel: "Expiration",- webhookType: "com.infisical.identity.credential.expiration",- resourceKind: "Identity Credential",+ webhookType: "com.infisical.identity.authentication.expiration",+ resourceKind: "Machine Identity Authentication",severity: severityFor(targets),summary: alertBefore- ? `${targets.length} identity credential(s) expiring within ${humanizeAlertBefore(alertBefore)}`- : `${targets.length} identity credential(s) expiring`,+ ? `${targets.length} machine identity authentication(s) expiring within ${humanizeAlertBefore(alertBefore)}`+ : `${targets.length} machine identity authentication(s) expiring`,items: targets.map((target) => ({id: `${target.credentialType}:${target.id}`,title: target.identityName,@@ -189,6 +189,12 @@ export const identityCredentialAlertProviderFactory = ({const assertPermission = async (input: TAlertPermissionInput): Promise<void> => {const isRead = input.action === AlertPermissionAction.Read;+ const isDelete = input.action === AlertPermissionAction.Delete;+ const projectActions = (() => {+ if (isRead) return [ProjectPermissionIdentityActions.Read];+ if (isDelete) return [ProjectPermissionIdentityActions.Edit];+ return [ProjectPermissionIdentityActions.Edit, ProjectPermissionIdentityActions.Read];+ })();if (input.projectId) {const { permission } = await permissionService.getProjectPermission({@@ -199,25 +205,25 @@ export const identityCredentialAlertProviderFactory = ({actorOrgId: input.actor.actorOrgId,actionProjectType: ActionProjectType.Any});- const action = isRead ? ProjectPermissionIdentityActions.Read : ProjectPermissionIdentityActions.Edit;-- if (input.resourceId) {- ForbiddenError.from(permission).throwUnlessCan(- action,- subject(ProjectPermissionSub.Identity, { identityId: input.resourceId })- );- return;- }- ForbiddenError.from(permission).throwUnlessCan(action, ProjectPermissionSub.Identity);- const hasProjectWideGrant = permission- .rulesFor(action, ProjectPermissionSub.Identity)- .some((rule) => !rule.inverted && !rule.conditions);- if (!hasProjectWideGrant) {- throw new ForbiddenRequestError({- message:- "Project-wide identity permission is required to manage an alert that is not bound to a specific identity"- });+ for (const action of projectActions) {+ if (input.resourceId) {+ ForbiddenError.from(permission).throwUnlessCan(+ action,+ subject(ProjectPermissionSub.Identity, { identityId: input.resourceId })+ );+ } else {+ ForbiddenError.from(permission).throwUnlessCan(action, ProjectPermissionSub.Identity);+ const hasProjectWideGrant = permission+ .rulesFor(action, ProjectPermissionSub.Identity)+ .some((rule) => !rule.inverted && !rule.conditions);+ if (!hasProjectWideGrant) {+ throw new ForbiddenRequestError({+ message:+ "Project-wide identity permission is required to manage an alert that is not bound to a specific identity"+ });+ }+ }}return;}@@ -230,15 +236,19 @@ export const identityCredentialAlertProviderFactory = ({actorAuthMethod: input.actor.actorAuthMethod,actorOrgId: input.actor.actorOrgId});- ForbiddenError.from(permission).throwUnlessCan(- isRead ? OrgPermissionIdentityActions.Read : OrgPermissionIdentityActions.Edit,- OrgPermissionSubjects.Identity- );+ const orgActions = (() => {+ if (isRead) return [OrgPermissionIdentityActions.Read];+ if (isDelete) return [OrgPermissionIdentityActions.Edit];+ return [OrgPermissionIdentityActions.Edit, OrgPermissionIdentityActions.Read];+ })();+ for (const action of orgActions) {+ ForbiddenError.from(permission).throwUnlessCan(action, OrgPermissionSubjects.Identity);+ }};return {resourceType: IDENTITY_AUTHENTICATION_RESOURCE_TYPE,- eventTypes: [IDENTITY_CREDENTIAL_EXPIRY_EVENT],+ eventTypes: [IDENTITY_AUTHENTICATION_EXPIRY_EVENT],conditionSchema: IdentityCredentialConditionSchema,findDueTargets,buildViewUrl,diff --git a/backend/src/services/smtp/emails/AlertNotificationTemplate.tsx b/backend/src/services/smtp/emails/AlertNotificationTemplate.tsxindex 169e80af33..87667d0270 100644--- a/backend/src/services/smtp/emails/AlertNotificationTemplate.tsx+++ b/backend/src/services/smtp/emails/AlertNotificationTemplate.tsx@@ -109,10 +109,10 @@ export const AlertNotificationTemplate = ({export default AlertNotificationTemplate;AlertNotificationTemplate.PreviewProps = {- alertName: "prod-identity-credential-expiry",+ alertName: "prod-identity-authentication-expiry",eventLabel: "Expiration",- resourceKind: "Identity Credential",- summary: "2 identity credential(s) expiring within 30d",+ resourceKind: "Machine Identity Authentication",+ summary: "2 machine identity authentication(s) expiring within 30 days",severity: "critical",viewUrl: "https://infisical.com/organizations/org-1/access-management?selectedTab=identities",siteUrl: "https://infisical.com",diff --git a/frontend/src/hooks/api/alerts/types.ts b/frontend/src/hooks/api/alerts/types.tsindex bfee4ffd99..5dad773f04 100644--- a/frontend/src/hooks/api/alerts/types.ts+++ b/frontend/src/hooks/api/alerts/types.ts@@ -5,7 +5,7 @@ export enum AlertResourceType {}export enum AlertEventType {- IdentityCredentialExpiry = "identity.credential.expiry"+ IdentityAuthenticationExpiry = "identity.authentication.expiry"}export enum AlertChannelType {@@ -39,7 +39,7 @@ export const ALERT_RESOURCE_TYPE_LABELS: Record<AlertResourceType, string> = {};export const ALERT_EVENT_TYPE_LABELS: Record<AlertEventType, string> = {- [AlertEventType.IdentityCredentialExpiry]: "Expiration"+ [AlertEventType.IdentityAuthenticationExpiry]: "Expiration"};export const ALERT_CHANNEL_TYPE_LABELS: Record<AlertChannelType, string> = {diff --git a/frontend/src/views/AlertsPage/components/AlertForm.tsx b/frontend/src/views/AlertsPage/components/AlertForm.tsxindex 8b2edfec6a..1dc4c7939b 100644--- a/frontend/src/views/AlertsPage/components/AlertForm.tsx+++ b/frontend/src/views/AlertsPage/components/AlertForm.tsx@@ -98,7 +98,7 @@ const buildFormDefaults = (alert?: TAlert): TAlertForm => {name: "",description: "",resourceType: AlertResourceType.IdentityAuthentication,- eventType: AlertEventType.IdentityCredentialExpiry,+ eventType: AlertEventType.IdentityAuthenticationExpiry,alertBeforeValue: 7,alertBeforeUnit: AlertTimeUnit.Days,dailyReminder: false,@@ -114,7 +114,7 @@ const buildFormDefaults = (alert?: TAlert): TAlertForm => {description: alert.description ?? "",resourceType:(alert.resourceType as AlertResourceType) ?? AlertResourceType.IdentityAuthentication,- eventType: (alert.eventType as AlertEventType) ?? AlertEventType.IdentityCredentialExpiry,+ eventType: (alert.eventType as AlertEventType) ?? AlertEventType.IdentityAuthenticationExpiry,alertBeforeValue: value,alertBeforeUnit: unit,dailyReminder: alert.condition?.dailyReminder ?? false,@@ -205,8 +205,8 @@ export const AlertForm = ({const scopeDescription = isResourceScope? "Watches this machine identity's authentications": isProjectScope- ? "Watches every identity credential in this project"- : "Watches every identity credential in this organization";+ ? "Watches every machine identity authentication in this project"+ : "Watches every machine identity authentication in this organization";const onSubmit = async (data: TAlertForm) => {const alertBefore = `${data.alertBeforeValue}${data.alertBeforeUnit}`;@@ -347,7 +347,7 @@ export const AlertForm = ({<FixedField label="Event"><Badge variant="warning">{ALERT_EVENT_TYPE_LABELS[value]}</Badge><span className="text-xs text-muted">- Fires as the credential nears expiration+ Fires as the authentication nears expiration</span></FixedField>)}