🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.
TypeScript analyticsautogenevaluationlangchainlarge-language-modelsllama-indexllmllm-evaluationllm-observabilityllmopsmonitoringobservabilityopen-sourceopenaiplaygroundprompt-engineeringprompt-managementself-hostedycombinator
fix(worker): preserve encrypted webhook headers on disable (#13503)
Tobias Wochingerdafbc986e3a1
diff --git a/worker/src/__tests__/webhooks.test.ts b/worker/src/__tests__/webhooks.test.tsindex a7c89a4c43..5ef18964ad 100644--- a/worker/src/__tests__/webhooks.test.ts+++ b/worker/src/__tests__/webhooks.test.ts@@ -541,6 +541,9 @@ describe("Webhook Integration Tests", () => {throw new Error("Action not found");}+ const secretHeaderValue = "secret-api-key-value";+ const encryptedSecretHeaderValue = encrypt(secretHeaderValue);+await prisma.action.update({where: { id: actionId },data: {@@ -549,6 +552,15 @@ describe("Webhook Integration Tests", () => {config: {...(action.config as WebhookActionConfigWithSecrets),url: "https://webhook-error.example.com/test",+ requestHeaders: {+ "x-secret-api-key": {+ secret: true,+ value: encryptedSecretHeaderValue,+ },+ },+ displayHeaders: {+ "x-secret-api-key": { secret: true, value: "secr...alue" },+ },},},});@@ -617,6 +629,17 @@ describe("Webhook Integration Tests", () => {const config = updatedAction?.config as any;expect(config.lastFailingExecutionId).toBeDefined();expect(typeof config.lastFailingExecutionId).toBe("string");++ // Encrypted request headers are preserved when lastFailingExecutionId is written.+ expect(config.requestHeaders["x-secret-api-key"].value).toBe(+ encryptedSecretHeaderValue,+ );+ expect(config.requestHeaders["x-secret-api-key"].value).not.toBe(+ secretHeaderValue,+ );+ expect(decrypt(config.requestHeaders["x-secret-api-key"].value)).toBe(+ secretHeaderValue,+ );});it("should execute webhook with secret headers correctly", async () => {diff --git a/worker/src/queues/webhooks.ts b/worker/src/queues/webhooks.tsindex d5dc056e5b..d722c48824 100644--- a/worker/src/queues/webhooks.ts+++ b/worker/src/queues/webhooks.ts@@ -12,7 +12,7 @@ import {type ActionDomainWithSecrets,} from "@langfuse/shared";import { decrypt, createSignatureHeader } from "@langfuse/shared/encryption";-import { prisma } from "@langfuse/shared/src/db";+import { Prisma, prisma } from "@langfuse/shared/src/db";import {validateWebhookURL,whitelistFromEnv,@@ -292,14 +292,11 @@ async function executeHttpAction({isWebhookAction(actionConfig) ||isGitHubDispatchAction(actionConfig)) {- await tx.action.update({- where: { id: automation.action.id, projectId },- data: {- config: {- ...actionConfig.config,- lastFailingExecutionId: executionId,- } as any, // Cast needed for Prisma Json type- },+ await setActionLastFailingExecutionId({+ tx,+ actionId: automation.action.id,+ projectId,+ executionId,});}@@ -665,14 +662,11 @@ async function executeSlackAction({});// Update action config to store the failing execution ID- await tx.action.update({- where: { id: automation.action.id, projectId },- data: {- config: {- ...failureActionConfig.config,- lastFailingExecutionId: executionId,- },- },+ await setActionLastFailingExecutionId({+ tx,+ actionId: automation.action.id,+ projectId,+ executionId,});logger.warn(@@ -685,3 +679,31 @@ async function executeSlackAction({);}}++const setActionLastFailingExecutionId = async ({+ tx,+ actionId,+ projectId,+ executionId,+}: {+ tx: Prisma.TransactionClient;+ actionId: string;+ projectId: string;+ executionId: string;+}) => {+ // The execution config may contain decrypted headers, so patch only this JSON+ // key and leave the stored encrypted config untouched.+ await tx.$executeRaw`+ UPDATE actions+ SET+ config = jsonb_set(+ config,+ '{lastFailingExecutionId}',+ to_jsonb(${executionId}::text),+ true+ ),+ updated_at = NOW()+ WHERE id = ${actionId}+ AND project_id = ${projectId}+ `;+};