fix: harden authentication and revoke stale sessions
This commit is contained in:
1 parent
c716ec7478
commit
d994ffb9a5
14 files changed
+373
-29
No files matched your search
@@ -104,6 +104,17 @@ function accountSaved(user: AuthUser) {
|
||||
accountSettingsOpen.value = false
|
||||
}
|
||||
|
||||
function passwordChanged() {
|
||||
accountSettingsOpen.value = false
|
||||
accountMenuOpen.value = false
|
||||
availableCredit.value = undefined
|
||||
authUser.value = undefined
|
||||
authenticated.value = false
|
||||
userName.value = ''
|
||||
portal.value = 'user'
|
||||
activeView.value = 'overview'
|
||||
}
|
||||
|
||||
function openHelp() {
|
||||
accountMenuOpen.value = false
|
||||
if (portal.value === 'user') {
|
||||
@@ -208,6 +219,7 @@ function openGlobalSearch() {
|
||||
:user="authUser"
|
||||
@close="accountSettingsOpen = false"
|
||||
@saved="accountSaved"
|
||||
@reauthenticate="passwordChanged"
|
||||
@notify="notify"
|
||||
/>
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ import UiModal from './UiModal.vue'
|
||||
import MfaSettings from './MfaSettings.vue'
|
||||
|
||||
const props = defineProps<{ user: AuthUser }>()
|
||||
const emit = defineEmits<{ close: []; saved: [user: AuthUser]; notify: [message: string] }>()
|
||||
const emit = defineEmits<{ close: []; saved: [user: AuthUser]; reauthenticate: []; notify: [message: string] }>()
|
||||
const form = reactive({ displayName: props.user.displayName, currentPassword: '', newPassword: '', confirmPassword: '' })
|
||||
const saving = ref(false)
|
||||
|
||||
@@ -24,8 +24,13 @@ async function save() {
|
||||
currentPassword: form.currentPassword || undefined,
|
||||
newPassword: form.newPassword || undefined,
|
||||
})
|
||||
emit('saved', user)
|
||||
emit('notify', '账号设置已保存')
|
||||
if (form.newPassword) {
|
||||
emit('reauthenticate')
|
||||
emit('notify', '密码已修改,全部浏览器会话已撤销,请重新登录')
|
||||
} else {
|
||||
emit('saved', user)
|
||||
emit('notify', '账号设置已保存')
|
||||
}
|
||||
} catch (error) {
|
||||
emit('notify', error instanceof Error ? error.message : '账号设置保存失败')
|
||||
} finally {
|
||||
@@ -46,7 +51,7 @@ async function save() {
|
||||
<input id="account-new-password" v-model="form.newPassword" type="password" class="text-input" maxlength="256" autocomplete="new-password" placeholder="留空表示不修改" />
|
||||
<label class="form-label" for="account-confirm-password">确认新密码</label>
|
||||
<input id="account-confirm-password" v-model="form.confirmPassword" type="password" class="text-input" maxlength="256" autocomplete="new-password" placeholder="留空表示不修改" />
|
||||
<p class="form-hint">普通用户新密码至少 8 位;超级管理员按实际设置保存。</p>
|
||||
<p class="form-hint">所有角色新密码均为 8 至 256 位。修改后全部浏览器会话失效,需重新登录;API Key 不自动撤销。</p>
|
||||
</form>
|
||||
<MfaSettings />
|
||||
<template #footer>
|
||||
|
||||
@@ -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>
|
||||
@@ -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')
|
||||
Reference in new issue
Block a user