#18182: fix(security): redact sensitive data in OTEL log exports (CWE-532)
extensions: diagnostics-otel
size: S
trusted-contributor
## Summary
The diagnostics-otel plugin exports application logs to external OTLP collectors without any PII filtering or secret redaction. API keys, tokens, session IDs, and potentially sensitive conversation content are all exported unredacted.
**CVSS 7.5** | **CWE-532: Insertion of Sensitive Information into Log File**
Fixes #12542
## Changes
- Export `redactSensitiveText` from `plugin-sdk` for extension use
- Apply redaction to log messages before OTEL export
- Apply redaction to string attribute values
- Add 2 tests verifying API key and token redaction
## How it works
The existing `redactSensitiveText` function (from `src/logging/redact.ts`) handles common sensitive patterns:
- API keys (`sk-*`, `ghp_*`, `gsk_*`, `AIza*`, `pplx-*`, etc.)
- Bearer tokens
- PEM private keys
- ENV-style assignments (`API_KEY=value`)
- JSON credential fields
Sensitive values are masked to show partial prefix/suffix with `…` in the middle, preserving debuggability while protecting secrets.
## Testing
```
pnpm test extensions/diagnostics-otel/src/service.test.ts # 3/3 passing
```
<!-- greptile_comment -->
<h3>Greptile Summary</h3>
Addresses CWE-532 by redacting sensitive data (API keys, tokens, credentials) before exporting logs and trace spans to external OTEL collectors. The implementation applies the existing `redactSensitiveText` function (now exported from plugin-sdk) to log messages, log attributes, and error/reason fields in trace spans. Test coverage includes verification of API key and GitHub token redaction in both log messages and attributes.
<h3>Confidence Score: 4/5</h3>
- This PR is safe to merge with one minor fix needed for complete coverage
- The security fix is well-implemented with comprehensive redaction patterns and good test coverage. The redaction function handles common sensitive patterns (API keys, tokens, PEM keys, etc.) and is applied consistently to log messages, attributes, and most trace span fields. However, there's one gap where `session.state` reason field is not redacted (line 541), while similar fields in other events are properly redacted. Once this is fixed, the PR will provide complete protection against CWE-532
- extensions/diagnostics-otel/src/service.ts:541 needs the `session.state` reason field redacted for consistency
<sub>Last reviewed commit: 7dfd722</sub>
<!-- greptile_other_comments_section -->
<!-- /greptile_comment -->
Most Similar PRs
#22231: fix(security): redact sensitive data in session transcripts
by novalis133 · 2026-02-20
80.2%
#16928: fix(security): OC-07 redact session history credentials and enforce...
by aether-ai-agent · 2026-02-15
77.2%
#12260: fix: redact secrets in tool results before persisting to session tr...
by Yida-Dev · 2026-02-09
75.3%
#16708: fix(security): OC-17 add token redaction to error formatting, depre...
by aether-ai-agent · 2026-02-15
75.3%
#19353: fix(diagnostics-otel): fix cross-chunk module isolation breaking even…
by nez · 2026-02-17
75.1%
#23654: security(cli): redact sensitive values in config get output
by SleuthCo · 2026-02-22
74.0%
#12792: fix: exclude 'tokens' (plural) fields from config redaction
by jpaine · 2026-02-09
73.7%
#11530: diagnostics-otel: fix OpenTelemetry v2 resource/logs API compatibility
by erain · 2026-02-07
73.5%
#16865: fix(diagnostics-otel): share listeners/transports across module bun...
by leonnardo · 2026-02-15
73.2%
#4255: fix(diagnostics-otel): complete OpenTelemetry v2.x compatibility
by arbgjr · 2026-01-29
73.1%