Skip to content

fix(web): keep secrets out of session replays and analytics URLs - #2009

Merged
gkhngyk merged 1 commit into
ansvisor:mainfrom
cihan-gyk:fix/replay-mask-secrets
Nov 2, 2026
Merged

gkhngyk merged 1 commit into
ansvisor:mainfrom
cihan-gyk:fix/replay-mask-secrets

Conversation

@cihan-gyk

Copy link
Copy Markdown
Collaborator

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)

  • Settings › MCP & API Keys: the new key and the MCP client setup that contains it.
  • AI Traffic › AI bots: the connection's one-time secret and the settings that contain it (Worker secret, Logpush destination, Vercel header).
  • Settings › Team: a new invitation's link.
  • Every password field (webhook secret, own AI provider key, WordPress / Webflow / Framer / Wix keys, store sign-ins, sign-in and sign-up passwords). Input adds the class to type="password", and PasswordInput keeps it while the password is shown as text.

PostHog options (lib/analytics-privacy.ts)

  • maskAllInputs: true is 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' and maskTextClass: 'ph-mask' are set explicitly (they are PostHog's defaults).
  • before_send cleans every URL-like property ($current_url, $pathname, $referrer, $initial_*, and $set / $set_once). It drops invite, email, token, code, token_hash, access_token and refresh_token from the query and the # fragment, and replaces /invite/<token> with /invite/[token], also inside ?next=.
  • maskCapturedNetworkRequestFn does 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.
  • No 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-mask covers the same need.

Invitation link

  • Sign-up reads ?invite=…&email=…&next=/invite/… once, keeps the address and the way back, then removes those parameters from the address bar with history.replaceState.
  • A reload after that shows a plain sign-up. The invitation e-mail's link still works.

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 feature
  • fix — Bug fix
  • chore — Maintenance / dependencies
  • docs — Documentation only
  • refactor — Code change that neither fixes a bug nor adds a feature
  • test — Adding or updating tests

How to test

  1. 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.
  2. replay-masking-coverage.test.ts is the guard. It reads the source and fails if a listed secret (new key, MCP setup, bot secret, invitation link) is rendered outside a ph-no-capture element, or if a plain <input type="password"> lacks the class. A new place that shows a secret is added to its list.
  3. By hand, on a build with NEXT_PUBLIC_POSTHOG_KEY:
    • Create a key in Settings › MCP & API Keys. In the replay, the key and the setup snippet are empty boxes.
    • Open an invitation link while signed out. The address bar shows /en/sign-up; the e-mail field still has the invited address. Sign up, and you come back to the invitation.

Checklist

  • Branch follows the naming convention
  • Commits follow Conventional Commits
  • yarn lint passes (0 errors; 7 old warnings in files this PR doesn't touch)
  • yarn typecheck passes
  • yarn format:check passes
  • Changes are focused — one concern per PR
  • Help article updated under help/ (or no user-visible change): no user-visible change, so no Help article

CI 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 and yarn build pass; server lint, format:check and all tests pass.

🤖 Generated with Claude Code

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

gkhngyk commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

Approved. One note: sign-up-form.tsx:34-37 strips invite, email and an /invite/… next from the URL and keeps them only in component state. A reload of the sign-up page (after an error, say) loses the invite: the email isn't prefilled, and after sign-up the person lands in onboarding instead of the invitation, so they may create their own workspace. Consider keeping next in sessionStorage or the existing next-cookie before stripping it.

@gkhngyk gkhngyk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@gkhngyk
gkhngyk merged commit 5b9422f into ansvisor:main Nov 2, 2026
6 checks passed
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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants