: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(messaging): skip click tracking on links in sensitive emails (#125321)
Luke Belton769fd74c10ec
diff --git a/nodejs/src/cdp/services/messaging/email-tracking.service.test.ts b/nodejs/src/cdp/services/messaging/email-tracking.service.test.tsindex 1d5a227a7b25..644df486e9d3 100644--- a/nodejs/src/cdp/services/messaging/email-tracking.service.test.ts+++ b/nodejs/src/cdp/services/messaging/email-tracking.service.test.ts@@ -129,11 +129,14 @@ describe('EmailTrackingService', () => {expect(out).not.toContain('target=')})+ const sensitiveInvocation = { ...invocation, hogFunction: { metadata: { sensitive: true } } }+it.each([- ['clicktracking="off"', '<body><a href="https://example.com" clicktracking="off">x</a></body>'],- ['data-ph-no-track', '<body><a href="https://example.com" data-ph-no-track>x</a></body>'],- ])('leaves the href untouched when the anchor opts out via %s', (_name, html) => {- const out = addTrackingToEmail(html, invocation, signer)+ ['clicktracking="off"', '<body><a href="https://example.com" clicktracking="off">x</a></body>', invocation],+ ['data-ph-no-track', '<body><a href="https://example.com" data-ph-no-track>x</a></body>', invocation],+ ['a sensitive template', '<body><a href="https://example.com">x</a></body>', sensitiveInvocation],+ ])('leaves the href untouched when the anchor opts out via %s', (_name, html, inv) => {+ const out = addTrackingToEmail(html, inv, signer)expect(out).toContain('href="https://example.com"')expect(out).not.toContain('target=')})@@ -159,14 +162,21 @@ describe('EmailTrackingService', () => {})it.each([- ['clicktracking="off"', '<body><a href="https://example.com" clicktracking="off">x</a></body>'],- ['data-ph-no-track', '<body><a href="https://example.com" data-ph-no-track>x</a></body>'],- ])('translates the %s opt-out into ses:no-track', (_name, html) => {+ [+ 'clicktracking="off"',+ '<body><a href="https://example.com" clicktracking="off">x</a></body>',+ invocation,+ ],+ ['data-ph-no-track', '<body><a href="https://example.com" data-ph-no-track>x</a></body>', invocation],+ ['a sensitive template', '<body><a href="https://example.com">x</a></body>', sensitiveInvocation],+ ])('translates the %s opt-out into ses:no-track', (_name, html, inv) => {// SES honors only its own attribute, so without this the anchor is still rewritten// to awstrack.me and app deeplinks stop resolving.- const out = sesTrack(html)+ const out = addTrackingToEmail(html, inv, signer, false, 'ses')expect(out).toContain('ses:no-track')expect(out).not.toContain('ses:tags')+ // Opting links out of click tracking keeps the open pixel.+ expect(out).toContain('ph_id=')})it('merges into an author-supplied ses:tags value instead of emitting a second attribute', () => {diff --git a/nodejs/src/cdp/services/messaging/email-tracking.service.ts b/nodejs/src/cdp/services/messaging/email-tracking.service.tsindex 5b806ab400ab..723e8040506f 100644--- a/nodejs/src/cdp/services/messaging/email-tracking.service.ts+++ b/nodejs/src/cdp/services/messaging/email-tracking.service.ts@@ -168,6 +168,9 @@ export const addTrackingToEmail = (// many anchors happened to be trackable. The same template therefore yields the same indices// on every send, which is what makes counts comparable across recipients.let anchorIndex = 0+ // A sensitive email's links can carry a login code or a reset token, so none of them goes through+ // a click-tracking redirect. Opens and deliveries are still tracked.+ const sensitive = invocation.hogFunction?.metadata?.sensitive === truehtml = html.replace(LINK_REGEX, (m, d, s, u) => {const linkIndex = anchorIndex++@@ -183,7 +186,7 @@ export const addTrackingToEmail = (// Match only the opening <a> tag so a marker in the link's inner HTML (a child// element's attribute or literal link text) can't silently disable tracking.const openingTag = m.match(/^<a\b[^>]*>/i)?.[0] ?? ''- const optedOut = LINK_TRACKING_OPT_OUT_REGEX.test(openingTag)+ const optedOut = sensitive || LINK_TRACKING_OPT_OUT_REGEX.test(openingTag)if (mode === 'ses') {// SES rewrites every http(s) anchor once click tracking is on, and it honors only itsdiff --git a/products/workflows/frontend/TemplateLibrary/MessageTemplate.tsx b/products/workflows/frontend/TemplateLibrary/MessageTemplate.tsxindex 3c6d83aefaa6..d871ce47f60e 100644--- a/products/workflows/frontend/TemplateLibrary/MessageTemplate.tsx+++ b/products/workflows/frontend/TemplateLibrary/MessageTemplate.tsx@@ -195,7 +195,7 @@ export function MessageTemplate(props: MessageTemplateSceneLogicProps): JSX.Elem<div className="font-semibold">Protect sensitive data</div><p className="text-secondary text-sm m-0 mt-1">For emails with login codes or reset links. PostHog keeps no copy of- what each email contained, and clicked links keep only the site address.+ what each email contained, and doesn't track link clicks.</p></div></div>@@ -243,7 +243,7 @@ export function MessageTemplate(props: MessageTemplateSceneLogicProps): JSX.ElemTransactional</LemonTag>{originalTemplate.sensitive && (- <Tooltip title="PostHog keeps no copy of what each email contained, and clicked links keep only the site address.">+ <Tooltip title="PostHog keeps no copy of what each email contained, and doesn't track link clicks."><LemonTagtype="highlight"icon={<IconLock />}diff --git a/products/workflows/frontend/Transactional/wizard/steps/NameStep.tsx b/products/workflows/frontend/Transactional/wizard/steps/NameStep.tsxindex e69f17f82d32..1d56a70d8111 100644--- a/products/workflows/frontend/Transactional/wizard/steps/NameStep.tsx+++ b/products/workflows/frontend/Transactional/wizard/steps/NameStep.tsx@@ -39,7 +39,7 @@ export function NameStep(): JSX.Element {<div className="font-semibold">Protect sensitive data</div><div className="text-secondary text-sm font-normal">For emails with login codes or reset links. PostHog keeps no copy of what each email- contained, and clicked links keep only the site address.+ contained, and doesn't track link clicks.</div></div>}