Repository navigation
fix(web): keep secrets out of session replays and analytics URLs - #2009
Merged
Merged
Conversation
Session replay is on in code, and PostHog masks inputs but not text, so a new MCP / API key shown in a <code> could be recorded. - Elements that show a secret get ph-no-capture: the new key and its MCP setup, an AI-bot connection's secret and settings, a new invitation link. Input adds it to password fields; PasswordInput keeps it while shown. - PostHog init: maskAllInputs set in code (the project can't turn it off), before_send drops invite/email/token/code params and /invite/<token> from every URL property, and the replay's URLs get the same cleaning, with request bodies never kept. - Sign-up reads an invitation link's address and way back once, then takes invite, email and next out of the address bar. - replay-masking-coverage.test.ts fails when a listed secret is rendered outside ph-no-capture. Co-Authored-By: Claude Opus 5.5 <[email protected]>
gkhngyk
approved these changes
Nov 2, 2026
Contributor
|
Approved. One note: |
cihan-gyk
added a commit
to cihan-gyk/ansvisor
that referenced
this pull request
Nov 3, 2026
Main's replay masking (ansvisor#2009) wants every plain password input to carry ph-no-capture. Co-Authored-By: Claude Opus 5.5 <[email protected]>
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
Session replay is on in code (
disable_session_recording: false), and PostHog masks inputs but not text. A new MCP / API key is shown once as plain text in a<code>, so it could end up in a recording. This PR keeps secrets out of PostHog's replays and events. Security plan, Phase 0 (SEC-10a). Behaviour is the same whatever the flags or the plan.Replays leave secrets out (
ph-no-capture)Inputadds the class totype="password", andPasswordInputkeeps it while the password is shown as text.PostHog options (
lib/analytics-privacy.ts)maskAllInputs: trueis set in code, so the PostHog project can't turn it off (a setting made in code wins over the project's).blockClass: 'ph-no-capture'andmaskTextClass: 'ph-mask'are set explicitly (they are PostHog's defaults).before_sendcleans every URL-like property ($current_url,$pathname,$referrer,$initial_*, and$set/$set_once). It dropsinvite,email,token,code,token_hash,access_tokenandrefresh_tokenfrom the query and the#fragment, and replaces/invite/<token>with/invite/[token], also inside?next=.maskCapturedNetworkRequestFndoes the same for the replay's page URLs and request URLs. It also drops request and response bodies: once this function is set, PostHog stops its own body scrubbing, and a body can hold a new API key.maskTextSelector. The plan suggested[data-private], but a selector set in code replaces the project's own text-masking setting, so it could reduce masking.ph-maskcovers the same need.Invitation link
?invite=…&email=…&next=/invite/…once, keeps the address and the way back, then removes those parameters from the address bar withhistory.replaceState.No migration, no new package, no env var, nothing visible changes.
For the maintainer: if replay was on in the PostHog project, maintainer should review existing recordings and rotate any exposed keys.
Related issue
None. Security plan, Phase 0 (SEC-10a).
Type of change
feat— New featurefix— Bug fixchore— Maintenance / dependenciesdocs— Documentation onlyrefactor— Code change that neither fixes a bug nor adds a featuretest— Adding or updating testsHow to test
cd web && yarn vitest run src/lib/analytics-privacy.test.ts src/lib/replay-masking-coverage.test.ts src/components/providers/posthog-provider.test.tsx src/components/auth/sign-up-form.test.tsx src/components/ui/password-input.test.tsx src/components/settings/api-keys-section.test.tsx src/components/settings/team-section.test.tsx "src/app/[locale]/(dashboard)/dashboard/traffic/_bots-connect.test.tsx"Locally: 8 files / 43 tests pass, and the coverage tests (
subscription-guard-coverage,replay-masking-coverage) 11 tests pass. Removing the class from the new key's<code>makes the guard fail.replay-masking-coverage.test.tsis the guard. It reads the source and fails if a listed secret (new key, MCP setup, bot secret, invitation link) is rendered outside aph-no-captureelement, or if a plain<input type="password">lacks the class. A new place that shows a secret is added to its list.NEXT_PUBLIC_POSTHOG_KEY:/en/sign-up; the e-mail field still has the invited address. Sign up, and you come back to the invitation.Checklist
yarn lintpasses (0 errors; 7 old warnings in files this PR doesn't touch)yarn typecheckpassesyarn format:checkpasseshelp/(or no user-visible change): no user-visible change, so no Help articleCI passed on this branch (d3de4d4), run on the fork (https://github.com/cihan-gyk/ansvisor/actions/runs/41475674725): schema is up to date; web
format:check, lint, typecheck, all tests andyarn buildpass; server lint,format:checkand all tests pass.🤖 Generated with Claude Code