fix(auth): role claims, expiring demo tokens and visible demo-auth fallback - #13
Merged
Merged
Conversation
|
Warning Review limit reachedNext included review available in 58 minutes. View limit detailsLimit details: You’ve used the included review currently available. You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Review configuration: ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (15)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Deploying umi-react-admin with
|
| Latest commit: |
f82b4d7
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://90509491.umi-react-admin.pages.dev |
| Branch Preview URL: | https://fix-auth-hardening.umi-react-admin.pages.dev |
…llback - access.ts switches to allowlist: canSeeAdmin requires role==='admin' from the issuer (demo token payload or real backend), instead of a username blacklist that made every logged-in user an admin - demo tokens are now self-describing payloads (name, role, ts) with a 7-day TTL and clock-rollback guard, shared by services/auth.ts and mock/userAPI.ts via demo/demoToken.ts; the mock file now carries a do-not-port-to-production warning since its token convention is a universal credential if copied into a real backend - production builds without UMI_APP_API_BASE now print an unmissable banner that the auth is a demo stub (visible fail-open, no hard build failure to keep the clone-and-build experience) - 401 now does a full-page redirect (resets in-memory initialState, avoids duplicate pushes on concurrent 401s), PUBLIC_PATH-aware - login surfaces localStorage failures instead of swallowing them behind the empty catch; locales gain login.storageError - demo userService validates stored JSON shape and falls back to the static seed when localStorage is corrupted - typings: CESIUM_ION_TOKEN / UMI_APP_API_BASE are string | undefined (they are optional define injections) verified headless against a static build: guard redirect, admin login and table access, logout, and dontHaveAccess landing on 403 with the admin menu entries filtered out
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.
背景
审计 2026-09-22 H-4 + M-1 + M-2 + L-2/L-5/L-8。09-20 审计后鉴权链的形式完整性已修复,本轮把剩余风险从「文档声明」升级为「机制性防线」:
UMI_APP_API_BASE时静默落入任意凭证放行(fail-open 不可见)canSeeAdmin用用户名黑名单——接真实后端后任何用户登录即 admin,CurrentUser无角色接入点${name}-demo-token可预测、永不过期;mock 实现形似现成后端参考代码,搬进真实后端即成万能凭证改动
CurrentUser/UserInfo增加role,canSeeAdmin = initialState?.role === 'admin';注释明示真实后端必须由服务端返回角色声明demo/demoToken.ts,auth 与 mock 共用):明文 JSON 载荷{name, role, ts}+ 7 天过期 + 时钟回拨防御;mock 文件头加「禁止搬进真实后端」警告window.location.assign):重置内存中残留的 initialState,避免并发 401 重复 push;PUBLIC_PATH兼容子路径login.storageError)typings.d.ts:CESIUM_ION_TOKEN/UMI_APP_API_BASE改为string | undefined(诚实类型)验证(headless 浏览器,静态构建)
完整权限链路实测:未登录守卫重定向 → admin 登录 +
/table可访问 → 登出回登录页 → dontHaveAccess(role=user)登录后访问 /table 落 403 且管理菜单项被过滤;零 console 错误。pnpm check53 用例全绿(含过期/伪造/未来时间戳 token 拒绝用例)。破坏性说明
演示 token 形状变更会让已登录的旧会话失效(旧
-demo-token形状不再被接受)——对演示站点是预期行为(重新登录即可)。canSeeAdmin语义变严:未返回 role 的真实后端接入者会全部失去 admin——这是有意为之(白名单式),README/SECURITY.md 已声明接入要求。