fix(analytics): keep MCP API keys out of PostHog session replay - #236
fix(analytics): keep MCP API keys out of PostHog session replay#2360xenzyme wants to merge 1 commit into
Conversation
- Mask the one-time plaintext key reveal in Settings - Strip Better Auth api-key network bodies from replay captures - Redact full oseo_ keys that appear in other captured payloads
Abhirup0
left a comment
There was a problem hiding this comment.
Hey @0xenzyme, thanks for putting this together!
The approach looks really solid to me. Adding both data-ph-mask and .ph-mask to the code block is great, and dropping the request/response bodies entirely for the Better Auth API key endpoints is much safer than just relying on regex pattern matching for the creation payload. Also like that the {16,} regex length check keeps the shortened oseo_abcd display prefixes intact in the UI table.
I just had a couple of small suggestions/thoughts for extra defense-in-depth if you think they're worth adding:
-
Scrubbing keys from URL query params:
InsanitizePostHogUrl, we currently handle/oauth-consentand stripemail. If someone ever passes an API key as a query param (like?apiKey=oseo_...),sanitizePostHogCapturedNetworkRequestmight still leave it inrequest.name. Running the regex overurl.searchorurl.toString()as well could be a nice safeguard. -
Relative URLs in
sanitizePostHogUrl:
InisApiKeyAuthRequestUrl, you usednew URL(name, "https://example.invalid")which handles relative paths cleanly. InsanitizePostHogUrl,new URL(value)without a base will throw on relative URLs (like/api/projects) and jump straight to thecatchblock returning the raw string. Passing a dummy base URL there too might make it more consistent. -
Request headers (minor):
If PostHog happens to recordrequestHeadersin your setup, it might be worth making sureauthorizationorx-api-keyheaders get scrubbed if they containoseo_...tokens.
Either way, the core fix is super clean and the test cases cover the main paths nicely. Thanks again for the PR!
Summary
data-ph-mask/ph-mask) so PostHog session replay cannot capture it from the DOM./api/auth/api-key*routes, and redact fulloseo_…keys elsewhere.Test plan
pnpm test -- src/client/lib/posthog-sanitize.test.ts