Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.
fix(telemetry): redact secrets inside JSON payloads (#4043)
## Summary Telemetry error text is redacted before it leaves the process, but the key/value rule only matches when the separator follows the key name directly: ``` \b(authorization|api[-_]?key|...|pwd)\b(\s*[:=]+\s*)(["']?)([^\s"',}&]+)\3 ``` In JSON — and in a Python `dict` repr — the key's own closing quote sits between the name and the colon, so `{"api_key": "..."}` never matches and the value is sent verbatim. That is the shape error messages usually carry: an API error envelope, a rejected request body echoed back, or an f-string interpolating a config dict. Both SDKs share the pattern and both are affected. The fix moves the optional quote into the separator group (`(["']?\s*[:=]+\s*)`). The key name, separator, and quoting are all preserved in the output; only the value is replaced. Measured with `redact_sensitive_text` / `redactSensitiveText` directly, before and after: | input | before | after | |---|---|---| | `api_key=sk-1` | redacted | redacted | | `api_key: "sk-1"` | redacted | redacted | | `x-api-key: sk-live-hdr` | redacted | redacted | | `{"api_key": "sk-live-abc"}` | **leaks** | `{"api_key": "[REDACTED]"}` | | `{"api_key":"sk-live-abc"}` | **leaks** | redacted | | `{"api_key" : "sk-live-abc"}` | **leaks** | redacted | | `{"refresh_token":"rt-abc.def-123"}` | **leaks** | redacted | | `{"x-api-key":"sk-hdr","user":"bob"}` | **leaks** | redacted, `"user":"bob"` kept | | `{'client_secret': 'cs-live-abc'}` | **leaks** | redacted | | `the password field is required` | untouched | untouched | | `no separator here "api_key" and nothing else` | untouched | untouched | The end-to-end path in Python is `composio/core/models/base.py:60-61`, which passes `str(e)` and `traceback.format_exc()` through the redactor into the telemetry `error` field. A tool failure whose message interpolates the rejected request body — `Error executing tool: request body was rejected: {"toolkit": "GMAIL", "arguments": {"api_key": "...", ...}}` — leaked the customer's key today. ## Changes - `python/composio/utils/redaction.py`, `ts/packages/core/src/telemetry/redact.ts`: allow a quote between the key name and the separator. - Tests on both sides for JSON, minified JSON, spaced-colon JSON, dict repr, the realistic serialized-payload shape, key/quote preservation, and no-false-positive cases. - Changeset for `@composio/core`. ## Type of change - [x] Bug fix ## How Has This Been Tested? Node 24.13.0 / pnpm 11.8.0 / Python 3.10.20 (uv), Windows. - `uv run pytest tests/test_redaction.py` — 13 passed. With `redaction.py` reverted and the new tests kept, 9 of them fail; the 4 that still pass are the pre-existing test plus the three no-false-positive controls. - `npx vitest run test/telemetry/redact.test.ts` in `ts/packages/core` — 10 passed. With `redact.ts` reverted, the 3 new cases fail. - Full Python suite: 913 passed, same 4 failures as on `next` unchanged (3 are `ModuleNotFoundError: composio_langchain` from providers not installed in my env; 1 is `test_empty_name_safe_fails_at_write_time`, which expects `IsADirectoryError` but Windows raises `PermissionError` when opening a directory). Collection 944 → 956, exactly the 12 tests added. - Full `@composio/core` vitest: 798 passed / 2 failed, byte-identical to the unchanged baseline (794 passed / same 2 failed — both Windows path-and-symlink cases). 11 test files fail to load in both runs because I installed with `--ignore-scripts`; the repo's `preinstall` hook doesn't run in my shell. - `ruff format --check` and `ruff check` clean on the two Python files; `prettier --write` applied to the two TypeScript files. ## Checklist - [x] I have read the Code of Conduct and this PR adheres to it - [x] I ran linters/tests locally and they passed - [ ] I updated documentation as needed — no user-facing behavior change to document - [x] I added tests or explain why not applicable - [x] I added a changeset if this change affects published packages ## Additional context This is defence-in-depth, so it stays deliberately narrow: same denylist of key names, same value character class, no new rules. Bare-prefix secrets (`sk-...`, `ghp_...`) and PEM blocks are still not matched by either SDK — worth a separate look, but widening the pattern is a different risk trade-off than closing a shape the rule already intends to cover.