fix(surveys): guard doesSurveyMatchSelector against invalid selectors#3503
Draft
posthog[bot] wants to merge 2 commits intomainfrom
Draft
fix(surveys): guard doesSurveyMatchSelector against invalid selectors#3503posthog[bot] wants to merge 2 commits intomainfrom
posthog[bot] wants to merge 2 commits intomainfrom
Conversation
…tors A misconfigured `survey.conditions.selector` (e.g. a bare attribute expression like `data-ph-survey='x'` instead of `[data-ph-survey='x']`) caused `document.querySelector` to throw a SyntaxError. The throw bubbled up through `Array.filter` in `getActiveMatchingSurveys` and aborted the entire eligibility filter pass on every 1s eval tick, silently breaking all surveys site-wide for the affected customer. Wrap the `querySelector` call in try/catch: log a warning and treat the survey as non-matching so a single bad selector cannot poison the rest of the surveys pipeline. Generated-By: PostHog Code Task-Id: 28a54057-a2b7-49a5-9a36-216a705b32a4
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Contributor
Contributor
|
Size Change: +896 B (+0.01%) Total Size: 6.99 MB
ℹ️ View Unchanged
|
Generated-By: PostHog Code Task-Id: 28a54057-a2b7-49a5-9a36-216a705b32a4
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
A misconfigured
survey.conditions.selectorvalue (e.g. a bare attribute expressiondata-ph-survey='approve-post-overview'instead of the valid attribute selector[data-ph-survey='approve-post-overview']) madedocument.querySelectorthrow aSyntaxErrorinsidedoesSurveyMatchSelector(packages/browser/src/extensions/surveys/surveys-extension-utils.tsx).The throw propagated up through
Array.filterinSurveyManager.getActiveMatchingSurveysand aborted the entire eligibility filter pass on every 1-second eval tick ofcallSurveysAndEvaluateDisplayLogic. Net effect: a single bad selector silently broke every survey site-wide for the affected customer (and would for any customer making the same misconfiguration), with no recovery between ticks.This was a defensive-coding gap from PR #1897 — the recent #3442 hardened adjacent eligibility checks against storage errors but missed this throw site.
Changes
document.querySelector(survey.conditions.selector)in a try/catch.SURVEY_LOGGER.warn(with the survey id and the offending selector) and returnfalseso only the misconfigured survey is treated as non-matching — the rest of the surveys pipeline keeps running.surveys-utils.test.tscovering: no selector, matching selector, non-matching selector, and the invalid-selector case (must not throw, must returnfalse).Test plan
pnpm exec jest src/__tests__/extensions/surveys-utils.test.ts(53 tests pass, including 4 new ones)pnpm exec jest src/__tests__/extensions/surveys(174 tests pass — no regressions)pnpm exec eslinton changed files (clean)Signal
DOMException: SyntaxError: Failed to execute 'querySelector' on 'Document'first observed 2026-04-29 05:35 PDT, 9 occurrences in 8s for 1 distinct user.Created with PostHog Code