mirror of
https://github.com/supabase/supabase.git
synced 2026-12-04 07:29:16 +00:00
create-pull-request/patch
4
Commits
| Author | SHA1 | Message | Date | |
|---|---|---|---|---|
|
|
d336555617 |
fix(telemetry): redact url params and page titles (#54044)
The frontend apps send the current URL and page title with every analytics event. The redaction added in #53500 and extended in #53955 only covers the `keywords` and `schema` params, so Table Editor filters, search text, invite tokens, OAuth codes and the auth redirect hash still go out in URL properties, and Studio's title carries the table, project and org names. **Changed:** - **Query values are redacted by default**: every `name=value` in a URL property now goes out as `name=redacted`, unless the name is one that attribution reads downstream (`utm_*`, the click ids the first-referrer cookie already collects, `dub_id`, `campaign_id`, `cid`, `promo_code`). Param names and the `?` stay, so reports that match on a param being present keep working. Fixed-vocabulary params such as `tab` are not on the list: nothing reads them today, and several of those names carry customer data on other pages. - **A change to a redacted value no longer sends a pageview**: picking a new filter value on the same page used to send a pageview, which would now be identical to the previous one. The dedupe check compares the redacted URL, so it is skipped. This lowers Studio pageview counts: on current traffic, at most about 9% of dashboard pageviews repeat the previous path with a query string. - **Events from both transports are covered, and the hash is dropped**: `identify` and `group` let the SDK stamp its own `$current_url` with the hash, and `$set_once` pinned that on the person. `before_send` now strips it, and the SDK no longer captures hashes itself. Custom events skip `before_send`, so the same redaction also runs on their `pathname` field, where www was appending the raw query string. The SDK's copy of a search-engine referrer's query (`ph_keyword`) is dropped too. - **Studio sends a route-level title**: `Tables | Database | Supabase` in place of `users | Tables | Database | <project> | <org> | Supabase`. The tab title users see is unchanged, and so are titles in the other apps, which are public content. - **Dead clicks, heatmaps and web vitals are pinned off**: each one puts page text or the page URL in a nested payload the redaction does not walk, and each can be switched on from project settings without a deploy. All three are off today. **Note:** One path is only partly covered. Feature-flag requests carry the first URL and referrer the SDK stored for the browser, and they never pass through `before_send`. The hash is now gone from them; query values in that first URL (for example an invite link opened in a fresh browser) still go out on those requests. ## To test Signed in on the Studio preview, with analytics consent accepted. Check events in the staging analytics project, filtered to the preview host. Tested on the PR preview: - [x] Open the Table Editor, add a filter with the value `leaktest@example.com` and a sort, type `leaktest` in the Tables search and in a logs search, then click through a few pages. Expect no event containing `leaktest`, and `filter=redacted`, `sort=redacted`, `search=redacted` and `s=redacted` in `$current_url`. Observed: zero events from the preview host contained `leaktest`; custom events, `$pageview`, `$pageleave` and `$set` all carried the `=redacted` forms. The filter and sort were applied by loading the Table Editor URL with them, which is how the app restores them - [x] Same session: expect `page_title` and `title` on every event to hold only page names (for example `Tables | Database | Supabase`), with no project, org or table name. Observed: `Table Editor | Supabase`, `Tables | Database | Supabase`, `Postgres Logs | Logs | Supabase`, `Team | Supabase` and similar; no event carried the project, org or table name. `explorer_*` events keep their existing fixed title `Explorer` - [x] Load `/dashboard/project/<ref>?token=leaktest1&projectName=leaktest2#access_token=leaktest3`, then open `/join?token=leaktest4&slug=x`. Expect zero events containing `leaktest`, including `$set`, `$identify` and `$groupidentify`. Observed: zero, with `token=redacted&projectName=redacted` and no hash on any stored URL. `$set` and `$groupidentify` fired and were clean; no `$identify` fired in this session (the user was already identified), so that event was not observed - [x] Load any page with `?utm_source=readable5` appended. Expect `utm_source=readable5` readable in `$current_url`. Observed on Database > Tables with `?utm_source=readable5&gclid=readable6&tab=readable7`: both attribution params readable, `tab=redacted`. The Table Editor route rewrites its own query string and drops unknown params before any event fires, so use another page - [x] Open a table in the Table Editor. Expect the browser tab title to still lead with the table name and include the project and org names. Observed: `<table> | Table Editor | <project> | <org> | Supabase` - [x] On the Table Editor with a filter applied, change the filter value twice, then add a sort. Expect no new `$pageview` for the two value changes and one for the added sort (a new param name). Observed, all through the UI with no reload: adding the filter sent one pageview, the two value changes sent none, adding the sort sent one, and a sidebar navigation sent one; the staging analytics project shows the same four pageviews ## Linear - fixes GROWTH-1572 |
||
|
|
62d6bf56f8 |
fix(telemetry): send the live posthog session id on custom events (#53504)
Custom events sent through the telemetry endpoint often carry a session id the browser's PostHog session has already left: 8.9% of server-captured events in a recent week had an id more than 24 hours old, against 0.046% of browser-captured ones. Two things on the client cause it. The `session_id` in the request body is parsed out of the PostHog cookie without going through posthog-js, so a custom event never rotates an expired session. And the `session_id` cookie, which the API reads for the events it emits itself, was written on each pageview before posthog-js rotated the session, so the first pageview after an idle period stored the previous session's id. **Changed:** - **Custom events carry the live session id**: I changed `buildTelemetryEventRequest` to ask posthog-js for the session id the way a captured event does, so an expired session rotates first. Until posthog-js has loaded it sends the cookie-parsed id, as before. - **The `session_id` cookie follows the session**: I moved the write from the pageview handler to posthog-js's session-change callback, plus one write when posthog-js loads, so the cookie changes when the session does. - **The cookie stays cleared after an opt-out**: when a visitor withdraws consent, posthog-js resets the session, and the new id would have been written back over the cleared cookie. I skip the write once the visitor has opted out, in this tab or another. Unit tests cover this one: preview builds accept consent by default, so withdrawal can't be exercised there. - **Session metrics will step**: custom events now count as session activity. A long-lived tab that sends events without navigating stays in one session, so expect fewer, longer sessions from the day this reaches each app. **Note:** The API starts reading the body's `session_id` in a companion change on its side. Either can deploy first: the field is already sent today and ignored. ## To test Tested on the PR preview: - [x] In Studio with the Network tab open, open the user dropdown in the header. Expect the `telemetry/event` request body's `session_id` to equal the `session_id` cookie. - [x] Open the dropdown again right away. Expect the same `session_id` as in the first request. - [x] Leave that tab untouched for 35 minutes, then open the user dropdown again without navigating. Expect a different `session_id` in the request body than in the first step, and the `session_id` cookie to equal the new one. Observed after 38 idle minutes. - [x] Navigate to another Studio page. Expect the `session_id` cookie to keep the value from the previous step. Observed on an in-app navigation to the account page. ## Linear - fixes GROWTH-1509 |
||
|
|
27578cdfb5 |
fix(telemetry): send search query shape instead of raw text (#53500)
Search telemetry sent whatever people typed, and search boxes are a place where people paste credentials and personal data. I replace the raw text with a description of it. #53336 added the raw `query` to `kb_search_submitted`; docs search and the command menu already sent it. **Changed:** - **I send a description of the search term**: `kb_search_submitted`, `docs_search_v2_search_submitted`, `docs_search_v2_result_clicked` and `command_menu_search_submitted` now send `queryLength` and `queryWordCount`, measured after trimming and collapsing repeated whitespace. - **Text only for keywords**: the term itself (`query`, `value`, and `search_query` on `command_menu_command_clicked`) is sent only when it is up to 4 letters-only parts of at most 16 letters each, 40 characters in total. Keys, tokens, emails, IDs, project refs and connection strings never match. Over the last 30 days that shape covers about 96% of command menu searches, 88% of docs searches and 73% of KB searches, so term-level analysis such as no-result queries keeps most of its data. - **I removed `keywords` from the auth users search event**: `auth_users_search_submitted` no longer carries it. Those terms identify customers' end users, and I confirmed nothing downstream reads them. - **The `keywords` URL parameter is redacted wherever telemetry copies a URL**: the Auth users page keeps the search term in its URL, so I replace the value with `keywords=redacted` in the page URL, query string and referrer we send, and in the posthog-js `before_send` hook for the URL properties the SDK fills in on its own (`$session_entry_url`, `$initial_current_url`, `$referrer`, `$initial_referrer`). The URL in the browser is unchanged. **Note:** a letters-only name or passphrase still matches the keyword shape, and longer questions lose their text. I opened this in place of #53435, which removed `query` from the KB event only. ## To test Tested on the PR previews (docs, kb, studio-staging), reading the request bodies sent to `/platform/telemetry/event`: - [x] Docs: open search and type `auth`, expect `docs_search_v2_search_submitted` with `query: "auth"`, `queryLength: 4` and `queryWordCount: 1`. Observed exactly that, with `hasResults: true`. - [x] Docs: type `person@example.com`, expect the same event with `queryLength: 18` and no `query`. Observed, and no telemetry body in that step contained the address. - [x] KB: search `how do I reset my database password`, expect `kb_search_submitted` with `queryLength: 35`, `queryWordCount: 7` and no `query`. Observed. - [x] KB: search `storage policies` with two spaces, expect `kb_search_submitted` with `query: "storage policies"` and `queryLength: 16`. Observed, with `queryWordCount: 2`. - [x] Studio: open the command menu and type `abcdefghijklmnopqrst`, expect `command_menu_search_submitted` with no `value`, then type `auth` and expect `value: "auth"`. Observed both, with `queryLength` 20 and 4. - [x] Studio: on Auth > Users, search `person@example.com`, expect `auth_users_search_submitted` with no `keywords`. Observed: `trigger`, `sort_column`, `sort_order`, `providers` and `filter_column` only. - [x] Studio: with `?keywords=person%40example.com` in the Auth > Users URL, reload, then trigger an event on the page, expect `page_url` and `ph.search` in the request body to carry `keywords=redacted` and the address bar to keep the real term. Observed on all three events from that page, and the address bar kept the term. - [x] Studio: from that URL, do a full page load to another project page and trigger an event, expect `ph.referrer` to carry `keywords=redacted` while `document.referrer` keeps the real term. Observed on all three events from the new page. - [x] Studio: after that session, query the staging analytics project for events from the preview host, expect no property value to carry the address or anything but `keywords=redacted`. Observed: none of the events in the test window carried the address, and the SDK's own `$set`, `$pageview` and `$pageleave` events arrived with `keywords=redacted` in `$current_url`, `$referrer` and `$initial_current_url`. The session started on a page without the parameter, so `$session_entry_url` was not exercised here; the unit test on the `before_send` hook covers it. ## Linear - fixes GROWTH-1501 |
||
|
|
b23e9e8d94 |
fix(consent): clear tracking state and reload when consent is withdrawn (#53294)
## Problem Opting out from the Privacy Settings modal (www, docs, kb) clears no cookies, and GTM keeps running. The banner's Opt out misses `_ga_<id>`, `_dcid`, and PostHog. ## Solution - `revokeTrackingConsent()` runs from `denyAll`, and from `updateServices` unless every service is accepted. It clears `_ga`, `_ga_*`, `_gcl_*`, `FP*`, `_dcid`, `session_id`, `ph_*_posthog`, PostHog's localStorage, stale consent copies. - PostHog resets and opts out, with persistence off. The opt-out survives sign-out. A saved accept opts back in. - Every opt-out calls `POST /platform/telemetry/reset` (keepalive, errors ignored) to clear the API's HttpOnly `session_id`, `anonymous_id`, and `user_id`. Studio's own call is removed. - To stop GTM, a saved opt-out reloads the page if tracking was on, waiting at most 1s for the reset. ## Review instructions 1. `cd packages/common && npx vitest run consent-state.test.ts posthog-client.test.ts` 2. On prod: accept, open Privacy Settings, turn Marketing off, Confirm. The page reloads with cookies gone and no `collect` request. Tested: `common` (237 pass), `AnalyticsSettings` tests, CI unit tests and typecheck. No browser test (previews lack Usercentrics). ## Checklist - [x] I have read [CONTRIBUTING.md](https://github.com/supabase/supabase/blob/master/CONTRIBUTING.md) - [ ] If I wrote a new docs topic or edited an existing topic, I used the `/write-the-docs` or `/edit-the-docs` skill |