Skip to content

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

store parsed config

Thiago Araujo da Silva63eb1f9e360e
diff --git a/backend/src/services/alert/alert-channel-config-fns.ts b/backend/src/services/alert/alert-channel-config-fns.ts
index e23f3f1888..a49e6dc5b4 100644
--- a/backend/src/services/alert/alert-channel-config-fns.ts
+++ b/backend/src/services/alert/alert-channel-config-fns.ts
@@ -11,13 +11,13 @@ export const getChannelDefinition = (channelType: string): TAlertChannelDefiniti
return definition;
};
-export const assertChannelConfigValid = (
+export const parseChannelConfig = (
definition: Pick<TAlertChannelDefinition, "configSchema">,
channelType: string,
config: Record<string, unknown>
-) => {
+): Record<string, unknown> => {
try {
- definition.configSchema.parse(config);
+ return definition.configSchema.parse(config) as Record<string, unknown>;
} catch (err) {
const detail = err instanceof z.ZodError ? err.issues.map((i) => i.message).join(", ") : null;
throw new BadRequestError({
diff --git a/backend/src/services/alert/alert-channel-service.test.ts b/backend/src/services/alert/alert-channel-service.test.ts
index 2a7d762175..334ced30c2 100644
--- a/backend/src/services/alert/alert-channel-service.test.ts
+++ b/backend/src/services/alert/alert-channel-service.test.ts
@@ -215,6 +215,40 @@ describe("alert channel service", () => {
]);
});
+ test("stores webhook header names trimmed, so a redacted value can be kept later", async () => {
+ const { service, store } = buildService();
+ const created = await createChannel(
+ service,
+ {
+ name: "Ops webhook",
+ channelType: AlertChannelType.WEBHOOK,
+ config: { url: "https://example.com/hook", headers: [{ key: " Authorization ", value: "Bearer abc" }] },
+ orgId: "org-1",
+ ...CHANNEL_INPUT
+ },
+ encryptor as never,
+ tx
+ );
+
+ await updateChannel(
+ service,
+ {
+ recipientScope: RECIPIENT_SCOPE,
+ channelId: created.id,
+ config: {
+ url: "https://example.com/hook",
+ headers: [{ key: "Authorization", value: ALERT_CHANNEL_REDACTED_VALUE }]
+ }
+ },
+ store.get(created.id) as never,
+ cipher,
+ tx
+ );
+
+ const stored = JSON.parse(store.get(created.id)!.encryptedConfig.toString()) as Record<string, unknown>;
+ expect(stored.headers).toEqual([{ key: "Authorization", value: "Bearer abc" }]);
+ });
+
test("rejects a redacted webhook header that has no stored value", async () => {
const { service } = buildService();
const channel = seedRow({
diff --git a/backend/src/services/alert/alert-channel-service.ts b/backend/src/services/alert/alert-channel-service.ts
index b13a2316a6..11a86aec36 100644
--- a/backend/src/services/alert/alert-channel-service.ts
+++ b/backend/src/services/alert/alert-channel-service.ts
@@ -8,11 +8,7 @@ import { BadRequestError } from "@app/lib/errors";
import { TOrgDALFactory } from "@app/services/org/org-dal";
import { TProjectDALFactory } from "@app/services/project/project-dal";
-import {
- assertChannelConfigValid,
- getChannelDefinition,
- mergeChannelConfigWithStored
-} from "./alert-channel-config-fns";
+import { getChannelDefinition, mergeChannelConfigWithStored, parseChannelConfig } from "./alert-channel-config-fns";
import {
decryptChannelConfig,
encryptChannelConfig,
@@ -212,14 +208,14 @@ export const alertChannelServiceFactory = ({
const definition = getChannelDefinition(input.channelType);
const recipients = input.recipients ?? [];
$assertRecipientRules(definition, input.channelType, recipients);
- assertChannelConfigValid(definition, input.channelType, input.config);
+ const config = parseChannelConfig(definition, input.channelType, input.config);
await validateRecipients(input.orgId, input.recipientScope, recipients, tx);
return {
row: {
name: input.name,
channelType: input.channelType,
- encryptedConfig: encryptChannelConfig(input.config, encryptor),
+ encryptedConfig: encryptChannelConfig(config, encryptor),
enabled: input.enabled ?? true,
orgId: input.orgId,
projectId: input.projectId ?? null,
@@ -265,8 +261,7 @@ export const alertChannelServiceFactory = ({
let finalConfig = existingConfig;
if (input.config !== undefined) {
const merged = mergeChannelConfigWithStored(channel.channelType, input.config, existingConfig);
- assertChannelConfigValid(definition, channel.channelType, merged);
- finalConfig = merged;
+ finalConfig = parseChannelConfig(definition, channel.channelType, merged);
}
const { recipients } = input;
diff --git a/backend/src/services/alert/alert-channel-test-service.ts b/backend/src/services/alert/alert-channel-test-service.ts
index f8e10bbe5c..9887bb7607 100644
--- a/backend/src/services/alert/alert-channel-test-service.ts
+++ b/backend/src/services/alert/alert-channel-test-service.ts
@@ -4,11 +4,7 @@ import { logger } from "@app/lib/logger";
import { TKmsServiceFactory } from "@app/services/kms/kms-service";
import { TSmtpService } from "@app/services/smtp/smtp-service";
-import {
- assertChannelConfigValid,
- getChannelDefinition,
- mergeChannelConfigWithStored
-} from "./alert-channel-config-fns";
+import { getChannelDefinition, mergeChannelConfigWithStored, parseChannelConfig } from "./alert-channel-config-fns";
import { decryptChannelConfig, getAlertChannelCipher } from "./alert-channel-crypto-fns";
import { TAlertChannelDALFactory } from "./alert-channel-dal";
import { TAlertChannelServiceFactory } from "./alert-channel-service";
@@ -94,8 +90,7 @@ export const alertChannelTestServiceFactory = ({
const incoming = dto.config ?? {};
if (!dto.channelId) {
- assertChannelConfigValid(definition, dto.channelType, incoming);
- return incoming;
+ return parseChannelConfig(definition, dto.channelType, incoming);
}
const channel = await alertChannelDAL.findById(dto.channelId);
@@ -117,8 +112,7 @@ export const alertChannelTestServiceFactory = ({
const stored = decryptChannelConfig<Record<string, unknown>>(channel.encryptedConfig, decryptor);
const merged = mergeChannelConfigWithStored(dto.channelType, incoming, stored);
- assertChannelConfigValid(definition, dto.channelType, merged);
- return merged;
+ return parseChannelConfig(definition, dto.channelType, merged);
};
const $resolveRecipients = async (
diff --git a/backend/src/services/alert/channels/alert-channel-webhook-fns.ts b/backend/src/services/alert/channels/alert-channel-webhook-fns.ts
index 56bdb9798e..c4c5e73d33 100644
--- a/backend/src/services/alert/channels/alert-channel-webhook-fns.ts
+++ b/backend/src/services/alert/channels/alert-channel-webhook-fns.ts
@@ -105,11 +105,10 @@ const triggerWebhook = async (params: {
customHeaders?: TWebhookChannelHeader[];
}): Promise<void> => {
const { url, payload, signingSecret, customHeaders } = params;
- const headers: Record<string, string> = {};
- customHeaders?.forEach(({ key, value }) => {
- headers[key] = value;
- });
- headers["Content-Type"] = "application/json";
+ const headers: Record<string, string> = {
+ ...Object.fromEntries((customHeaders ?? []).map(({ key, value }) => [key, value])),
+ "Content-Type": "application/json"
+ };
if (signingSecret) {
const payloadString = JSON.stringify(payload);
diff --git a/frontend/src/views/Alerts/WebhookHeadersField.tsx b/frontend/src/views/Alerts/WebhookHeadersField.tsx
index 0facfb7511..c906b5d957 100644
--- a/frontend/src/views/Alerts/WebhookHeadersField.tsx
+++ b/frontend/src/views/Alerts/WebhookHeadersField.tsx
@@ -1,4 +1,3 @@
-import { useState } from "react";
import { useFieldArray, useFormContext } from "react-hook-form";
import { PlusIcon, TrashIcon } from "lucide-react";
@@ -31,8 +30,6 @@ export const WebhookHeadersField = ({ index, isExisting }: Props) => {
const { fields, append, remove } = useFieldArray({ control, name: `channels.${index}.headers` });
const headerErrors = errors.channels?.[index]?.headers;
- const [clearedRows, setClearedRows] = useState<Set<string>>(() => new Set());
-
return (
<Field>
<FieldLabel>
@@ -63,10 +60,13 @@ export const WebhookHeadersField = ({ index, isExisting }: Props) => {
onFocus={() => {
if (getValues(valueName) !== ALERT_CHANNEL_REDACTED_VALUE) return;
setValue(valueName, "");
- setClearedRows((current) => new Set(current).add(field.id));
}}
onBlur={() => {
- if (!clearedRows.has(field.id) || getValues(valueName) !== "") return;
+ if (
+ field.value !== ALERT_CHANNEL_REDACTED_VALUE ||
+ getValues(valueName) !== ""
+ )
+ return;
setValue(valueName, ALERT_CHANNEL_REDACTED_VALUE);
}}
/>