fix(security): 日志脱敏规则增强, 覆盖更多 token 泄露形态

- 原 sanitizeLog 仅匹配 token=[\w\d]+, 无法覆盖 token: xxx /
  access_token / refresh_token / credential / Authorization 及含
  ./- 的 JWT 形态。
- 扩展为三类规则: token=形式 / token: 形式 / 敏感凭据字段名前缀。
- 同时覆盖 LogHandler(历史日志)与 LogRealTimeHandler(SSE 实时日志),
  两处本就共用 sanitizeLog, 无需改动调用侧。
This commit is contained in:
SnowCat Security Bot committed 2026-11-13 03:33:45 +08:00
1 parent 76520c6157
commit caedbb219d
1 file changed
+5 -2
@@ -7,8 +7,11 @@ const isMacOS = process.platform === 'darwin';
// 日志脱敏函数 // 日志脱敏函数
const sanitizeLog = (log: string): string => { const sanitizeLog = (log: string): string => {
// 脱敏 token 参数,将 token=xxx 替换为 token=*** // 脱敏: token=xxx / token: xxx / access_token / refresh_token / credential / Authorization 一律打码
return log.replace(/token=[\w\d]+/gi, 'token=***'); return log
.replace(/token=[\w\d.\-]+/gi, 'token=***')
.replace(/token[:=]\s*"?[\w\d.\-]+/gi, 'token=***')
.replace(/(access_token|refresh_token|credential|Authorization)[:=]\s*"?[\w\d.\-+/=]+/gi, '$1=***');
}; };
// 日志记录 // 日志记录
export const LogHandler: RequestHandler = async (req, res) => { export const LogHandler: RequestHandler = async (req, res) => {