MCPcopy Create free account
hub / github.com/cortexkit/magic-context / redactSecretString

Function redactSecretString

packages/cli/src/lib/diagnostics-pi.ts:166–178  ·  view source on GitHub ↗
(value: string)

Source from the content-addressed store, hash-verified

164}
165
166function redactSecretString(value: string): string {
167 // Apply the shared comprehensive redactor (OpenCode parity: adds
168 // github_pat_/ghp_/hf_/AKIA/Slack/Google/JWT and generic key=value forms that
169 // the bespoke version leaked) AND then the original looser patterns as a
170 // SUPERSET — the shared `sk-` pattern requires 32+ chars (real key length),
171 // so keep the looser `sk-{12,}` here too so short/synthetic sk- tokens are
172 // still caught. Redaction is safer over-broad than under.
173 return redactSecretText(value)
174 .replace(/Bearer\s+[A-Za-z0-9._~+\-/=]+/g, "Bearer <REDACTED>")
175 .replace(/sk-[A-Za-z0-9_-]{12,}/g, "sk-<REDACTED>")
176 .replace(/api[_-]?key=([^\s&]+)/gi, "api_key=<REDACTED>")
177 .replace(/token=([^\s&]+)/gi, "token=<REDACTED>");
178}
179
180/**
181 * Sanitize paths, usernames, and obvious secret material before writing issue

Callers 1

sanitizeStringFunction · 0.85

Calls 1

redactSecretTextFunction · 0.90

Tested by

no test coverage detected