: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.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(cdp): validate To field liquid template in native_email inputs (#68183)
Harley Alexandera5cbc0dfc3d1
diff --git a/frontend/src/lib/components/CyclotronJob/CyclotronJobInputsValidation.test.ts b/frontend/src/lib/components/CyclotronJob/CyclotronJobInputsValidation.test.tsindex c8e7f985f11b..c326e88b2f00 100644--- a/frontend/src/lib/components/CyclotronJob/CyclotronJobInputsValidation.test.ts+++ b/frontend/src/lib/components/CyclotronJob/CyclotronJobInputsValidation.test.ts@@ -1,4 +1,4 @@-import { CyclotronJobInputSchemaType } from '~/types'+import { CyclotronJobInputSchemaType, CyclotronJobInputType } from '~/types'import { CyclotronJobInputsValidation, TEMPLATING_MISMATCH_WARNINGS } from './CyclotronJobInputsValidation'@@ -215,6 +215,43 @@ describe('CyclotronJobInputsValidation', () => {})})+ describe('native_email To field (object form)', () => {+ // native_email stores `to` as { name, email }, unlike the legacy `email` type which stores a bare string.+ const nativeEmailInput = (+ to: unknown,+ templating: 'hog' | 'liquid' = 'liquid'+ ): Record<string, CyclotronJobInputType> => ({+ email: {+ templating,+ value: { html: '<p>Hi</p>', subject: 'Subject', from: { integrationId: 1 }, to },+ },+ })+ const schema: CyclotronJobInputSchemaType[] = [{ key: 'email', type: 'native_email', label: 'Email' }]++ // Dot notation on a $-prefixed, hyphenated survey key is invalid Liquid — the natural first attempt.+ it.each([+ [+ 'a malformed Liquid template',+ '{{ event.properties.$survey_response_1c0454ff-1138 }}',+ 'Liquid template error',+ ],+ ['an empty address', '', 'To is required'],+ ])('errors when to.email is %s', (_desc, email, expectedError) => {+ const result = CyclotronJobInputsValidation.validate(nativeEmailInput({ name: '', email }), schema)+ expect(result.valid).toBe(false)+ expect(result.errors.email).toContain(expectedError)+ })++ it('passes a valid bracket-notation Liquid template in to.email', () => {+ const result = CyclotronJobInputsValidation.validate(+ nativeEmailInput({ name: '', email: "{{ event.properties['$survey_response_1c0454ff-1138'] }}" }),+ schema+ )+ expect(result.valid).toBe(true)+ expect(result.errors).toEqual({})+ })+ })+describe('templating validation', () => {it('should validate liquid templates and return error on parse failure', () => {const inputs = { template: { value: '{% invalid %}', templating: 'liquid' as const } }diff --git a/frontend/src/lib/components/CyclotronJob/CyclotronJobInputsValidation.ts b/frontend/src/lib/components/CyclotronJob/CyclotronJobInputsValidation.tsindex 322767eec9ec..933a017bb4bd 100644--- a/frontend/src/lib/components/CyclotronJob/CyclotronJobInputsValidation.ts+++ b/frontend/src/lib/components/CyclotronJob/CyclotronJobInputsValidation.ts@@ -145,6 +145,10 @@ const validateInput = (input: CyclotronJobInputType, inputSchema: CyclotronJobIn}if (['email', 'native_email'].includes(inputSchema.type) && value) {+ // `native_email` stores `to` as { name, email }; the legacy `email` type stores a bare address string.+ // Pull out the address so it gets the same required + templating validation as every other field —+ // otherwise a malformed Liquid template in the To field (or an empty address) saves with no error.+ const toEmail = value.to && typeof value.to === 'object' ? value.to.email : value.toconst emailTemplateErrors: Partial<EmailTemplate> = {html:!value.html && !value.text@@ -155,7 +159,7 @@ const validateInput = (input: CyclotronJobInputType, inputSchema: CyclotronJobIntext: value.text ? getTemplatingError(value.text) : undefined,subject: !value.subject ? 'Subject is required' : getTemplatingError(value.subject),from: !value.from ? 'From is required' : getTemplatingError(value.from),- to: !value.to ? 'To is required' : getTemplatingError(value.to),+ to: !toEmail ? 'To is required' : getTemplatingError(toEmail),}const combinedErrors = Object.values(emailTemplateErrors)