Commit dda05086 by luoqi

fix(auth): 会话失效告警只对真·嵌入/换票失败推,直接访问不再误报

现象:直接浏览器打开 /plans(无 code、非嵌入)也推 [PAC CRITICAL],且根因误判成
"code 到手即死"(其实压根没 code)。
- 告警门控:仅 hadCode=true 或 isEmbedded=true 才推;直接非嵌入访问只落日志。
- freshButDead 根因加 hadCode=true 前置(没 code 不判时间差);
  新增"嵌入内 URL 无 code"分支。

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
parent b8b6497c
Pipeline #3361 failed in 0 seconds
......@@ -215,8 +215,11 @@ export class AuthService {
(d.hostOrigin ? ` host=${d.hostOrigin}` : '') +
(d.err ? ` err=${d.err}` : ''),
);
// 只在"用户真失效"事件推企微(no-credentials / refresh-fail);成功/中间态只落日志不推。
if (d.ev === 'no-credentials' || d.ev === 'refresh-fail') {
// 只对"真·嵌入/换票失败"推企微:①带 code 的失败(换票没成),或 ②在宿主 iframe 内失败。
// 直接浏览器打开 /plans(无 code、非嵌入)= 正常走 mock/SSO,不是故障,只落日志不推(否则误报刷屏)。
const isFailure = d.ev === 'no-credentials' || d.ev === 'refresh-fail';
const worthAlert = isFailure && (d.hadCode === true || d.isEmbedded === true);
if (worthAlert) {
void this.alertSessionExpiry(d).catch((e) =>
this.logger.warn(`[client-diag] 告警推送失败: ${e instanceof Error ? e.message : String(e)}`),
);
......@@ -351,10 +354,15 @@ export class AuthService {
const usedBefore = trace?.usedBefore ?? false;
// 不做去重:每次会话失效都推(宿主复用刷爆群 = 排查宿主的信号)。
// 根因推断:分清"存储分区" / "重载复用死码" / "旧码" / "全新最新码到手即死(时间差/淘汰)"
// 根因推断:分清"存储分区" / "重载复用死码" / "旧码" / "全新码到手即死" / "嵌入没带 code"
const storageBlocked = d.storageWritable === false;
// 全新码到手即死 仅当【确实带了 code】才成立(hadCode=true);否则根本没 code,别乱判成时间差。
const freshButDead =
!usedBefore && trace?.isLatest !== false && d.isReload !== true && d.storedRefresh !== true;
d.hadCode === true &&
!usedBefore &&
trace?.isLatest !== false &&
d.isReload !== true &&
d.storedRefresh !== true;
const rootCause = storageBlocked
? '存储不可写(iframe 第三方存储被分区/ITP/隐私模式拦)'
: usedBefore
......@@ -363,7 +371,9 @@ export class AuthService {
? '用了旧 code(非最新签发)+ store 无 token'
: freshButDead
? `全新最新 code 到手即死(疑似 mint→验证超时/Redis 淘汰;code ${trace?.ageSeconds ?? '?'}s)`
: '无凭据(可能首次访问未带 code,或 code 已过期)';
: d.hadCode !== true && d.isEmbedded === true
? '嵌入内 URL 无 code + store 无 token(宿主(重)载没带 code / 存储读不到)'
: '无凭据(URL 无 code 且 store 无 token)';
const y = (b: boolean | null | undefined) => (b === null || b === undefined ? '?' : b ? '是' : '否');
await this.alert.send({
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment