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.

fix(workflows): backtick-quote account external_id group type (#65509)

Arthur Moreira de Deus8e6367dea9f0
diff --git a/products/workflows/frontend/Workflows/hogflows/registry/actions/customer_analytics.test.ts b/products/workflows/frontend/Workflows/hogflows/registry/actions/customer_analytics.test.ts
index 0a3b1640883e..939ebb680432 100644
--- a/products/workflows/frontend/Workflows/hogflows/registry/actions/customer_analytics.test.ts
+++ b/products/workflows/frontend/Workflows/hogflows/registry/actions/customer_analytics.test.ts
@@ -86,13 +86,18 @@ describe('customer analytics action registry', () => {
describe('buildAccountExternalIdInputs', () => {
it('builds a name-based group key expression from the account group type index', () => {
const inputs = buildAccountExternalIdInputs(2, groupTypesMap([0, 'project'], [2, 'organization']))
- expect(inputs).toEqual({ external_id: { value: '{groups["organization"].id}' } })
+ expect(inputs).toEqual({ external_id: { value: '{groups.`organization`.id}' } })
})
- it('quotes the group type so a name with template delimiters is escaped, not injected', () => {
+ it('backtick-quotes the group type so a name with template delimiters is escaped, not injected', () => {
const malicious = '"].id} + inject {groups["x'
const inputs = buildAccountExternalIdInputs(0, groupTypesMap([0, malicious]))
- expect(inputs).toEqual({ external_id: { value: `{groups[${JSON.stringify(malicious)}].id}` } })
+ expect(inputs).toEqual({ external_id: { value: '{groups.`"].id} + inject {groups["x`.id}' } })
+ })
+
+ it('escapes backticks in the group type by doubling them', () => {
+ const inputs = buildAccountExternalIdInputs(0, groupTypesMap([0, 'we`ird']))
+ expect(inputs).toEqual({ external_id: { value: '{groups.`we``ird`.id}' } })
})
it.each([null, undefined])('returns undefined when the account group type index is %s', (index) => {
diff --git a/products/workflows/frontend/Workflows/hogflows/registry/actions/customer_analytics.ts b/products/workflows/frontend/Workflows/hogflows/registry/actions/customer_analytics.ts
index 7f95a8538654..0d112f8a84bb 100644
--- a/products/workflows/frontend/Workflows/hogflows/registry/actions/customer_analytics.ts
+++ b/products/workflows/frontend/Workflows/hogflows/registry/actions/customer_analytics.ts
@@ -15,8 +15,14 @@ export const buildAccountExternalIdInputs = (
return undefined
}
const groupType = groupTypes.get(accountGroupTypeIndex as GroupTypeIndex)?.group_type
- // Quote the group type as a property key — an ingested name with template delimiters must not break out of the Hog expression.
- return groupType ? { external_id: { value: `{groups[${JSON.stringify(groupType)}].id}` } } : undefined
+ if (!groupType) {
+ return undefined
+ }
+ // Backtick-quote the group type as an identifier. Bracket access (`groups["x"]`) compiles the index as a
+ // separate global lookup and fails at runtime; backtick quoting escapes any name (delimiters, spaces, backticks
+ // via doubling) without breaking out of the Hog expression.
+ const quotedGroupType = groupType.replace(/`/g, '``')
+ return { external_id: { value: `{groups.\`${quotedGroupType}\`.id}` } }
}
const getAccountExternalIdDefaultInputs = (): Record<string, CyclotronInputType> | undefined =>