Repository navigation
fix(ui): 收紧会话身份边界——验签后必须匹配当前 USERNAME - #11
Merged
Merged
Conversation
readSession 此前只检查载荷 u 是字符串,没有比对 env.USERNAME:签名只证明 "这份载荷由当前 PASSWORD 派生的密钥签发过",不证明 u 就是当前用户名。 于是改用户名后旧 Cookie 仍然有效(改密码已经会失效,两者应是同一性质)。 - src/ui/session.ts:验签+TTL 通过后追加 payload.u !== env.USERNAME 即拒; 顶部几十行历史方案比较压成当前事实(HKDF/HMAC、24h exp、改用户名/密码失效)。 - test/hardening.test.ts:新增 G8(用户名不变有效 / 仅改 USERNAME 旧令牌失效 / 新用户名签发的令牌有效),并在文件头登记 G8。
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
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.
问题
readSession()验签并解析载荷后,只检查payload.u是不是字符串,没有比对当前env.USERNAME。签名只证明"这份载荷由当前
PASSWORD派生的密钥签发过",不证明u就是当前用户名。于是改用户名后旧 Cookie 仍然有效——而改密码已经会让旧会话整体失效(密钥按口令值派生),两者本应是同一性质。改动
src/ui/session.ts:验签 + TTL 通过后追加payload.u !== env.USERNAME → null;顶部几十行历史方案比较压缩成当前事实(HKDF/HMAC、24h exp、改用户名/密码皆失效)。test/hardening.test.ts:新增 G8 三组判据——用户名不变时旧 token 有效;只改USERNAME后旧 token 立即失效;新用户名签发的 token 有效。不新增 sessionVersion、不建 D1 会话表、不加 revoke 表。
验证
tsc --noEmit0 错;eslint0 告警。env.USERNAME比对去掉,G8 用例转红。test/hardening.test.ts、test/ui-guard.test.ts、test/fixes.test.ts通过。