feat: 重构控制面安全机制与分页规范
本次提交包含多项安全加固和体验优化: 1. 分离管理密钥与传输凭证,避免持 API Token 者伪造管理员票据 2. 钉钉回调地址增加白名单校验,防止开放重定向钓鱼 3. 初始管理员密码改为随机生成并日志记录,移除硬编码 123456 4. 新增登录防爆破计数表,支持 MySQL 多 worker 共享 5. 统一分页规范,新增 usePagedList composable 和 PagerBar 组件 6. 控制面 CORS 收敛为白名单,避免公网环境下任意站点跨域 7. 插件管理、凭证管理等列表接口支持分页和搜索 8. 强制初始密码修改,未改密前禁止使用管理功能 9. 定时任务触发被拒日志节流,避免授权失效时刷屏 10. 健康检查接口移除环境信息泄露,返回固定响应
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
<template>
|
||||
<div class="pager-bar" v-if="total > 0">
|
||||
<el-pagination background layout="total, sizes, prev, pager, next"
|
||||
:total="total" :current-page="page" :page-size="pageSize"
|
||||
:page-sizes="[10, 20, 50, 100]"
|
||||
@current-change="p => emit('change', p, pageSize)"
|
||||
@size-change="s => emit('change', 1, s)" />
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
// 统一分页条:配合后端 page/page_size 分页接口({items,total})。
|
||||
// 用法:<PagerBar :total="total" :page="page" :page-size="pageSize"
|
||||
// @change="(p, s) => { page = p; pageSize = s; load() }" />
|
||||
defineProps({ total: { type: Number, default: 0 }, page: { type: Number, default: 1 }, pageSize: { type: Number, default: 20 } })
|
||||
const emit = defineEmits(['change'])
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.pager-bar { display: flex; justify-content: flex-end; padding: 12px 4px 2px; }
|
||||
</style>
|
||||
@@ -1,5 +1,10 @@
|
||||
<template>
|
||||
<el-dialog v-model="visible" title="修改密码" width="440px" align-center destroy-on-close @closed="reset">
|
||||
<el-dialog v-model="visible" title="修改密码" width="440px" align-center destroy-on-close
|
||||
:close-on-click-modal="!force" :close-on-press-escape="!force" :show-close="!force"
|
||||
@closed="onClosed">
|
||||
<el-alert v-if="force" type="warning" :closable="false" class="force-tip" show-icon>
|
||||
首次登录请先修改初始密码,修改成功后才能使用管理功能。
|
||||
</el-alert>
|
||||
<el-alert v-if="store.current" type="info" :closable="false" class="acct-tip" show-icon>
|
||||
当前账号:<b class="mono">{{ store.current }}</b>
|
||||
</el-alert>
|
||||
@@ -8,7 +13,7 @@
|
||||
<el-input v-model="form.oldPwd" type="password" placeholder="请输入原密码" show-password @keyup.enter="submit" />
|
||||
</el-form-item>
|
||||
<el-form-item label="新密码" prop="newPwd">
|
||||
<el-input v-model="form.newPwd" type="password" placeholder="至少 6 位,不与原密码相同" show-password @keyup.enter="submit" />
|
||||
<el-input v-model="form.newPwd" type="password" placeholder="至少 8 位,不与原密码相同" show-password @keyup.enter="submit" />
|
||||
</el-form-item>
|
||||
<el-form-item label="确认新密码" prop="newPwd2">
|
||||
<el-input v-model="form.newPwd2" type="password" placeholder="再次输入新密码" show-password @keyup.enter="submit" />
|
||||
@@ -16,7 +21,7 @@
|
||||
</el-form>
|
||||
<template #footer>
|
||||
<div class="modal-foot">
|
||||
<el-button @click="visible = false">取消</el-button>
|
||||
<el-button v-if="!force" @click="visible = false">取消</el-button>
|
||||
<el-button type="primary" :loading="busy" @click="submit">保存</el-button>
|
||||
</div>
|
||||
</template>
|
||||
@@ -29,16 +34,19 @@ import { ElMessage as message } from 'element-plus'
|
||||
import { store } from '../store'
|
||||
import { adminPassword } from '../api'
|
||||
|
||||
// force=true 强制改密模式(首次登录 must_change_pwd):不可取消/关闭,改密成功前不允许进入管理面
|
||||
const props = defineProps({ force: { type: Boolean, default: false } })
|
||||
const visible = defineModel({ type: Boolean, default: false })
|
||||
const formRef = ref()
|
||||
const busy = ref(false)
|
||||
const changed = ref(false)
|
||||
const form = reactive({ oldPwd: '', newPwd: '', newPwd2: '' })
|
||||
|
||||
const rules = {
|
||||
oldPwd: { required: true, message: '请输入原密码' },
|
||||
newPwd: [
|
||||
{ required: true, message: '请输入新密码' },
|
||||
{ min: 6, message: '新密码至少 6 位' },
|
||||
{ min: 8, message: '新密码至少 8 位' },
|
||||
{ validator: (_r, v, cb) => (v && v === form.oldPwd ? cb(new Error('新密码不能与原密码相同')) : cb()), message: '新密码不能与原密码相同' },
|
||||
],
|
||||
newPwd2: [
|
||||
@@ -52,11 +60,17 @@ function reset() {
|
||||
formRef.value?.resetFields()
|
||||
}
|
||||
|
||||
function onClosed() {
|
||||
// 强制模式下未改密成功不允许关闭:自动重新打开
|
||||
if (props.force && !changed.value) visible.value = true
|
||||
}
|
||||
|
||||
async function submit() {
|
||||
try { await formRef.value.validate() } catch (_) { return }
|
||||
busy.value = true
|
||||
try {
|
||||
await adminPassword({ account: store.current, old_password: form.oldPwd, new_password: form.newPwd })
|
||||
changed.value = true
|
||||
message.success('密码已修改,下次登录请使用新密码')
|
||||
visible.value = false
|
||||
} catch (e) {
|
||||
@@ -68,6 +82,7 @@ async function submit() {
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.force-tip { margin-bottom: 14px; }
|
||||
.acct-tip { margin-bottom: 16px; }
|
||||
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; }
|
||||
</style>
|
||||
|
||||
Reference in New Issue
Block a user