24 lines
1.1 KiB
TypeScript
24 lines
1.1 KiB
TypeScript
/**
|
|
* 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<redacted>")
|
|
.replace(/(Bearer\s+)[A-Za-z0-9._~+/=-]+/gi, "$1<redacted>")
|
|
.replace(/(Basic\s+)[A-Za-z0-9+/=]+/gi, "$1<redacted>")
|
|
.replace(
|
|
/("(?:appSecurity|password|secret|signKey|closeToken|refreshToken|accessToken|authorization)"\s*:\s*")[^"]*(")/gi,
|
|
"$1<redacted>$2"
|
|
);
|
|
}
|