Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

fix(mcp): redact warehouse source credentials from tool telemetry (#82905)

Tom Owerseda295e61e38
diff --git a/services/mcp/src/hono/analytics.ts b/services/mcp/src/hono/analytics.ts
index 67672bd24ee8..a8f08d1f71f4 100644
--- a/services/mcp/src/hono/analytics.ts
+++ b/services/mcp/src/hono/analytics.ts
@@ -295,10 +295,37 @@ const REDACTED_VALUE = '[redacted]'
// like user-settings-update carry `password`/`current_password`, warehouse
// sources carry `client_secret`, and hog-function inputs carry `secret` values.
// Match errs toward redaction — an over-redacted eval field is harmless, a
-// leaked credential is not. Deliberately excludes bare `key`/`id`/`token`, which
-// are almost always identifiers or token counts an evaluation needs.
+// leaked credential is not.
+//
+// Enumerating credential prefixes missed most of them: our own warehouse sources
+// name their secret `api_token`, `database_token`, `consumer_key`,
+// `signing_key`, and a dozen more, none of which the prefix list matched. The
+// trailing-segment rule catches that whole shape. Plural `*_tokens` stays out on
+// purpose — it is LLM token counts and Adjust's `app_tokens` app ids, never a
+// secret. `connection_string` gets its own name: Postgres, MSSQL, Redshift,
+// Snowflake and friends all accept one as an alternative to discrete
+// host/user/password fields, and it carries the credentials inline
+// (`postgres://user:pass@host/db`) — MongoDB's source has no other field for them.
+// `certificate` covers Temporal Cloud's `client_certificate`: the source config
+// itself marks it `secret: true` even though the name reads as public key
+// material, and a client cert is namespace-identifying enough to keep out of
+// telemetry too. `server_client_root_ca` stays unmatched on purpose — it is
+// the CA the client uses to verify the *server*, public key material with no
+// private half, marked `secret: true` only because the UI groups it with the
+// real credentials.
+//
+// `app_id`/`api_id` and the trailing `username` case cover sources whose
+// credential is an identifier rather than a token: Open Exchange Rates'
+// `app_id` and Veracode's `api_id` are the whole usable credential, and
+// Pipeliner generates its `username` alongside `password` as one half of a
+// one-time API key pair (`secret: true` on the source config), unlike every
+// other source's plain login `username`. Aircall's `api_id` and
+// AppsFlyer/AppSignal/Churnkey's `app_id` are not credentials — they select
+// which account or app an already-redacted token applies to — but the
+// pattern can't tell those apart by name, and over-redacting a non-secret
+// identifier is harmless where under-redacting a credential is not.
const SENSITIVE_KEY_PATTERN =
- /password|passwd|passphrase|secret|credential|private[_-]?key|access[_-]?key|api[_-]?key|access[_-]?token|refresh[_-]?token|auth[_-]?token|session[_-]?token|authorization|bearer/i
+ /password|passwd|passphrase|secret|credential|certificate|private[_-]?key|access[_-]?key|api[_-]?key|access[_-]?token|refresh[_-]?token|auth[_-]?token|session[_-]?token|authorization|bearer|keypair|key[_-]?file|token[_-]?request|connection[_-]?string|app[_-]?id|api[_-]?id|(^|[_-])(token|key|keys|username)$/i
function redactSecrets(value: unknown): unknown {
if (Array.isArray(value)) {
diff --git a/services/mcp/tests/hono/analytics.test.ts b/services/mcp/tests/hono/analytics.test.ts
index 3dedf6c510a7..52975f033491 100644
--- a/services/mcp/tests/hono/analytics.test.ts
+++ b/services/mcp/tests/hono/analytics.test.ts
@@ -439,5 +439,41 @@ describe('Hono MCP analytics contexts', () => {
})
expect(JSON.parse($ai_output_state)).toEqual({ id: 1, api_key: '[redacted]' })
})
+
+ // Redaction is key-name based, so a source whose credential field the
+ // pattern does not name ships that credential verbatim. Cloudflare's
+ // `api_token` did exactly that. These are real field names from
+ // products/warehouse_sources/.../sources/*/source.py, paired with the
+ // metadata and token-count fields the pattern must keep readable.
+ it.each([
+ ['api_token', true],
+ ['database_token', true],
+ ['consumer_key', true],
+ ['signing_key', true],
+ ['key_file', true],
+ ['keypair', true],
+ ['token', true],
+ ['client_secret', true],
+ ['connection_string', true],
+ ['client_certificate', true],
+ ['app_id', true],
+ ['api_id', true],
+ ['basic_auth_username', true],
+ ['username', true],
+ ['server_client_root_ca', false],
+ ['token_id', false],
+ ['token_url', false],
+ ['app_tokens', false],
+ ['input_tokens', false],
+ ])('redacts %s: %s', async (field, redacted) => {
+ await trackToolSpan('external-data-sources-create', makeState(), {
+ durationMs: 100,
+ isError: false,
+ input: { payload: { [field]: 'sensitive-value' } },
+ })
+
+ const { $ai_input_state } = mockCapture.mock.calls[0]![0].properties
+ expect(JSON.parse($ai_input_state).payload[field]).toBe(redacted ? '[redacted]' : 'sensitive-value')
+ })
})
})