/** * Redacts credential-bearing patterns from free text before it reaches an * output channel. * * Applied to: error messages surfaced by the CLI runner (`src/cli/runner.ts`) and * HTTP error responses (`src/http/routes.ts`). * * NOT applied to successful stdout payloads: those are redacted where they are * built — handlers mask fields via `presentWebhookIntegration`, * `redactIntegrationSecrets`, `maskHoseSecurity` and `formatSafeSourceDetail`. * Blanket redaction of stdout would also destroy deliberate credential-delivery * output (`auth link` tokens, `extract-keys --reveal`), so it stays per-handler. */ export function redactSensitiveText(value: string): string { return value .replace(/([?&](?:accessToken|token|returnToken|appSecurity|signKey|secret)=)[^&\s]+/gi, "$1") .replace(/(Bearer\s+)[A-Za-z0-9._~+/=-]+/gi, "$1") .replace(/(Basic\s+)[A-Za-z0-9+/=]+/gi, "$1") .replace( /("(?:appSecurity|password|secret|signKey|closeToken|refreshToken|accessToken|authorization)"\s*:\s*")[^"]*(")/gi, "$1$2" ); }