加强客户端错误日志脱敏与指纹稳定性

覆盖 Bearer 授权值并在 WebView 日志桥接处执行二次脱敏

使用首个调用点参与指纹,避免相同消息合并不同调用位置
This commit is contained in:
2026-09-01 15:22:32 +08:00
parent a2207cb208
commit fdc155d8fa
@@ -40,7 +40,10 @@ function normalizeMessage(value: string) {
function normalizeDiagnosticText(value: string) {
return value
.replace(/authorization\s*:\s*\S+/giu, 'authorization: [REDACTED]')
.replace(
/authorization\s*:\s*(?:bearer\s+)?\S+/giu,
'authorization: [REDACTED]',
)
.replace(/bearer\s+\S+/giu, 'Bearer [REDACTED]')
.replace(/(?:api[_-]?key|token)\s*[=:]\s*\S+/giu, '[REDACTED]')
.replace(/https?:\/\/\S+/giu, '<url>')
@@ -70,13 +73,17 @@ export async function captureClientError(
const stack = errorValue.stack
? normalizeDiagnosticText(errorValue.stack).slice(0, 8_000)
: undefined;
// 只用栈的首行参与指纹,避免同一错误因调用位置行号变化而无法合并。
const callSite = stack
?.split('\n')
.find((line) => /^\s*at\s+/u.test(line))
?.replace(/:\d+(?::\d+)?\)?$/u, '')
.trim();
const fingerprintInput = [
context.source ?? 'client',
context.action,
context.page,
message,
stack?.split('\n')[0],
callSite,
]
.filter(Boolean)
.join('|');
@@ -124,7 +131,9 @@ function formatConsoleArgument(value: unknown) {
}
export function appendWebviewLog(level: WebviewLogLevel, values: unknown[]) {
const message = values.map(formatConsoleArgument).join(' ').slice(0, 8_000);
const message = normalizeDiagnosticText(
values.map(formatConsoleArgument).join(' ').slice(0, 8_000),
);
void invoke('append_application_log', {
level,
source: 'webview',