Repository navigation
fix: 令牌重复存储、字典/角色冲突落成 500、生成物与默认值漂移 - #15
Merged
Merged
Conversation
同一份 access/refresh token 此前既写 cookie 又写 localStorage。 该 cookie 由前端 JS 写入、不带 HttpOnly,JS 可读写,因此不提供任何 额外的 XSS 防护,只是把凭证暴露面翻倍;后端只从 Authorization 头 取令牌,从不读取它。 - 读取/写入只走 localStorage,删除 setCookie/getCookie - remove* 仍清理旧版本遗留的同名 cookie,升级后不会被误读 - 测试内存 localStorage 从空实现改为真实 Map,使会话测试校验真正 的持久化路径,并断言不再写 token cookie Refs: 审查项 ahaodev#4(凭证暴露面)
DictItem 上 (type_id, label) 有唯一索引,但创建/更新只检查了 value, 重复 label 会以 ent 约束错误冒泡到 controller,最终落到 500。 - 新增 domain.ErrDictItemLabelExists,并在 errorRules 登记为 409 (沿用 value 冲突的处理方式,错误文案精确到 label) - CreateItem/UpdateItem 在事务内前置检查 label,更新时排除自身 - 回归测试覆盖创建重复 label、改名撞已有 label、以及改成自身 label 不被误挡;回退修复后该测试复现 `UNIQUE constraint failed: dict_items.type_id, dict_items.label` Refs: 审查项 ahaodev#7
普通角色改名时既没有用途检查也没有重名检查,唯一索引的约束错误 被 wrap 成普通错误,最终表现为 500;Create 路径有检查,Update 没有。 - usecase 改名时先 ExistsByName,命中返回 ErrRoleNameExists - repository.Update 兜底把约束错误映射为 ErrRoleNameExists(并发改名) - 回归测试:auditor 改名为已存在的 operator 得到 ErrRoleNameExists; 回退修复后该测试复现 `UNIQUE constraint failed: roles.name` Refs: 审查项 ahaodev#8
- 分页:swagger 注释把 page_size 默认值写成 20,实际使用 domain.DefaultPageSize=10;修正 user/loginlog 两处并重新生成 docs - 令牌:.env.example 的 REFRESH_TOKEN_EXPIRY_MINUTE=1440 与代码默认 1800 不一致。258d9a6 有意改为 1800,故以代码为准修正示例文件 - 生成物:backend.md 声称 ent 生成代码已入库,实际 .gitignore 忽略 ent/*;routeTree.gen.ts 被 .gitignore 忽略却已被跟踪(tsc -b 早于 vite 执行,必须存在)。修正两处描述,规则与仓库现状一致 - CI:新增 `git diff --exit-code -- docs` 校验,swagger 注释与实际 文档不同步时直接失败;同时把 swag 固定到 v1.16.6(原为 @latest, 生成器版本漂移会让该校验本身不稳定) Refs: 审查项 P3-4
上一提交引入的 `import React from "react";` 使用双引号且未按 prettier 规则排序,使 `pnpm format:check` 在 dev 上即为红色。 仅调整该行,便于本 PR 的格式门禁通过。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
针对审查结论中的 4 项做最小修复,不改变既有设计。
改动
1. 令牌只保存一处(审查项 #4)
accessToken/refreshToken此前既写 cookie 又写 localStorage。该 cookie 由前端 JS 写入、不带 HttpOnly,JS 可读写 —— 因此不提供任何额外的 XSS 防护,只是把同一份凭证的暴露面翻倍;后端只从Authorization头取令牌,从不读取它。setCookie/getCookieremove*仍清理旧版本遗留的同名 cookie(升级后不会被误读)2. 字典重复 label → 409(审查项 #7)
DictItem上(type_id, label)有唯一索引,但代码只检查了value,重复 label 以 ent 约束错误冒泡成 500。domain.ErrDictItemLabelExists+errorRules一行(409)CreateItem/UpdateItem事务内前置检查 label,更新时排除自身3. 角色改名冲突 → 409(审查项 #8)
Create有重名检查,Update没有;唯一索引错误被 wrap 成普通错误 → 500。ExistsByName,repository.Update兜底映射约束错误4. 生成物与默认值漂移(审查项 P3-4)
page_size默认 20,实际DefaultPageSize=10;修正 user/loginlog 两处并重新生成docs/.env.example的REFRESH_TOKEN_EXPIRY_MINUTE=1440与代码默认 1800 不一致。258d9a6是有意改成 1800,故以代码为准修正示例backend.md称 ent 生成代码已入库(实际被.gitignore忽略);routeTree.gen.ts被忽略却已被跟踪。两处描述改为与仓库现状一致git diff --exit-code -- docs,注释与文档不同步直接失败;swag由@latest固定到v1.16.6(否则生成器漂移会让该校验本身不稳定)main.tsx的 import 格式(dev 上pnpm format:check本就是红的,不修则本 PR 无法通过格式门禁)验证
两个回归测试在回退修复后均复现问题(
UNIQUE constraint failed: dict_items.type_id, dict_items.label/roles.name)。未包含(避免超范围)
审查中的 P0 项(源码内置默认凭据且 prod 不拒绝、启动即
WithDropColumn/WithDropIndex、登录端点无限流、server 缺读写超时与 body 上限)不在本 PR 内——它们涉及行为与配置策略,建议单独讨论。