From 688910f738e203d97bba031d569932e93a90f082 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=84=E8=87=AA=E8=BE=BE?= <980324341@qq.com> Date: Sun, 25 Oct 2026 22:42:17 +0800 Subject: [PATCH] =?UTF-8?q?fix(secrets):=20=E6=8D=A2=E5=8F=B7=E6=9C=9F?= =?UTF-8?q?=E9=97=B4=E7=9A=84=E6=97=A7=E8=B4=A6=E5=8F=B7=E4=BB=A3=E7=90=86?= =?UTF-8?q?=E4=B8=8E=E5=BF=AB=E7=85=A7=E4=B8=8D=E5=BE=97=E8=90=BD=E5=88=B0?= =?UTF-8?q?=E6=96=B0=E8=B4=A6=E5=8F=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 登出清理涉及两次异步桥调用(读/写 app.json),期间可能已经换号。 给锁定代理回填、代理补报和继承快照消费都加上当前 uid 复核: 旧账号的代理不写进新账号的本地 proxy_users,也不带新账号令牌补报; 继承在读到快照后再确认一次 uid,变了就放弃本次继承。 --- .../shared/utils/api-secret-inheritance.ts | 2 ++ .../src/shared/utils/api-secret-store.ts | 22 ++++++++++++++----- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/frontend-vue/src/shared/utils/api-secret-inheritance.ts b/frontend-vue/src/shared/utils/api-secret-inheritance.ts index 0fe3cb069..6c34dd291 100644 --- a/frontend-vue/src/shared/utils/api-secret-inheritance.ts +++ b/frontend-vue/src/shared/utils/api-secret-inheritance.ts @@ -132,6 +132,8 @@ export async function inheritSecretsFromDevice( console.warn('[api-secret] 读取本机继承快照失败(下次加载重试):', error) return null }) + // 等配置期间可能已经登出/换号:旧账号的快照不能写进新账号的服务端 + if (host.currentUid() !== uid) return { count: 0, notice: null } const stash = readInheritedSecretStash(config, host.moduleKeys()) if (!stash || stash.fromUid === uid) return { count: 0, notice: null } const serverHas = new Set(serverItems.filter((item) => item?.exists).map((item) => item.moduleKey)) diff --git a/frontend-vue/src/shared/utils/api-secret-store.ts b/frontend-vue/src/shared/utils/api-secret-store.ts index 4f7272a68..cd9111076 100644 --- a/frontend-vue/src/shared/utils/api-secret-store.ts +++ b/frontend-vue/src/shared/utils/api-secret-store.ts @@ -410,7 +410,10 @@ export function ensureApiSecretsLoaded(): Promise { return loadApiSecrets() } -async function applyServerBundle(bundle: UserApiSecretBundle | null | undefined): Promise { +async function applyServerBundle( + bundle: UserApiSecretBundle | null | undefined, + epoch: number, +): Promise { if (Array.isArray(bundle?.requiredModules) && bundle.requiredModules.length) { requiredModules = bundle.requiredModules } @@ -420,6 +423,8 @@ async function applyServerBundle(bundle: UserApiSecretBundle | null | undefined) } } serverProxy = toServerProxy(bundle?.proxy) + // 登出/换号可能发生在读配置的等待里:旧账号的锁定代理绝不能写进新账号的本地配置 + if (epoch !== cacheEpoch) return if (serverProxy?.locked && serverProxy.full) { // 后台锁定代理:把后台值对齐到本地配置(客户端任务链读本地),先比对、幂等、失败静默 await syncLockedProxyToLocal(serverProxy.full) @@ -434,7 +439,7 @@ async function doLoad(): Promise { try { let bundle = await fetchMyApiSecrets() if (epoch !== cacheEpoch) return 'unknown' - await applyServerBundle(bundle) + await applyServerBundle(bundle, epoch) if (epoch !== cacheEpoch) return 'unknown' bundleLoaded = true notify() @@ -443,7 +448,7 @@ async function doLoad(): Promise { if (migrated > 0) { bundle = await fetchMyApiSecrets() if (epoch !== cacheEpoch) return 'unknown' - await applyServerBundle(bundle) + await applyServerBundle(bundle, epoch) if (epoch !== cacheEpoch) return 'unknown' notify() } @@ -455,7 +460,7 @@ async function doLoad(): Promise { if (inherited > 0) { bundle = await fetchMyApiSecrets() if (epoch !== cacheEpoch) return 'unknown' - await applyServerBundle(bundle) + await applyServerBundle(bundle, epoch) if (epoch !== cacheEpoch) return 'unknown' notify() } @@ -524,9 +529,12 @@ async function tryMigrateLocalSecrets(serverItems: UserApiSecretItem[]): Promise */ async function tryBackfillProxyToServer(): Promise { try { - if (currentUid() === '0') return false + const uid = currentUid() + if (uid === '0') return false const config = await readConfigForBackfill() if (!config) return false + // 等配置期间可能已经登出/换号:补报请求会带新账号令牌,必须放弃旧账号的本地代理 + if (currentUid() !== uid) return false const url = readLocalProxyUrl(config) if (!url) return false const result = await migrateMyApiSecrets([{ moduleKey: 'proxy', value: url }]) @@ -612,9 +620,11 @@ async function syncLockedProxyToLocal(full: string): Promise { if (typeof window === 'undefined') return const api = window.pywebview?.api if (!api?.read_config || !api?.save_config) return + const uidAtStart = currentUid() const config = (await api.read_config()) as Record | null + if (currentUid() !== uidAtStart) return if (readLocalProxyUrl(config) === full) return - const uid = currentUid() + const uid = uidAtStart if (uid === '0') { const mode = Number(config?.proxy_mode) === 2 ? 2 : 1 await api.save_config({ proxy_url: full, proxy_mode: mode })