From e1bbec574b4cba2ab09a28f5b0c011ae57a2eaa9 Mon Sep 17 00:00:00 2001 From: automated-signal <37887102+automated-signal@users.noreply.github.com> Date: Fri, 29 Mar 2024 13:35:18 -0500 Subject: [PATCH] Add better invalid service id logs Co-authored-by: Jamie Kyle <113370520+jamiebuilds-signal@users.noreply.github.com> --- ts/types/ServiceId.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/ts/types/ServiceId.ts b/ts/types/ServiceId.ts index 74cff7b681..73a36f1b01 100644 --- a/ts/types/ServiceId.ts +++ b/ts/types/ServiceId.ts @@ -53,6 +53,12 @@ export function toUntaggedPni(pni: PniString): UntaggedPniString { return pni.replace(/^PNI:/i, '') as UntaggedPniString; } +const INVALID_SERVICE_ID_PATTERN = /^.*(.{3})/; + +function redactInvalidServiceId(input: string): string { + return input.replace(INVALID_SERVICE_ID_PATTERN, '[REDACTED]$1'); +} + export function normalizeServiceId( rawServiceId: string, context: string, @@ -77,8 +83,10 @@ export function normalizeServiceId( const result = rawServiceId.toLowerCase().replace(/^pni:/, 'PNI:'); if (!isAciString(result) && !isPniString(result)) { + const before = redactInvalidServiceId(rawServiceId); + const after = redactInvalidServiceId(result); logger.warn( - `Normalizing invalid serviceId: ${rawServiceId} to ${result} in context "${context}"` + `Normalizing invalid serviceId: ${before} to ${after} in context "${context}"` ); // Cast anyway we don't want to throw here