Skip to content

fix(telemetry): redact credentials from CLI diagnostics - #1640

Merged
betegon merged 3 commits into
mainfrom
bt/redact-cli-diagnostics
Sep 29, 2026
Merged

betegon merged 3 commits into
mainfrom
bt/redact-cli-diagnostics

Conversation

@betegon

@betegon betegon commented Sep 28, 2026 •

Copy link
Copy Markdown
Member

Summary

Runtime errors can echo credentials into command diagnostics. Redact recognizable Sentry tokens and Bearer values in CLI/Stricli errors, SDK errors, and outgoing telemetry envelopes, including credentials split by control characters or escaped in JSON.

Telemetry redaction runs at the final transport boundary, after scope attributes and internal errors are resolved. A detached JSON copy preserves SDK serialization behavior without mutating caller objects or live SDK state. Text redaction has no SDK dependencies, preserving the completion startup path. Fatal diagnostics retain error names while redacting credentials.

This complements the merged auth validation in #1638: diagnostics can still contain credentials from custom headers and other error paths.

Validation

  • Full unit suite: 10,143 passed, 14 skipped (TZ=UTC).
  • 35 auth/library/completion E2E tests passed against a fresh bundle.
  • Lint, typecheck, bundle build, and diff checks passed.
  • Regression tests failed before these fixes and passed afterward: both CLI/library entry points avoid eager SDK imports, and the actual fatal handler preserves the error name and redacts split credentials.
  • Factored regex sources and flags match the previous implementation exactly; envelope redaction was moved without behavior changes.

Limits

Redaction recognizes Sentry token prefixes and Bearer context; it does not detect arbitrary opaque secrets without that context. Binary attachment bytes are preserved. Successful API response formatting is unchanged.

Runtime header errors can contain ambiguous delimiters inside the credential itself. Redaction conservatively uses the final matching delimiter, which can also hide intervening text when multiple diagnostics are concatenated into one string.

@vercel

vercel Bot commented Sep 28, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
cli Ready Ready Preview Sep 29, 2026 6:00am UTC
1 Skipped Deployment
Project Deployment Actions Updated
sentry-local Skipped Skipped Sep 29, 2026 6:00am UTC

Request Review

Comment thread packages/cli/src/lib/credential-redaction.ts
BYK pushed a commit that referenced this pull request Sep 28, 2026
## Summary

Malformed bearer credentials can be echoed by runtime header-validation
errors. Normalize access tokens and reject invalid formatting before
constructing authenticated API, Docs, init, and artifact-download
requests. Failures use a fixed `AUTH_INVALID` message without the
credential and preserve exit code 12.

Share one helper for trimming surrounding whitespace and ASCII controls.
Internal whitespace, controls, and non-ASCII characters remain invalid;
split lines are never joined. Environment selection, token host claims,
and cache `Vary` metadata use the same trimming rules. Cache metadata
only trims a candidate: validation waits until OAuth refresh and
credential selection determine the token actually used.

Validate access tokens before SQLite writes, including refreshed
credentials. Reject a malformed explicit `auth login --token` before
changing the host or clearing existing authentication. Legacy JSON
migration skips malformed auth, migrates other settings, and retains the
original file with a fixed recovery warning, so help, login, and logout
remain usable.

Malformed-token failures remain visible as safe
`MalformedAuthTokenError` events without retaining the credential or
original cause. They do not trigger auto-login or mark a session
crashed; ordinary authentication failures keep their existing reporting
policy.

## Validation

- Full validation at `e754fb328`: 467 unit files, 10,050 passed / 14
skipped (`TZ=UTC`); 34 bundled E2E passed across auth, library, and
migration; lint, TypeScript, and bundle build passed.
- After test-only cleanup: all 102 affected unit tests and 14 auth E2E
passed, along with Biome and `git diff --check`. Production code is
unchanged; the full suite and build were not repeated locally.
- Property and regression coverage for edge padding, internal invalid
characters, auth precedence, OAuth refresh, cache metadata, and
persistence.

## Separate work

General output and telemetry redaction remains in #1640. SDK invocation
isolation (#1645) and rc tokens truncated when copied into `process.env`
(#1646) are separate fixes; this PR does not address those earlier
input/lifecycle boundaries.

Bundler consumers pinned to `sentry ^0.44.0` need a `0.44.x` backport or
a dependency update after release.

@cursor cursor Bot 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.

Cursor Bugbot has reviewed your changes and found 2 potential issues.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit c060c54. Configure here.

Comment thread packages/cli/src/lib/credential-redaction.ts Outdated
Comment thread packages/cli/src/cli.ts Outdated
@vercel
vercel Bot temporarily deployed to Preview – sentry-local September 29, 2026 05:59 Inactive
@betegon
betegon merged commit 596a6d5 into main Sep 29, 2026
37 of 38 checks passed
@betegon
betegon deleted the bt/redact-cli-diagnostics branch September 29, 2026 10:37

This branch was successfully deployed

1 active and 1 inactive deployments
Preview – cli — abb01d21 Deployed Sep 29, 2026 by vercel[bot]
Preview – sentry-local — abb01d21 Deployed Sep 29, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

risk: medium PR risk score: medium

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant