#23391: Logging: redact runtime secrets from skill env/apiKey in logs and transcripts
agents
size: M
trusted-contributor
## Summary
- add runtime secret registry for redaction literals sourced from config, env, and credential files
- apply runtime literal redaction in `redactSensitiveText` alongside existing regex masking
- redact tool-result text blocks before transcript persistence in `installSessionToolResultGuard`
- add regression coverage for runtime secret collection, literal redaction, and transcript persistence redaction
## Testing
- pnpm test src/logging/redact.test.ts src/logging/secret-registry.test.ts
- pnpm test:e2e src/agents/session-tool-result-guard.e2e.test.ts
<!-- greptile_comment -->
<h3>Greptile Summary</h3>
Adds a runtime secret registry that collects sensitive values from config (gateway auth, skill `apiKey`/`env`), process environment variables, and credential files on disk, then applies literal string replacement alongside existing regex-based redaction in `redactSensitiveText`. Tool result text blocks are now redacted before transcript persistence via `redactToolResultText` in the session-tool-result guard.
- `collectConfigSecrets` collects **all** skill `env` values without filtering by key name — non-sensitive env vars (e.g. `DATABASE_HOST`, `LOG_LEVEL`) will be registered as secrets and redacted from tool output
- `SENSITIVE_KEY_RE` matches bare `"access"` and `"refresh"` substrings, which is broader than `ENV_SENSITIVE_KEY_RE` and may over-collect from credential JSON files with keys like `accessLevel` or `refreshInterval`
- `redactSensitiveText` now always calls `resolveConfigRedaction()` even when options are provided, changing the API contract for callers passing partial options (they now get config-derived values merged in as fallbacks)
<h3>Confidence Score: 3/5</h3>
- Functional but with over-collection risks that could cause unexpected redaction of non-sensitive strings in tool output
- The core redaction and caching logic is sound, and the integration into the session-tool-result-guard is well-structured. However, the skill env value collection is unfiltered (collects all values regardless of key), and the SENSITIVE_KEY_RE regex is broader than its ENV counterpart, both of which could cause false-positive redaction of common strings in tool output. These are not crash bugs but could degrade tool output readability in production.
- Pay close attention to `src/logging/secret-registry.ts` (over-collection of skill env values and broad regex matching) and `src/logging/redact.ts` (always-call config resolution changing API behavior)
<sub>Last reviewed commit: 30f15b2</sub>
<!-- greptile_other_comments_section -->
<!-- /greptile_comment -->
Most Similar PRs
#12260: fix: redact secrets in tool results before persisting to session tr...
by Yida-Dev · 2026-02-09
82.6%
#12296: security: persistence-only secret redaction for session transcripts
by akoscz · 2026-02-09
78.6%
#22231: fix(security): redact sensitive data in session transcripts
by novalis133 · 2026-02-20
77.1%
#22846: Config: add secret ref schema and redaction foundations
by joshavant · 2026-02-21
74.3%
#23174: feat(security): credential leak prevention — exfiltration patterns,...
by ihsanmokhlisse · 2026-02-22
73.2%
#18182: fix(security): redact sensitive data in OTEL log exports (CWE-532)
by brandonwise · 2026-02-16
72.9%
#11250: fix: expand skills watcher ignore list and improve session repair l...
by zhangzhefang-github · 2026-02-07
72.6%
#19115: fix(logging): improved redaction for config objects and unquoted keys
by Clawborn · 2026-02-17
72.4%
#22744: feat: masked secrets — prevent agents from accessing raw API keys
by theMachineClay · 2026-02-21
72.0%
#12792: fix: exclude 'tokens' (plural) fields from config redaction
by jpaine · 2026-02-09
71.9%