: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(heatmaps): guard URL parsing on the heatmaps browser logic (#71618)
Jordan Mryyanf12eab351b38
diff --git a/frontend/src/scenes/heatmaps/components/heatmapsBrowserLogic.test.ts b/frontend/src/scenes/heatmaps/components/heatmapsBrowserLogic.test.tsnew file mode 100644index 000000000000..5a0c615d6dab--- /dev/null+++ b/frontend/src/scenes/heatmaps/components/heatmapsBrowserLogic.test.ts@@ -0,0 +1,18 @@+import { normalizeHeatmapDataUrl } from './heatmapsBrowserLogic'++describe('normalizeHeatmapDataUrl', () => {+ it.each([+ ['example.com', null],+ [' ', null],+ ['', null],+ [null, null],+ ['h', null],+ ['https://', null],+ ['https://example.com', { href: 'https://example.com/', matchType: 'exact' }],+ ['https://example.com/pricing', { href: 'https://example.com/pricing', matchType: 'exact' }],+ [' https://example.com/pricing ', { href: 'https://example.com/pricing', matchType: 'exact' }],+ ['https://example.com/users/*', { href: 'https://example.com/users/*', matchType: 'pattern' }],+ ] as const)('normalizeHeatmapDataUrl(%s) → %s', (input, expected) => {+ expect(normalizeHeatmapDataUrl(input)).toEqual(expected)+ })+})diff --git a/frontend/src/scenes/heatmaps/components/heatmapsBrowserLogic.ts b/frontend/src/scenes/heatmaps/components/heatmapsBrowserLogic.tsindex dd96fc2578c8..c86c828e3034 100644--- a/frontend/src/scenes/heatmaps/components/heatmapsBrowserLogic.ts+++ b/frontend/src/scenes/heatmaps/components/heatmapsBrowserLogic.ts@@ -64,6 +64,23 @@ const normalizeUrlPath = (urlObj: URL): string => {return urlObj.toString()}+export const normalizeHeatmapDataUrl = (+ url: string | null+): { href: string; matchType: 'pattern' | 'exact' } | null => {+ const trimmed = url?.trim()+ if (!trimmed) {+ return null+ }+ if (isUrlPattern(trimmed)) {+ return { href: trimmed, matchType: 'pattern' }+ }+ try {+ return { href: normalizeUrlPath(new URL(trimmed)), matchType: 'exact' }+ } catch {+ return null+ }+}+// Generated by kea-typegen. Update if you're an agent, ignore if you're human.export interface heatmapsBrowserLogicValues {checkUrlIsAuthorized: (url: string) => boolean // authorizedUrlListLogic@@ -595,17 +612,13 @@ export const heatmapsBrowserLogic = kea<heatmapsBrowserLogicType>([setDataUrl: ({ url }) => {actions.maybeLoadTopUrls()- if (url?.trim().length) {- let normalizedUrl = url.trim()-- const isPattern = isUrlPattern(normalizedUrl)- if (!isPattern) {- const urlObj = new URL(normalizedUrl)- normalizedUrl = normalizeUrlPath(urlObj)- }-- actions.setHref(normalizedUrl)- actions.setHrefMatchType(isPattern ? 'pattern' : 'exact')+ if (router.values.location.pathname === '/heatmaps/new') {+ return+ }+ const normalized = normalizeHeatmapDataUrl(url)+ if (normalized) {+ actions.setHref(normalized.href)+ actions.setHrefMatchType(normalized.matchType)}},