diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 126a6b3f..6ca4c4ef 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -44,6 +44,7 @@ jobs: echo "ADMINFILENAME=smail-admin_${{ matrix.goos }}_${{ matrix.goarch }}" >> ${GITHUB_ENV} echo "WCFILENAME=wechat_push_${{ matrix.goos }}_${{ matrix.goarch }}" >> ${GITHUB_ENV} echo "SPAMBLOCKFILENAME=spam_block_${{ matrix.goos }}_${{ matrix.goarch }}" >> ${GITHUB_ENV} + echo "TELEGRAMFILENAME=pmail_telegram_push_${{ matrix.goos }}_${{ matrix.goarch }}" >> ${GITHUB_ENV} echo "ZIPNAME=${{ matrix.goos }}_${{ matrix.goarch }}" >> ${GITHUB_ENV} - name: Rename Windows File if: matrix.goos == 'windows' @@ -52,6 +53,7 @@ jobs: echo "ADMINFILENAME=smail-admin_${{ matrix.goos }}_${{ matrix.goarch }}.exe" >> ${GITHUB_ENV} echo "WCFILENAME=wechat_push_${{ matrix.goos }}_${{ matrix.goarch }}.exe" >> ${GITHUB_ENV} echo "SPAMBLOCKFILENAME=spam_block_${{ matrix.goos }}_${{ matrix.goarch }}.exe" >> ${GITHUB_ENV} + echo "TELEGRAMFILENAME=pmail_telegram_push_${{ matrix.goos }}_${{ matrix.goarch }}.exe" >> ${GITHUB_ENV} - name: FE Build run: cd fe && yarn install --frozen-lockfile && yarn build - name: BE Build @@ -59,10 +61,15 @@ jobs: cd server cp -rf ../fe/dist listen/http_server BUILD_FLAGS="-s -w -X 'git.pcux.cn/xuans/Smail/internal/buildinfo.Version=${{ env.VERSION }}' -X 'git.pcux.cn/xuans/Smail/internal/buildinfo.GoVersion=$(go version)' -X 'git.pcux.cn/xuans/Smail/internal/buildinfo.GitHash=$(git show -s --format=%H)' -X 'git.pcux.cn/xuans/Smail/internal/buildinfo.BuildTime=$(date -u +%Y-%m-%dT%H:%M:%SZ)'" - go build -ldflags "$BUILD_FLAGS" -o ${{ env.FILENAME }} . + go build -ldflags "$BUILD_FLAGS" -o ${{ env.FILENAME }} ./cmd/smail go build -ldflags "$BUILD_FLAGS" -o ${{ env.ADMINFILENAME }} ./cmd/smail-admin go build -ldflags "-s -w" -o ${{ env.WCFILENAME }} hooks/wechat_push/wechat_push.go go build -ldflags "-s -w" -o ${{ env.SPAMBLOCKFILENAME }} hooks/spam_block/spam_block.go + cd ../plugins/pmail_telegram_push + npm ci + npm run build-only + go build -ldflags "-s -w" -o ../../server/${{ env.TELEGRAMFILENAME }} . + cd ../../server cat > release.json < output/release.json diff --git a/docs/后端接口说明文档.md b/docs/后端接口说明文档.md index 23c55917..03458182 100644 --- a/docs/后端接口说明文档.md +++ b/docs/后端接口说明文档.md @@ -571,7 +571,7 @@ curl -X POST "https://mail.example.com/api/email/send" \ | 参数 | 类型 | 必填 | 说明 | |---|---|---:|---| | `current_password` | string | 是 | 当前密码 | -| `password` | string | 是 | 新密码,长度为 8 到 256 字节 | +| `password` | string | 是 | 新密码,长度为 8 到 12 字节 | ### 调用示例 diff --git a/docs/安全审查风险整改任务清单.md b/docs/安全审查风险整改任务清单.md index 92b326b0..672ed361 100644 --- a/docs/安全审查风险整改任务清单.md +++ b/docs/安全审查风险整改任务清单.md @@ -823,3 +823,14 @@ go vet ./... - **专项补强**:新增三个插件分别拒绝 `generation == 0` 的负向测试,并验证 WeChat 与 Telegram Secret 仅按当前插件 ID 下发,其他插件 Secret 不进入运行时配置或序列化结果。 - **验证结果**:`server` 全量 Go 测试、Telegram 插件全量测试、目录专项测试和 `git diff --check` 通过;本记录仅表示本机自动化复核证据已补充。 - **未完成验收**:真实 Linux/Windows 生产隔离、真实数据库、生产网络白名单、浏览器和部署环境验证仍需独立完成,不修改 SEC-019 的最终发布阻塞边界。 + +## 2026-08-29 本轮开发完成记录 + +### 插件 V1 用户设置与安全边界 + +- **状态**:`[x] 已完成,等待复审` +- **本轮修改**:补充 Telegram 插件用户设置、Bot 信息、测试消息控制器测试;补充插件页面 V1 路径安全响应头测试;修正 V1 插件 iframe 未被识别为插件页面的问题;移除前端仍调用已停用旧版插件保存接口的逻辑。 +- **验证命令**:`go test ./... -count=1`(服务端);`go test ./controllers -run 'TestTelegram' -count=1`;`go test ./listen/http_server -run 'TestSecurityHeadersRespectPluginFrameBoundary' -count=1`。 +- **验证结果**:本地自动化测试通过;未将真实浏览器、Ubuntu、Telegram Bot 和生产插件进程验证标记为通过。 +- **遗留风险**:真实环境中的 iframe 渲染、插件进程隔离、Telegram API 连通性和用户可见页面仍需实机复审。 +- **复审日期**:2026-08-29(本机自动化复审)。 diff --git a/docs/超级管理员重置与邮箱验证码实施任务清单.md b/docs/超级管理员重置与邮箱验证码实施任务清单.md index 4c8c2210..c009aa1d 100644 --- a/docs/超级管理员重置与邮箱验证码实施任务清单.md +++ b/docs/超级管理员重置与邮箱验证码实施任务清单.md @@ -1387,3 +1387,11 @@ AD-065 + CG-053~CG-056 → AD-066 → CG-057 35. 未经用户许可删除文件、旧配置、数据库列或旧数据。 完成全部 66 项任务并关闭以上 35 项发布阻塞条件后,才能进入最终发布评审。 + +## 2026-08-29 本轮开发完成记录 + +- **状态**:`[x] 已完成,等待复审` +- **已完成内容**:补充插件 V1 接口的登录校验、请求字段边界、乐观锁版本冲突、Bot 信息脱敏和测试消息不落库验证;修正 V1 插件页面的 iframe 安全响应头识别;移除前端对已停用旧版插件保存接口的调用。 +- **本地验证**:服务端全量 `go test ./... -count=1` 通过;插件控制器和 HTTP 安全头专项测试通过。 +- **未完成真实验收**:超级管理员本机重置通道仍需在 Ubuntu 22.04、Windows 部署端和实际权限模型中复审;邮箱验证码、SMTP 投递、WebAuthn、真实浏览器和多实例流程不得标记为最终通过。 +- **复审日期**:2026-08-29(本机自动化复审)。 diff --git a/docs/配置系统重构实施任务清单.md b/docs/配置系统重构实施任务清单.md index 6ab7ba05..9035d777 100644 --- a/docs/配置系统重构实施任务清单.md +++ b/docs/配置系统重构实施任务清单.md @@ -1213,3 +1213,35 @@ CG-053~CG-056 → AD-066 → CG-057 - **未完成验收**:真实 Ubuntu 22.04/24.04、Windows 生产插件隔离、真实 MySQL/PostgreSQL、真实浏览器、生产 SMTP/IMAP/POP3、多实例部署和长期日志观测仍未完成,不能据此视为最终发布验收通过。 - **回退验证**:未删除既有文件、配置或数据库;如复审不通过,可通过停用插件回退,不恢复复制完整主配置文件的旧路径。 - **复审人**:Codex(2026-08-28,本机自动化复审) + +## 2026-08-29 本轮开发完成记录 + +- **状态**:`[x] 已完成,等待复审` +- **已完成内容**:完成插件用户设置服务与 V1 API 的当前用户绑定、版本并发控制、未知字段拒绝和 Secret 不回显验证;完成插件运行时设置下发边界和 V1 插件页面安全头修正;清理前端对旧版插件配置保存接口的调用路径。 +- **本地验证**:服务端全量测试通过,插件配置服务、控制器、框架和 HTTP 路由相关专项测试通过。 +- **未完成真实验收**:真实 MySQL/PostgreSQL 配置迁移、Ubuntu/Windows 正式部署、插件生产隔离、浏览器页面、SMTP/IMAP/POP3 和 Telegram Bot 仍需现场复审。 +- **复审日期**:2026-08-29(本机自动化复审)。 + +## 2026-08-30 配置审计、受控重启和数据库迁移基础链路复审记录 + +- **本轮状态**:`[x] 已完成,等待复审` +- **执行任务**:继续实施 CG-013,补齐配置审计详情与正式导出、受控重启预览、数据库名称迁移安全基础链路及定向测试。 +- **修改文件**:`server/config/audit_query.go`、`server/config/audit_export.go`、`server/config/audit_query_test.go`、`server/config/audit_store.go`、`server/controllers/config_audit.go`、`server/controllers/config_audit_query_test.go`、`server/controllers/database_migration.go`、`server/controllers/restart.go`、`server/listen/http_server/http_server.go`、`server/listen/http_server/api_v1_compat.go`、`server/listen/http_server/api_v1_compat_test.go`、`server/services/access/catalog.go`、`server/services/dbmigration/`、`server/services/restart/`。 +- **实施摘要**:配置审计事件支持稳定 ID、详情查询和正式 JSON/CSV 导出;导出响应设置禁止缓存并保留敏感字段脱敏边界;受控重启预览只返回固定 Smail 目标,不接受服务名、命令、脚本或参数;数据库迁移仅允许同类型、同服务器、同端口、同账户下的数据库名称或 SQLite 本地引用变更,采用短期一次性预览票据和按迁移 ID 隔离的状态机,失败时保留旧配置。 +- **定向测试**:`go test ./services/dbmigration -count=1`、`go test -race ./services/dbmigration -count=1`、`go test ./config -count=1`、`go test ./controllers ./services/restart ./listen/http_server -count=1` 均通过。 +- **安全检查**:修复迁移状态读取的并发访问边界;拒绝状态倒退;票据只保存哈希且执行后立即失效;审计详情和导出不返回密码、密钥、票据或底层错误;新路由已纳入能力目录和方法限制测试。 +- **明确未完成项**:真实 MySQL、PostgreSQL、SQLite 数据复制、校验和原子切换执行器尚未接入;Ubuntu 22.04、Windows、真实三数据库、多实例、浏览器和生产环境尚未完成实机验收;CG-013 不得标记为最终复审通过,数据库迁移相关任务继续保持 `[~] 进行中`。 +- **全量复审状态**:待执行 Go 全量测试、`go vet`、前端构建与 ESLint、差异和敏感信息检查。 +- **Git 状态**:本轮不自动提交、不自动推送,等待用户明确授权。 +- **复审人**:待复审。 + +## 2026-08-30 全量自动化复审结果 + +- **复审状态**:`[x] 已完成,等待人工与实机复审` +- **Go 测试**:`go test ./... -count=1` 通过;`go test -race ./... -count=1` 通过;`go vet ./...` 通过。 +- **前端检查**:`npm.cmd run build` 通过;ESLint 通过。构建仅提示既有资源分块偏大和动态导入提示,不影响构建成功。 +- **仓库检查**:`git diff --check` 通过;未发现新增 `` `n ``、`` `r`n ``、替换字符或 HTML 数字实体乱码;未发现本轮测试生成的服务二进制进入 Git 状态。 +- **结论**:本轮配置审计、受控重启预览、数据库迁移安全基础链路和定向测试达到待复审状态;配置系统重构整体仍不能宣称全部完成。 +- **发布阻塞**:真实 MySQL/PostgreSQL/SQLite 数据复制、校验、原子切换执行器尚未实现;真实 Ubuntu 22.04、Windows、浏览器、三数据库、邮件投递、多实例和生产环境验收尚未完成;CG-013 及依赖真实迁移执行器的任务不得标记为 `[✓]`。 +- **Git 操作**:没有执行 `git add`、`git commit` 或 `git push`;既有工作区改动和未跟踪文件保持原样,等待用户授权后再按文件范围提交。 +- **复审人**:待人工复审。 diff --git a/fe/src/stores/useGlobalStatusStore.js b/fe/src/stores/useGlobalStatusStore.js index 7d3f9e70..c23e00bf 100644 --- a/fe/src/stores/useGlobalStatusStore.js +++ b/fe/src/stores/useGlobalStatusStore.js @@ -34,7 +34,7 @@ const useGlobalStatusStore = defineStore("useGlobalStatusStore", { this.authLoading = true; try { - const response = await http.post("/api/user/info", {}); + const response = await http.post("/api/v1/user/info", {}); if (response.errorNo === 0 && response.data) { this.setUser(response.data, false); this.authChecked = true; diff --git a/fe/src/utils/axios.js b/fe/src/utils/axios.js index 064279a3..e4cc874a 100644 --- a/fe/src/utils/axios.js +++ b/fe/src/utils/axios.js @@ -27,6 +27,21 @@ http.interceptors.request.use((config) => { Promise.reject(error)); //响应拦截器 +function attachApiErrorDetails(error) { + const payload = error?.response?.data + const details = payload?.data + + if (payload && typeof payload === 'object') { + error.apiErrorCode = typeof details?.code === 'string' ? details.code : '' + error.apiRequestId = typeof details?.requestId === 'string' ? details.requestId : '' + error.apiErrorFields = details?.fields && typeof details.fields === 'object' ? details.fields : {} + if (typeof payload.errorMsg === 'string' && payload.errorMsg.trim()) { + error.message = payload.errorMsg + } + } + + return error +} http.interceptors.response.use(async (response) => { //响应成功 if (response.data.errorNo === 403) { @@ -95,9 +110,13 @@ http.interceptors.response.use(async (response) => { // eslint-disable-next-line no-unused-vars message = '请求失败'; } - return Promise.reject(error); + const enrichedError = attachApiErrorDetails(error) + if (message && !enrichedError.response?.data?.errorMsg) { + enrichedError.message = message + } + return Promise.reject(enrichedError) } - return Promise.reject(error); + return Promise.reject(attachApiErrorDetails(error)); }); -export {http}; \ No newline at end of file +export {http}; diff --git a/fe/src/utils/password.js b/fe/src/utils/password.js new file mode 100644 index 00000000..09ff7717 --- /dev/null +++ b/fe/src/utils/password.js @@ -0,0 +1,11 @@ +export const PASSWORD_MIN_BYTES = 8 +export const PASSWORD_MAX_BYTES = 12 + +export function getPasswordByteLength(value) { + return new TextEncoder().encode(value || "").length +} + +export function isValidPasswordLength(value) { + const length = getPasswordByteLength(value) + return length >= PASSWORD_MIN_BYTES && length <= PASSWORD_MAX_BYTES +} diff --git a/fe/src/views/Editer/Editer.js b/fe/src/views/Editer/Editer.js index 59c714da..c01f6134 100644 --- a/fe/src/views/Editer/Editer.js +++ b/fe/src/views/Editer/Editer.js @@ -169,7 +169,7 @@ export function usePage() { let text = editorRef.value.getText() - http.post("/api/email/send", { + http.post("/api/v1/email/send", { from: {name: ruleForm.nickName, email: ruleForm.sender + "@" + ruleForm.pick域名}, to: objectTos, cc: objectCcs, diff --git a/fe/src/views/EmailDetail/EmailDetail.js b/fe/src/views/EmailDetail/EmailDetail.js index e4644517..123dbc8e 100644 --- a/fe/src/views/EmailDetail/EmailDetail.js +++ b/fe/src/views/EmailDetail/EmailDetail.js @@ -31,7 +31,7 @@ export function usePage() { const showCC = ref(false) - http.post("/api/email/detail", {id: parseInt(route.params.id)}).then(res => { + http.post("/api/v1/email/detail", {id: parseInt(route.params.id)}).then(res => { detailData.value = res.data || {} detailData.value.attachments = res.data.attachments || []; @@ -88,7 +88,7 @@ export function usePage() { cancelButtonText: '取消', type: 'warning', }).then(() => { - http.post("/api/email/del", {ids: [id], forcedDel}).then(res => { + http.post("/api/v1/email/del", {ids: [id], forcedDel}).then(res => { if (res.errorNo === 0) { ElMessage.success('删除成功'); router.push({name: 'list'}); diff --git a/fe/src/views/ForcePasswordChange/ForcePasswordChange.js b/fe/src/views/ForcePasswordChange/ForcePasswordChange.js index 56254ba7..178082a6 100644 --- a/fe/src/views/ForcePasswordChange/ForcePasswordChange.js +++ b/fe/src/views/ForcePasswordChange/ForcePasswordChange.js @@ -6,6 +6,8 @@ import { useRouter } from "vue-router" import { http } from "@/utils/axios" +import { isValidPasswordLength } from "@/utils/password" + import { useGlobalStatusStore } from "@/stores/useGlobalStatusStore" export function usePage() { @@ -27,14 +29,14 @@ export function usePage() { ElMessage.warning("两次输入的新密码不一致") return } - if (new TextEncoder().encode(form.newPassword).length < 8) { - ElMessage.warning("新密码长度至少为 8 个字节") + if (!isValidPasswordLength(form.newPassword)) { + ElMessage.warning("新密码长度必须为 8 到 12 个字节") return } loading.value = true try { - const response = await http.post("/api/settings/modify_password", { + const response = await http.post("/api/v1/settings/modify_password", { current_password: form.currentPassword, password: form.newPassword }) @@ -54,7 +56,7 @@ export function usePage() { const logout = async () => { try { - await http.post("/api/logout", {}) + await http.post("/api/v1/logout", {}) } finally { globalStatus.clear() await router.replace({ name: "login" }) diff --git a/fe/src/views/List/List.js b/fe/src/views/List/List.js index 484109a9..98af49f3 100644 --- a/fe/src/views/List/List.js +++ b/fe/src/views/List/List.js @@ -47,14 +47,14 @@ export function usePage() { const totalPage = ref(0) const updateList = function () { - http.post("/api/email/list", {tag: tag, page_size: 15}).then(res => { + http.post("/api/v1/email/list", {tag: tag, page_size: 15}).then(res => { data.value = res.data.list || [] totalPage.value = res.data.total_page || 0 }) } const updateGroupList = function () { - http.post("/api/group/list").then(res => { + http.post("/api/v1/group/list").then(res => { groupList.value = res.data || [] }) } @@ -100,7 +100,7 @@ export function usePage() { return; } let ids = rows.map(e => e.id); - http.post("/api/email/read", {"ids": ids}).then(res => { + http.post("/api/v1/email/read", {"ids": ids}).then(res => { if (res.errorNo === 0) { updateList() ElMessage.success('Marked as read'); @@ -121,7 +121,7 @@ export function usePage() { ElMessageBox.confirm(lang.move_email_confirm, '警告', { confirmButtonText: '确定', cancelButtonText: '取消', type: 'warning' }).then(() => { - http.post("/api/email/move", {"group_id": group_id, "group_name": group_name, "ids": ids}).then(res => { + http.post("/api/v1/email/move", {"group_id": group_id, "group_name": group_name, "ids": ids}).then(res => { if (res.errorNo === 0) { updateList() ElMessage.success('移动完成') @@ -144,7 +144,7 @@ export function usePage() { ElMessageBox.confirm(lang.del_email_confirm, '警告', { confirmButtonText: '确定', cancelButtonText: '取消', type: 'warning' }).then(() => { - http.post("/api/email/del", {"ids": ids, "forcedDel": groupTag.status === 3}).then(res => { + http.post("/api/v1/email/del", {"ids": ids, "forcedDel": groupTag.status === 3}).then(res => { if (res.errorNo === 0) { updateList() ElMessage.success('删除成功') @@ -160,7 +160,7 @@ export function usePage() { } const pageChange = function (p) { - http.post("/api/email/list", {tag: tag, page_size: 15, current_page: p}).then(res => { + http.post("/api/v1/email/list", {tag: tag, page_size: 15, current_page: p}).then(res => { data.value = res.data.list || [] }) } diff --git a/fe/src/views/Login/Login.js b/fe/src/views/Login/Login.js index a479ac0c..79bfe8b2 100644 --- a/fe/src/views/Login/Login.js +++ b/fe/src/views/Login/Login.js @@ -26,7 +26,7 @@ export function usePage() { } loading.value = true try { - const res = await http.post("/api/login", form) + const res = await http.post("/api/v1/login", form) if (res.errorNo !== 0) { ElMessage.error(res.errorMsg) return diff --git a/fe/src/views/LoginVerification/LoginVerification.js b/fe/src/views/LoginVerification/LoginVerification.js index 096f4ea0..24e30946 100644 --- a/fe/src/views/LoginVerification/LoginVerification.js +++ b/fe/src/views/LoginVerification/LoginVerification.js @@ -69,7 +69,7 @@ export function usePage() { loading.value = true errorMessage.value = "" try { - const response = await http.post("/api/security/login/verify", { + const response = await http.post("/api/v1/security/login/verify", { id: pending.value.challengeId, account: pending.value.account, code: code.value.trim() @@ -96,7 +96,7 @@ export function usePage() { resending.value = true errorMessage.value = "" try { - const response = await http.post("/api/security/login/resend", { + const response = await http.post("/api/v1/security/login/resend", { id: pending.value.challengeId, account: pending.value.account }) @@ -126,7 +126,7 @@ export function usePage() { webAuthnLoading.value = true errorMessage.value = "" try { - const begin = await http.post("/api/security/webauthn/login/begin", { + const begin = await http.post("/api/v1/security/webauthn/login/begin", { challenge_id: pending.value.challengeId, account: pending.value.account }) @@ -136,7 +136,7 @@ export function usePage() { const credential = await navigator.credentials.get({ publicKey: normalizeRequestOptions(begin.data.options) }) - const finish = await http.post("/api/security/webauthn/login/finish", { + const finish = await http.post("/api/v1/security/webauthn/login/finish", { challenge_id: pending.value.challengeId, account: pending.value.account, session_id: begin.data.session_id, diff --git a/fe/src/views/PasswordRecovery/PasswordRecovery.js b/fe/src/views/PasswordRecovery/PasswordRecovery.js index 4cdf1493..12b42afb 100644 --- a/fe/src/views/PasswordRecovery/PasswordRecovery.js +++ b/fe/src/views/PasswordRecovery/PasswordRecovery.js @@ -4,6 +4,8 @@ import { ElMessage } from 'element-plus' import { http } from '@/utils/axios' +import { isValidPasswordLength } from '@/utils/password' + export function usePage() { const loading = ref(false) @@ -61,7 +63,7 @@ export function usePage() { verificationState.value = '' sendingCode.value = true try { - const result = await http.post('/api/security/recovery/begin', { + const result = await http.post('/api/v1/security/recovery/begin', { identifier: recovery.identifier, email: recovery.email }) @@ -84,9 +86,8 @@ export function usePage() { ElMessage.warning('两次输入的新密码不一致') return false } - const passwordLength = new TextEncoder().encode(recovery.newPassword).length - if (passwordLength < 8 || passwordLength > 256) { - ElMessage.warning('新密码长度必须为 8-256 个字节') + if (!isValidPasswordLength(recovery.newPassword)) { + ElMessage.warning('新密码长度必须为 8 到 12 个字节') return false } return true @@ -128,7 +129,7 @@ export function usePage() { answer: recovery.answer, recovery_code: recovery.recoveryCode } - const result = await http.post('/api/security/recovery/verify', payload) + const result = await http.post('/api/v1/security/recovery/verify', payload) if (result.errorNo !== 0 || !result.data?.ticket) throw new Error('验证失败') verificationTicket.value = result.data.ticket return result.data.ticket @@ -141,7 +142,7 @@ export function usePage() { verificationState.value = '' try { const ticket = await verifyRecovery() - const result = await http.post('/api/security/recovery/complete', { + const result = await http.post('/api/v1/security/recovery/complete', { ticket, new_password: recovery.newPassword }) diff --git a/fe/src/views/Recovery/Recovery.css b/fe/src/views/Recovery/Recovery.css index 2376c294..01b83454 100644 --- a/fe/src/views/Recovery/Recovery.css +++ b/fe/src/views/Recovery/Recovery.css @@ -1,295 +1,169 @@ .recovery-content { width: 100%; - max-width: 760px; + max-width: 720px; min-width: 0; - margin: auto; - padding: clamp(28px, 4vw, 48px); + margin: 0 auto; + padding: clamp(24px, 4vw, 44px); box-sizing: border-box; } +.reset-boundary { + margin-top: 18px; +} + +.security-notice, +.steps-card, +.channel-card { + min-width: 0; + box-sizing: border-box; + border: 1px solid var(--pm-border-color); + border-radius: 14px; + background: rgba(247, 250, 255, 0.9); + box-shadow: 0 4px 14px rgba(31, 41, 55, 0.04); +} + .security-notice { display: flex; - gap: 8px; - min-width: 0; - margin-bottom: 18px; - padding: 12px 14px; - box-sizing: border-box; - color: var(--pm-text-secondary); - background: rgba(247, 250, 255, 0.88); - border: 1px solid var(--pm-border-color); - border-radius: 12px; - font-size: 13px; - line-height: 1.6; + gap: 14px; + align-items: flex-start; + padding: 18px; + border-color: rgba(245, 158, 11, 0.32); + background: rgba(255, 251, 235, 0.92); } -.security-notice strong { +.notice-icon { + display: inline-flex; flex: 0 0 auto; - color: var(--pm-text-primary); - white-space: nowrap; + align-items: center; + justify-content: center; + width: 28px; + height: 28px; + border-radius: 50%; + color: #ffffff; + background: #d97706; + font-size: 17px; + font-weight: 700; } -.security-notice span { - min-width: 0; +.security-notice h2, +.steps-card h3 { + margin: 0; + color: var(--pm-text-primary); + line-height: 1.4; +} + +.security-notice h2 { + font-size: 19px; +} + +.security-notice p, +.channel-card p { + margin: 8px 0 0; + color: var(--pm-text-secondary); + font-size: 14px; + line-height: 1.7; overflow-wrap: anywhere; } -.method-switcher { +.steps-card, +.channel-card { + margin-top: 16px; + padding: 18px; +} + +.steps-card h3 { + font-size: 17px; +} + +.steps-card ol { + margin: 12px 0 0; + padding-left: 24px; + color: var(--pm-text-secondary); + font-size: 14px; + line-height: 1.8; +} + +.steps-card li + li { + margin-top: 4px; +} + +code { + padding: 2px 6px; + border-radius: 6px; + color: var(--pm-primary-color); + background: rgba(37, 99, 235, 0.1); + font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; + font-size: 0.94em; +} + +.channel-heading { display: flex; + gap: 10px; align-items: center; justify-content: space-between; - gap: 16px; - min-width: 0; - margin-bottom: 18px; - padding: 10px 14px; - box-sizing: border-box; - background: rgba(247, 250, 255, 0.88); - border: 1px solid var(--pm-border-color); - border-radius: 12px; - box-shadow: 0 4px 14px rgba(31, 41, 55, 0.04); -} - -.method-copy { - min-width: 0; - display: flex; - flex-direction: column; - gap: 5px; -} - -.method-label { color: var(--pm-text-secondary); - font-size: 13px; - line-height: 1.35; + font-size: 14px; } -.method-copy strong { +.channel-heading strong { color: var(--pm-text-primary); + font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 16px; - font-weight: 600; - line-height: 1.35; - overflow-wrap: anywhere; } -.switch-button { - flex: 0 1 auto; - max-width: 48%; - white-space: normal; -} - -.verification-panel { - min-width: 0; - margin-bottom: 18px; - padding: 16px; - box-sizing: border-box; - background: rgba(247, 250, 255, 0.88); - border: 1px solid var(--pm-border-color); - border-radius: 12px; - box-shadow: 0 4px 14px rgba(31, 41, 55, 0.04); -} - -.verification-panel h2 { - margin: 0 0 6px; - color: var(--pm-text-primary); - font-size: 17px; - line-height: 1.35; - overflow-wrap: anywhere; -} - -.verification-panel p { - margin: 0 0 14px; - color: var(--pm-text-secondary); - font-size: 13px; - line-height: 1.6; - overflow-wrap: anywhere; -} - -.verification-panel :deep(.el-form-item) { - margin-bottom: 10px; -} - -.verification-panel :deep(.el-form-item__label), -.password-form :deep(.el-form-item__label) { - max-width: 100%; - padding-bottom: 4px; - color: var(--pm-text-primary); - font-weight: 500; - line-height: 1.35; - white-space: normal; - overflow-wrap: anywhere; -} - -.verification-panel :deep(.el-input__wrapper), -.password-form :deep(.el-input__wrapper) { - min-height: 44px; - background-color: var(--pm-surface-muted); - border: 1px solid transparent; - border-radius: 12px; - box-shadow: 0 0 0 1px var(--pm-border-color) inset !important; - transition: all 0.2s; -} - -.verification-panel :deep(.el-input__wrapper:hover), -.verification-panel :deep(.el-input__wrapper.is-focus), -.password-form :deep(.el-input__wrapper:hover), -.password-form :deep(.el-input__wrapper.is-focus) { - border-color: var(--pm-primary-color); - background-color: var(--pm-bg-secondary); -} - -.recovery-action-btn, -.switch-button { - min-height: 44px; - padding: 0 14px; - border-radius: 14px; - font-size: 15px; - font-weight: 600; - line-height: 1.35; - white-space: normal; -} - -.recovery-action-btn { - box-shadow: 0 10px 24px rgba(37, 99, 235, 0.2); -} - -.recovery-action-btn:hover { - transform: translateY(-1px); - box-shadow: 0 14px 28px rgba(37, 99, 235, 0.26); -} - -.secondary-action-btn { - color: var(--pm-text-primary); - border-color: var(--pm-border-color); - background: rgba(240, 246, 255, 0.9); - box-shadow: 0 4px 14px rgba(31, 41, 55, 0.04); -} - -.secondary-action-btn:hover, -.secondary-action-btn:focus-visible { - color: var(--pm-primary-color); - border-color: rgba(37, 99, 235, 0.36); - background: rgba(37, 99, 235, 0.07); - transform: translateY(-1px); -} - -.email-verification-row { - width: 100%; - min-width: 0; - display: grid; - grid-template-columns: minmax(0, 1fr) minmax(128px, auto); - gap: 10px; -} - -.email-verification-row > * { - min-width: 0; -} - -.email-verification-row :deep(.el-button) { - width: 100%; -} - -.verification-state { - display: block; - min-width: 0; - margin-top: 10px; - color: var(--pm-text-secondary); - font-size: 13px; - line-height: 1.45; - overflow-wrap: anywhere; -} - -.password-form :deep(.el-form-item) { - margin-bottom: 10px; -} - -.actions { +.channel-hint { display: flex; - justify-content: flex-end; - margin-top: 18px; + flex-wrap: wrap; + gap: 8px 16px; + margin-top: 12px; + color: var(--pm-text-secondary); + font-size: 12px; } .back-button { - display: block; - margin: 18px auto 0; + display: flex; + width: 100%; + margin-top: 20px; + min-height: 44px; + border-radius: 12px; + font-size: 15px; font-weight: 600; } @media (max-width: 760px) { .recovery-content { - max-width: none; - padding: 18px 16px 22px; + padding: 18px 16px 24px; } } -@media (max-width: 560px) { - .security-notice { - display: block; - } - - .security-notice strong { - display: block; - margin-bottom: 4px; - } - - .method-switcher { - gap: 8px; - } - - .switch-button { - max-width: 48%; - font-size: 13px; - } - - .email-verification-row { - grid-template-columns: minmax(0, 1fr) minmax(118px, auto); - } - - .actions, - .actions .el-button, - .back-button { - width: 100%; - } -} - -@media (max-width: 380px) { +@media (max-width: 480px) { .recovery-content { padding: 16px 12px 20px; } .security-notice, - .method-switcher, - .verification-panel { - padding: 10px; + .steps-card, + .channel-card { + padding: 14px; } - .method-switcher { - align-items: stretch; + .security-notice { + gap: 10px; + } + + .security-notice h2 { + font-size: 17px; + } + + .security-notice p, + .channel-card p, + .steps-card ol { + font-size: 13px; + } + + .channel-heading { + align-items: flex-start; flex-direction: column; + gap: 5px; } - - .switch-button { - width: 100%; - max-width: none; - } - - .email-verification-row { - grid-template-columns: minmax(0, 1fr); - } - - .method-label, - .verification-panel p, - .verification-state { - font-size: 11px; - } - - .method-copy strong, - .verification-panel h2 { - font-size: 14px; - } - - .recovery-action-btn, - .switch-button { - min-height: 38px; - padding-right: 10px; - padding-left: 10px; - font-size: 12px; - } -} +} \ No newline at end of file diff --git a/fe/src/views/Recovery/Recovery.js b/fe/src/views/Recovery/Recovery.js index b17051b0..57e245c2 100644 --- a/fe/src/views/Recovery/Recovery.js +++ b/fe/src/views/Recovery/Recovery.js @@ -1,139 +1,12 @@ -import { computed, reactive, ref } from 'vue' - -import { ElMessage } from 'element-plus' - -import { http } from '@/utils/axios' - -import { normalizeRequestOptions, serializeCredential, webAuthnSupported } from '@/utils/webauthn' +import { ref } from 'vue' export function usePage() { const loading = ref(false) - - const verificationTicket = ref('') - - const verificationState = ref('') - - const securityKeySupported = webAuthnSupported() - - const recovery = reactive({ - method: 'webauthn', - email: '', - code: '', - challengeId: '', - newPassword: '', - confirmPassword: '' - }) - - const verified = computed(() => verificationTicket.value !== '') - - const clearVerification = () => { - recovery.code = '' - recovery.challengeId = '' - verificationTicket.value = '' - verificationState.value = '' - } - - const switchRecoveryMethod = () => { - recovery.method = recovery.method === 'webauthn' ? 'email' : 'webauthn' - recovery.email = '' - clearVerification() - } - - const verifySecurityKey = async () => { - if (!securityKeySupported) { - ElMessage.warning('当前浏览器或访问环境不支持安全密钥') - return - } - clearVerification() - loading.value = true - try { - const begin = await http.post('/api/security/recovery/webauthn/begin', { identifier: 'super_admin' }) - if (begin.errorNo !== 0 || !begin.data?.options) throw new Error('安全密钥验证暂不可用') - const credential = await navigator.credentials.get({ publicKey: normalizeRequestOptions(begin.data.options) }) - const result = await http.post('/api/security/recovery/webauthn/verify', { - identifier: 'super_admin', - session_id: begin.data.session_id, - credential: serializeCredential(credential) - }) - if (result.errorNo !== 0 || !result.data?.ticket) throw new Error('安全密钥验证失败') - verificationTicket.value = result.data.ticket - verificationState.value = '安全密钥验证成功' - } catch (error) { - if (error?.name !== 'NotAllowedError') { - verificationState.value = '安全密钥验证未完成' - ElMessage.error(error?.message || '安全密钥验证失败') - } - } finally { - loading.value = false - } - } - - const requestRecoveryCode = async () => { - if (!recovery.email) { - ElMessage.warning('请填写外部安全邮箱') - return - } - clearVerification() - loading.value = true - try { - const result = await http.post('/api/security/recovery/begin', { identifier: 'super_admin', email: recovery.email }) - if (result.errorNo === 0 && result.data?.id) recovery.challengeId = result.data.id - verificationState.value = '如果邮箱有效,验证码将发送到该邮箱' - } catch (_) { - verificationState.value = '如果邮箱有效,验证码将发送到该邮箱' - } finally { - loading.value = false - } - } - - const validatePassword = () => { - if (!recovery.newPassword || !recovery.confirmPassword) { - ElMessage.warning('请填写两次新密码') - return false - } - if (recovery.newPassword !== recovery.confirmPassword) { - ElMessage.warning('两次输入的新密码不一致') - return false - } - if (new TextEncoder().encode(recovery.newPassword).length < 8) { - ElMessage.warning('新密码至少需要 8 个字节') - return false - } - return true - } - - const completeRecovery = () => { - if (!verified.value) { - ElMessage.warning('请先完成当前验证方式') - return - } - if (!validatePassword()) return - ElMessage.warning('请通过部署端 smail-admin 本机安全通道完成正式重置') - } - + const goLogin = () => window.location.assign('/#/login') return { - computed, - reactive, - ref, - ElMessage, - http, - normalizeRequestOptions, - serializeCredential, - webAuthnSupported, loading, - verificationTicket, - verificationState, - securityKeySupported, - recovery, - verified, - clearVerification, - switchRecoveryMethod, - verifySecurityKey, - requestRecoveryCode, - validatePassword, - completeRecovery, goLogin } -} +} \ No newline at end of file diff --git a/fe/src/views/Recovery/Recovery.vue b/fe/src/views/Recovery/Recovery.vue index 1f92efba..c9e4daf8 100644 --- a/fe/src/views/Recovery/Recovery.vue +++ b/fe/src/views/Recovery/Recovery.vue @@ -1,12 +1,12 @@ -