fix: harden authentication and revoke stale sessions

This commit is contained in:
xpp committed 2026-10-21 22:05:43 +08:00
1 parent c716ec7478
commit d994ffb9a5
14 files changed
+373 -29

No files matched your search

@@ -0,0 +1,2 @@
<!doctype html>
<html lang="zh-CN"><head><meta charset="UTF-8" /><meta name="viewport" content="width=device-width,initial-scale=1" /><title>Isolated account security preview</title></head><body><div id="app"></div><script type="module" src="/tests/auth-security-preview.ts"></script></body></html>
+19
View File
@@ -0,0 +1,19 @@
// Isolated UI fixture; every API request is intercepted. No real account or credentials are used.
import { createApp, h, ref } from 'vue'
import AccountSettings from '../src/components/AccountSettings.vue'
import AuthView from '../src/views/AuthView.vue'
import '../src/styles.css'
const user = { id: 'isolated-security-user', account: 'test@example.test', accountKind: 'email' as const, displayName: '隔离测试账号', role: 'super_admin' as const, status: 'active' as const, createdAt: '2026-10-21T00:00:00Z' }
const loginRequired = ref(false), notice = ref(''), writes = ref(0)
window.fetch = async (input, init) => {
const path = new URL(typeof input === 'string' ? input : input instanceof URL ? input.href : input.url, location.origin).pathname
const json = (data: unknown) => new Response(JSON.stringify(data), { headers: { 'Content-Type': 'application/json' } })
if (path === '/api/auth/account' && init?.method === 'PATCH') { writes.value++; return json({ user }) }
if (path === '/api/auth/verification') return json({ email: false, phone: false })
if (path.includes('/mfa')) return json({ enabled: false, recoveryRemaining: 0 })
return json({})
}
createApp({ setup: () => () => h('main', [
h('output', { 'aria-label': '隔离测试状态', style: 'display:block;padding:16px;background:#fffaf4;position:fixed;top:0;left:0;z-index:2000;font-size:14px' }, `模拟接口写入 ${writes.value} 次;需要重新登录:${loginRequired.value ? '是' : '否'}。${notice.value}`),
loginRequired.value ? h(AuthView, { onNotify: (message: string) => notice.value = message }) : h(AccountSettings, { user, onReauthenticate: () => loginRequired.value = true, onSaved: () => notice.value = '仅资料保存不退出登录', onNotify: (message: string) => notice.value = message }),
]) }).mount('#app')