: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
chore: add semgrep rule for unreachable links in Tooltip title (#58266)
Paul D'Ambra92459afbaa90
diff --git a/.semgrep/rules/tooltip-link-needs-doclink-or-interactive.test.tsx b/.semgrep/rules/tooltip-link-needs-doclink-or-interactive.test.tsxnew file mode 100644index 000000000000..54dc41bbe6a5--- /dev/null+++ b/.semgrep/rules/tooltip-link-needs-doclink-or-interactive.test.tsx@@ -0,0 +1,71 @@+// @ts-nocheck+// Test fixture for tooltip-link-needs-doclink-or-interactive rule.+//+// Each test case is a single-line JSX expression assigned to a const so the+// annotation comment is on the line directly above the matched expression.+// The rule matches the Tooltip JSX element; Semgrep reports the match start+// at the line where that element's expression begins.++import { Link, Tooltip } from '@posthog/lemon-ui'++// ─── Positive cases — rule must match ───++// Shape 1: Link inside a Fragment wrapper.+// ruleid: tooltip-link-needs-doclink-or-interactive+const Case1Fragment = <Tooltip title={<>Some prose. <Link to="https://posthog.com/docs/foo">Learn more</Link></>}><span>trigger</span></Tooltip>++// Shape 2: Link inside a <span> wrapper.+// ruleid: tooltip-link-needs-doclink-or-interactive+const Case2SpanWrap = <Tooltip title={<span>Body copy. Read about <Link to="https://posthog.com/docs/foo">the thing</Link>.</span>}><IconInfo /></Tooltip>++// Shape 3: Link inside a <div> wrapper.+// ruleid: tooltip-link-needs-doclink-or-interactive+const Case3DivWrap = <Tooltip title={<div>Paragraph one. <Link to="https://posthog.com/docs/foo">Docs</Link>.</div>}><IconInfo /></Tooltip>++// Shape 4: Link as the bare value of title.+// ruleid: tooltip-link-needs-doclink-or-interactive+const Case4BareLink = <Tooltip title={<Link to="https://posthog.com/docs/foo">Just a link</Link>}><IconInfo /></Tooltip>++// Shape 5: closeDelayMs workaround — extends the close timer but does NOT+// make the popup hoverable, so the rule must still fire.+// ruleid: tooltip-link-needs-doclink-or-interactive+const Case5CloseDelayWorkaround = <Tooltip closeDelayMs={200} title={<>Body. <Link to="https://posthog.com/docs/foo">Docs</Link></>}><IconInfo /></Tooltip>++// Shape 6: Link nested two layers deep — six of the eleven audited bug cases+// had this shape (nested <div> wrappers).+// ruleid: tooltip-link-needs-doclink-or-interactive+const Case6DeeplyNested = <Tooltip title={<div className="deprecated-space-y-2"><div>Top-level prose.</div><div>Read more in the <Link to="https://posthog.com/docs/foo">documentation</Link>.</div></div>}><IconInfo /></Tooltip>++// Shape 7: Plain <a href> inside title — the rule covers bare anchors too.+// ruleid: tooltip-link-needs-doclink-or-interactive+const Case7PlainAnchor = <Tooltip title={<>See <a href="/somewhere">over here</a></>}><IconInfo /></Tooltip>++// ─── Negative cases — rule must NOT match ───++// Link is the trigger (children), not inside title+// ok: tooltip-link-needs-doclink-or-interactive+const OkLinkIsTrigger = <Tooltip title="Hover me"><Link to="/somewhere">Click me</Link></Tooltip>++// Plain-string title, no Link anywhere+// ok: tooltip-link-needs-doclink-or-interactive+const OkPlainStringTitle = <Tooltip title="Just a label"><span>trigger</span></Tooltip>++// Title JSX without a Link+// ok: tooltip-link-needs-doclink-or-interactive+const OkRichTextNoLink = <Tooltip title={<span className="font-mono">code-ish content</span>}><IconInfo /></Tooltip>++// docLink prop — auto-enables interactive + adds autocapture+// ok: tooltip-link-needs-doclink-or-interactive+const OkWithDocLink = <Tooltip docLink="https://posthog.com/docs/foo" title={<>Body. <Link to="/x">more</Link></>}><IconInfo /></Tooltip>++// interactive bare prop (sugar for interactive={true})+// ok: tooltip-link-needs-doclink-or-interactive+const OkInteractiveBare = <Tooltip interactive title={<>Body. <Link to="/x">more</Link></>}><IconInfo /></Tooltip>++// interactive={true} — explicit literal+// ok: tooltip-link-needs-doclink-or-interactive+const OkInteractiveExplicit = <Tooltip interactive={true} title={<>Body. <Link to="/x">more</Link></>}><IconInfo /></Tooltip>++// interactive={dynamic} — developer is at least signalling intent+// ok: tooltip-link-needs-doclink-or-interactive+const OkInteractiveDynamic = <Tooltip interactive={!!something} title={<>Body. <Link to="/x">more</Link></>}><IconInfo /></Tooltip>diff --git a/.semgrep/rules/tooltip-link-needs-doclink-or-interactive.yaml b/.semgrep/rules/tooltip-link-needs-doclink-or-interactive.yamlnew file mode 100644index 000000000000..ff96b48cd309--- /dev/null+++ b/.semgrep/rules/tooltip-link-needs-doclink-or-interactive.yaml@@ -0,0 +1,69 @@+rules:+ - id: tooltip-link-needs-doclink-or-interactive+ message: >-+ This `<Tooltip>` renders a `<Link>` inside its `title` prop but has neither+ `docLink` nor `interactive` set. The shared Tooltip defaults `interactive`+ to `false`, which passes `disableHoverablePopup={true}` to base-ui — the+ popup is not a valid hover target, so the cursor leaves the trigger before+ it can reach the link. The link is effectively unreachable.++ Fix:++ - If the link is a PostHog docs URL, use the `docLink` prop. It auto-enables+ `interactive`, renders the canonical "Read the docs" link, and attaches+ the standard `clicked tooltip doc link` autocapture:+ `<Tooltip docLink="https://posthog.com/docs/..." title="...">...</Tooltip>`++ - If the link points to an internal app page (settings, urls.*) or fires+ an action, add `interactive` so the popup becomes hoverable:+ `<Tooltip interactive title={<>... <Link to={...}>...</Link></>}>...</Tooltip>`++ Note: `closeDelayMs` extends the close timer but does NOT make the popup+ hoverable. It is not a substitute for `interactive`.++ If a particular call site is intentionally non-hoverable (e.g. the Link is+ purely decorative and unreachable on purpose), add a `// nosemgrep: tooltip-link-needs-doclink-or-interactive`+ comment above it with a brief justification.+ severity: ERROR+ languages: [typescript, javascript]+ patterns:+ # Match <Tooltip ... title={$TITLE} ...>...</Tooltip>, then run a+ # fresh Semgrep search inside the binding of $TITLE looking for a+ # <Link> or <a>. metavariable-pattern descends through the JSX AST,+ # so this catches Links nested at any depth inside the title+ # expression — including the audit case with two <div> layers+ # between the Fragment root and the <Link>.+ - pattern: <Tooltip ... title={$TITLE} ...>$...CHILDREN</Tooltip>+ - metavariable-pattern:+ metavariable: $TITLE+ patterns:+ - pattern-either:+ - pattern: <Link ...>...</Link>+ - pattern: <a ...>...</a>+ # Structural `pattern-not: <Tooltip ... interactive ... title={$T} ...>`+ # in Semgrep does not reliably expand `...` to zero JSX attributes,+ # so call sites where `interactive`/`docLink` is the first prop are+ # not excluded. Drop to a text-level exclusion: if the matched+ # source text contains `interactive` or `docLink` as a whole word,+ # the developer has acknowledged hoverability — even an explicit+ # `interactive={false}` is a deliberate choice, and `interactive={dynamic}`+ # at least signals intent. `closeDelayMs` is intentionally NOT in+ # this list: it extends the close timer but does not make the popup+ # hoverable, so tooltips relying on it as a workaround still fire.+ - pattern-not-regex: '\binteractive\b'+ - pattern-not-regex: '\bdocLink\b'+ paths:+ include:+ - 'frontend/'+ - 'products/'+ exclude:+ - '**/*.test.tsx'+ - '**/*.test.ts'+ - '**/*.spec.tsx'+ - '**/*.spec.ts'+ - '**/*.stories.tsx'+ metadata:+ category: correctness+ technology:+ - react+ - posthogdiff --git a/frontend/src/scenes/data-pipelines/batch-exports/BatchExportEditForm.tsx b/frontend/src/scenes/data-pipelines/batch-exports/BatchExportEditForm.tsxindex 75de3a0154ec..ca18f7891715 100644--- a/frontend/src/scenes/data-pipelines/batch-exports/BatchExportEditForm.tsx+++ b/frontend/src/scenes/data-pipelines/batch-exports/BatchExportEditForm.tsx@@ -730,6 +730,7 @@ export function BatchExportsEditFields({<span className="flex gap-2 items-center">Use VARIANT type for storing JSON data<Tooltip+ interactivetitle={<>Using VARIANT for storing JSON data is{' '}diff --git a/frontend/src/scenes/data-warehouse/scene/ViewsTab.tsx b/frontend/src/scenes/data-warehouse/scene/ViewsTab.tsxindex 75dd4a38824d..acbcc4037a14 100644--- a/frontend/src/scenes/data-warehouse/scene/ViewsTab.tsx+++ b/frontend/src/scenes/data-warehouse/scene/ViewsTab.tsx@@ -130,6 +130,7 @@ export function ViewsTab({ getViewUrl }: ViewsTabProps = {}): JSX.Element {view.managed_viewset_kind !== null ? (<><Tooltip+ interactivetitle={<>You cannot edit the definition for a view that belongs to a@@ -303,6 +304,7 @@ export function ViewsTab({ getViewUrl }: ViewsTabProps = {}): JSX.Element {view.managed_viewset_kind !== null ? (<><Tooltip+ interactivetitle={<>You cannot edit the definition for a view that belongs to adiff --git a/frontend/src/scenes/feature-flags/FeatureFlagReleaseConditionsCollapsible.tsx b/frontend/src/scenes/feature-flags/FeatureFlagReleaseConditionsCollapsible.tsxindex f66d9f73a973..207a20cd4550 100644--- a/frontend/src/scenes/feature-flags/FeatureFlagReleaseConditionsCollapsible.tsx+++ b/frontend/src/scenes/feature-flags/FeatureFlagReleaseConditionsCollapsible.tsx@@ -679,16 +679,11 @@ const ConditionContent = ({<span className="flex items-center gap-1"><span className="font-medium text-default">Optional override</span><Tooltip+ docLink="https://posthog.com/docs/feature-flags/testing#method-1-assign-a-user-a-specific-flag-value"title={<>Force all matching {resolvedTargetName} to receive a- specific variant.{' '}- <Link- to="https://posthog.com/docs/feature-flags/testing#method-1-assign-a-user-a-specific-flag-value"- target="_blank"- >- Learn more- </Link>+ specific variant.</>}>diff --git a/frontend/src/scenes/persons/PersonScene.tsx b/frontend/src/scenes/persons/PersonScene.tsxindex c75e03839aa3..a6153e6975cb 100644--- a/frontend/src/scenes/persons/PersonScene.tsx+++ b/frontend/src/scenes/persons/PersonScene.tsx@@ -389,6 +389,7 @@ export function PersonScene({ tabId }: { tabId?: string }): JSX.Element | null {<div className="flex items-center">Choose ID:<Tooltip+ docLink="https://posthog.com/docs/feature-flags/creating-feature-flags#persisting-feature-flags-across-authentication-steps"title={<div className="deprecated-space-y-2"><div>@@ -402,10 +403,7 @@ export function PersonScene({ tabId }: { tabId?: string }): JSX.Element | null {</div><div>This option may depend on your specific setup and- isn't always suitable. Read more in the{' '}- <Link to="https://posthog.com/docs/feature-flags/creating-feature-flags#persisting-feature-flags-across-authentication-steps">- documentation.- </Link>+ isn't always suitable.</div></div>}diff --git a/frontend/src/scenes/settings/environment/ReplayTriggers.tsx b/frontend/src/scenes/settings/environment/ReplayTriggers.tsxindex b243564b175e..8ec322012c39 100644--- a/frontend/src/scenes/settings/environment/ReplayTriggers.tsx+++ b/frontend/src/scenes/settings/environment/ReplayTriggers.tsx@@ -1,6 +1,6 @@import { useActions, useValues } from 'kea'-import { LemonBanner, LemonCollapse, LemonLabel, LemonTab, LemonTabs, Link, Tooltip } from '@posthog/lemon-ui'+import { LemonBanner, LemonCollapse, LemonLabel, LemonTab, LemonTabs, Tooltip } from '@posthog/lemon-ui'import IngestionControls from 'lib/components/IngestionControls'import { IngestionControlsSummary } from 'lib/components/IngestionControls/Summary'@@ -299,15 +299,8 @@ function MinimumDurationSetting(): JSX.Element | null {</div><TooltipdelayMs={200}- title={- <>- The JS SDK has an in-memory queue. This means that for traditional web apps the minimum- duration control is best effort.{' '}- <Link to="https://posthog.com/docs/session-replay/how-to-control-which-sessions-you-record#limitations">- Read more in our docs- </Link>- </>- }+ docLink="https://posthog.com/docs/session-replay/how-to-control-which-sessions-you-record#limitations"+ title="The JS SDK has an in-memory queue. This means that for traditional web apps the minimum duration control is best effort.">Setting a minimum session duration will ensure that only sessions that last longer than that valueare collected. This helps you avoid collecting sessions that are too short to be useful.