/** * Redacts credential-bearing patterns from free text before it reaches any output channel * (stdout JSON payloads, stderr messages, HTTP error responses). * * Lives in core because domain handlers embed upstream error messages — which may contain * full request URLs (`?token=...`) or echoed bodies (`"appSecurity":"..."`) — into their * results; the CLI printer and the HTTP adapter apply the same rules at their boundaries. */ 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( /("(?:appSecurity|password|secret|signKey|closeToken|refreshToken|accessToken|authorization)"\s*:\s*")[^"]*(")/gi, "$1$3" ); }