Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

feat(workflows): offer destinations with secret inputs as workflow steps (#107640)

Meikel Ratza8dac11e8d85
diff --git a/nodejs/src/cdp/workflows-e2e.serial.test.ts b/nodejs/src/cdp/workflows-e2e.serial.test.ts
index e85c445dbeb6..49856a250529 100644
--- a/nodejs/src/cdp/workflows-e2e.serial.test.ts
+++ b/nodejs/src/cdp/workflows-e2e.serial.test.ts
@@ -469,6 +469,86 @@ describe('Workflows E2E (postgres-v2)', () => {
})
})
+ describe('workflow with a secret function input: trigger → function → exit', () => {
+ const secretApiKey = 'workflows-e2e-secret-api-key-0000'
+ let workflowId: string
+
+ beforeEach(async () => {
+ await insertHogFunctionTemplate(hub.postgres, {
+ id: 'template-workflows-e2e-secret-fetch',
+ name: 'Workflows E2E Secret Fetch',
+ code: `
+ let res := fetch(inputs.url, {'method': 'POST', 'headers': {'Authorization': f'Bearer {inputs.api_key}'}});
+ print('Fetch result:', res.status);
+ `,
+ inputs_schema: [
+ { key: 'url', type: 'string', required: true },
+ { key: 'api_key', type: 'string', required: true, secret: true },
+ ],
+ })
+
+ workflowId = await createWorkflow({
+ actions: {
+ trigger: trigger(),
+ send_with_secret: {
+ type: 'function',
+ config: {
+ template_id: 'template-workflows-e2e-secret-fetch',
+ inputs: { url: { value: 'https://example.com/secret-webhook' } },
+ },
+ },
+ exit: exitAction(),
+ },
+ edges: [
+ { from: 'trigger', to: 'send_with_secret', type: 'continue' },
+ { from: 'send_with_secret', to: 'exit', type: 'continue' },
+ ],
+ })
+
+ // Mirrors what the hog flow API stores on save: the secret input is stripped out of the
+ // plaintext `actions` and kept Fernet-encrypted in `encrypted_inputs`, keyed by action id.
+ await hub.postgres.query(
+ PostgresUse.COMMON_WRITE,
+ `UPDATE posthog_hogflow SET encrypted_inputs = $2 WHERE id = $1`,
+ [
+ workflowId,
+ hub.encryptedFields.encrypt(
+ JSON.stringify({ send_with_secret: { api_key: { value: secretApiKey } } })
+ ),
+ ],
+ 'setWorkflowEncryptedInputs'
+ )
+ globals = createGlobals()
+ })
+
+ it('sends the decrypted secret and keeps it out of logs and stored jobs', async () => {
+ await triggerWorkflow(globals)
+
+ await waitForExpect(() => {
+ expect(mockFetch).toHaveBeenCalledTimes(1)
+ }, 10000)
+ expect(mockFetch).toHaveBeenCalledWith(
+ 'https://example.com/secret-webhook',
+ expect.objectContaining({
+ method: 'POST',
+ headers: expect.objectContaining({ Authorization: `Bearer ${secretApiKey}` }),
+ })
+ )
+
+ await waitForExpect(() => {
+ const logs = mockProducerObserver
+ .getProducedKafkaMessagesForTopic(KAFKA_LOG_ENTRIES)
+ .filter((m: any) => m.value.log_source_id === workflowId)
+ expect(logs.map((m: any) => m.value.message)).toContainEqual(
+ expect.stringContaining('Fetch result:, 200')
+ )
+ expect(JSON.stringify(logs)).not.toContain(secretApiKey)
+ }, 5000)
+
+ expect(JSON.stringify(await queryCyclotronJobs())).not.toContain(secretApiKey)
+ })
+ })
+
describe('delay workflow: trigger → delay → function → exit', () => {
beforeEach(async () => {
await createWorkflow({
diff --git a/nodejs/tests/fixtures/hog-bytecode/b8b8d5945fabcf43ebecf99cc931687f1c91e8d4c37a11a7f6bacb3e4b124bae.json b/nodejs/tests/fixtures/hog-bytecode/b8b8d5945fabcf43ebecf99cc931687f1c91e8d4c37a11a7f6bacb3e4b124bae.json
new file mode 100644
index 000000000000..700aac7c769b
--- /dev/null
+++ b/nodejs/tests/fixtures/hog-bytecode/b8b8d5945fabcf43ebecf99cc931687f1c91e8d4c37a11a7f6bacb3e4b124bae.json
@@ -0,0 +1 @@
+["_H",1,32,"url",32,"inputs",1,2,32,"method",32,"POST",32,"headers",32,"Authorization",32,"Bearer ",32,"api_key",32,"inputs",1,2,2,"concat",2,42,1,42,2,2,"fetch",2,32,"Fetch result:",36,0,32,"status",45,2,"print",2,35,35]
diff --git a/products/workflows/frontend/Workflows/hogflows/panel/HogFlowEditorPanelBuild.tsx b/products/workflows/frontend/Workflows/hogflows/panel/HogFlowEditorPanelBuild.tsx
index b8375960bf51..4ad2b2887419 100644
--- a/products/workflows/frontend/Workflows/hogflows/panel/HogFlowEditorPanelBuild.tsx
+++ b/products/workflows/frontend/Workflows/hogflows/panel/HogFlowEditorPanelBuild.tsx
@@ -12,6 +12,7 @@ import { teamLogic } from 'scenes/teamLogic'
import { HogFunctionTemplateType } from '~/types'
import { CreateActionType, hogFlowEditorLogic } from '../hogFlowEditorLogic'
+import { destinationPickerFilter } from './destinationPickerFilter'
// Side-effect imports: register product-specific trigger and action nodes
import '../registry'
@@ -258,22 +259,7 @@ function HogFlowEditorToolbarSection({ title, children }: { title: string; child
)
}
-// For now we only want to show destinations that do not have secrets and not coming soon
-const customFilterFunction = (template: HogFunctionTemplateType): boolean => {
- if (template.type !== 'destination' || TEMPLATE_IDS_AT_TOP_LEVEL.includes(template.id)) {
- return false
- }
-
- if (template.type === 'destination' && template.inputs_schema?.some((input) => input.secret)) {
- return false
- }
-
- if (['hidden', 'coming_soon'].includes(template.status)) {
- return false
- }
-
- return true
-}
+const customFilterFunction = destinationPickerFilter(TEMPLATE_IDS_AT_TOP_LEVEL)
function HogFunctionTemplatesChooser({
onActionSelect,
diff --git a/products/workflows/frontend/Workflows/hogflows/panel/destinationPickerFilter.test.ts b/products/workflows/frontend/Workflows/hogflows/panel/destinationPickerFilter.test.ts
new file mode 100644
index 000000000000..7f1e5b3ae049
--- /dev/null
+++ b/products/workflows/frontend/Workflows/hogflows/panel/destinationPickerFilter.test.ts
@@ -0,0 +1,50 @@
+import { HogFunctionTemplateType } from '~/types'
+
+import { destinationPickerFilter } from './destinationPickerFilter'
+
+const TOP_LEVEL_ID = 'template-already-a-button'
+
+const template = (overrides: Partial<HogFunctionTemplateType>): HogFunctionTemplateType =>
+ ({
+ id: 'template-example',
+ type: 'destination',
+ name: 'Example',
+ status: 'stable',
+ free: false,
+ code: '',
+ code_language: 'hog',
+ inputs_schema: [],
+ ...overrides,
+ }) as HogFunctionTemplateType
+
+describe('destinationPickerFilter', () => {
+ const isOffered = destinationPickerFilter([TOP_LEVEL_ID])
+
+ it.each([
+ [
+ 'offers a destination that declares a secret input',
+ template({
+ inputs_schema: [
+ { key: 'url', type: 'string', label: 'URL', secret: false },
+ { key: 'api_key', type: 'string', label: 'API key', secret: true },
+ ],
+ }),
+ true,
+ ],
+ ['offers a destination with no secret inputs', template({}), true],
+ [
+ 'leaves out a mapping destination that declares a secret input',
+ template({
+ inputs_schema: [{ key: 'api_token', type: 'string', label: 'API token', secret: true }],
+ mapping_templates: [{ name: 'Conversion', include_by_default: true, inputs_schema: [] }],
+ }),
+ false,
+ ],
+ ['leaves out a hidden destination', template({ status: 'hidden' }), false],
+ ['leaves out a destination that is coming soon', template({ status: 'coming_soon' }), false],
+ ['leaves out a destination that already has its own button', template({ id: TOP_LEVEL_ID }), false],
+ ['leaves out a template that is not a destination', template({ type: 'source_webhook' }), false],
+ ])('%s', (_name, candidate, expected) => {
+ expect(isOffered(candidate)).toBe(expected)
+ })
+})
diff --git a/products/workflows/frontend/Workflows/hogflows/panel/destinationPickerFilter.ts b/products/workflows/frontend/Workflows/hogflows/panel/destinationPickerFilter.ts
new file mode 100644
index 000000000000..5d8e81f923c9
--- /dev/null
+++ b/products/workflows/frontend/Workflows/hogflows/panel/destinationPickerFilter.ts
@@ -0,0 +1,23 @@
+import { HogFunctionTemplateType } from '~/types'
+
+// A secret input is no reason to leave a destination out: the hog flow API moves those inputs to
+// `encrypted_inputs` on save, so a workflow step holds an API key the way a destination does.
+export function destinationPickerFilter(
+ templateIdsAtTopLevel: string[]
+): (template: HogFunctionTemplateType) => boolean {
+ return (template: HogFunctionTemplateType): boolean => {
+ if (template.type !== 'destination' || templateIdsAtTopLevel.includes(template.id)) {
+ return false
+ }
+
+ // The hog flow worker does not apply a step's mappings, so a destination that reads its fields
+ // from mappings skips the event or sends empty fields. This check keeps out the mapping
+ // destinations that have a secret input. Mapping destinations without one, such as Google Ads,
+ // have the same gap and are still offered.
+ if (template.mapping_templates?.length && template.inputs_schema?.some((input) => input.secret)) {
+ return false
+ }
+
+ return !['hidden', 'coming_soon'].includes(template.status)
+ }
+}