Skip to content

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

reject wide scope alerts

Thiago Araujo da Silva8485be081246
diff --git a/backend/src/services/alert/alert-service.test.ts b/backend/src/services/alert/alert-service.test.ts
index 1910cfbc68..a6f64b3244 100644
--- a/backend/src/services/alert/alert-service.test.ts
+++ b/backend/src/services/alert/alert-service.test.ts
@@ -219,6 +219,7 @@ const webhookChannel: TAlertChannelInput = {
const validCreate = {
name: "test-alert",
resourceType: RESOURCE_TYPE,
+ resourceId: "resource-1",
eventType: "test.resource.expiration",
condition: { alertBefore: "30d" },
channels: [emailChannel, webhookChannel],
@@ -256,9 +257,9 @@ describe("alert service", () => {
);
});
- test("skips the resource-scope check for a filter-based alert (no resourceId)", async () => {
- const { service } = buildService({ resourceScopeThrows: true });
- await expect(service.createAlert(validCreate)).resolves.toBeDefined();
+ test("rejects a resource-less (scope-wide) alert as unsupported", async () => {
+ const { service } = buildService();
+ await expect(service.createAlert({ ...validCreate, resourceId: undefined })).rejects.toThrow(/not supported yet/);
});
test("rejects a condition that fails the provider schema", async () => {
diff --git a/backend/src/services/alert/alert-service.ts b/backend/src/services/alert/alert-service.ts
index fbf18b5349..6a5dddbcea 100644
--- a/backend/src/services/alert/alert-service.ts
+++ b/backend/src/services/alert/alert-service.ts
@@ -112,6 +112,13 @@ export const alertServiceFactory = ({
});
const createAlert = async (dto: TCreateAlertDTO): Promise<TAlertResponse> => {
+ if (!dto.resourceId) {
+ throw new BadRequestError({
+ message:
+ "Alerts must be bound to a specific resource. Organization wide and project wide alerts are not supported yet."
+ });
+ }
+
const provider = $getProvider(dto.resourceType);
$validate(provider, dto, { alwaysValidateCondition: true });
diff --git a/backend/src/services/alert/providers/identity-credential-alert-provider.ts b/backend/src/services/alert/providers/identity-credential-alert-provider.ts
index 05f57b8629..ef4eaa96b1 100644
--- a/backend/src/services/alert/providers/identity-credential-alert-provider.ts
+++ b/backend/src/services/alert/providers/identity-credential-alert-provider.ts
@@ -89,7 +89,12 @@ export const identityCredentialAlertProviderFactory = ({
identityCredentialAlertDAL,
permissionService
}: TIdentityCredentialAlertProviderDep): IResourceAlertProvider<TIdentityCredentialTarget> => {
- const projectBaseUrl = (siteUrl: string, orgId: string, projectType: string, projectId: string): string => {
+ const projectBaseUrl = (
+ siteUrl: string | undefined,
+ orgId: string,
+ projectType: string,
+ projectId: string
+ ): string => {
switch (projectType) {
case ProjectType.SecretManager:
return `${siteUrl}/organizations/${orgId}/projects/secret-management/${projectId}`;
@@ -102,7 +107,7 @@ export const identityCredentialAlertProviderFactory = ({
const buildViewUrl = async (alert: TAlertContext): Promise<string> => {
const appCfg = getConfig();
- const siteUrl = appCfg.SITE_URL ?? "https://app.infisical.com";
+ const siteUrl = appCfg.SITE_URL;
if (alert.projectId) {
const projectType = await identityCredentialAlertDAL.getProjectType(alert.projectId);