From 51a35654124ca870322c5867a42545bc0a246b7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B9=9B=E5=85=AE?= Date: Fri, 12 Jun 2026 06:12:49 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E9=81=BF=E5=85=8D=E9=9D=9E=E5=AD=97?= =?UTF-8?q?=E7=AC=A6=E4=B8=B2=E7=8A=B6=E6=80=81=E8=A2=AB=E8=AF=AF=E8=84=B1?= =?UTF-8?q?=E6=95=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - src/common/security/redact-sensitive.ts: 敏感字段名只对字符串整值脱敏,布尔和数字状态保持可观测 --- src/common/security/redact-sensitive.ts | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/common/security/redact-sensitive.ts b/src/common/security/redact-sensitive.ts index 4014451..86ac54b 100644 --- a/src/common/security/redact-sensitive.ts +++ b/src/common/security/redact-sensitive.ts @@ -1,3 +1,6 @@ +/** + * 通用脱敏工具负责清理密钥形态的字符串,同时保留布尔/数字等非密钥状态值。 + */ const SENSITIVE_KEY_PATTERN = /(token|secret|password|passwd|authorization|api[-_]?key|webhook|cookie|credential|private[-_]?key)/i; const INLINE_SECRET_PATTERN = @@ -21,7 +24,9 @@ function redactValue(value: unknown): unknown { return Object.fromEntries( Object.entries(value as Record).map(([key, entry]) => [ key, - SENSITIVE_KEY_PATTERN.test(key) ? '[REDACTED]' : redactValue(entry), + SENSITIVE_KEY_PATTERN.test(key) + ? redactSensitiveKeyValue(entry) + : redactValue(entry), ]), ); } @@ -46,6 +51,18 @@ function redactValue(value: unknown): unknown { return value; } +function redactSensitiveKeyValue(value: unknown): unknown { + if (typeof value === 'string') { + return '[REDACTED]'; + } + + if (value && typeof value === 'object') { + return redactValue(value); + } + + return value; +} + function looksLikeSecret(value: string): boolean { const trimmed = value.trim();