Skip to content

feat(usercenter): M1 loginByProvider 统一流程 + OAuth state/cookie 硬化 - #44

Merged
longsizhuo merged 1 commit into
feat/user-identities-m0from
feat/user-identities-m1
Jul 19, 2026
Merged

feat(usercenter): M1 loginByProvider 统一流程 + OAuth state/cookie 硬化#44
longsizhuo merged 1 commit into
feat/user-identities-m0from
feat/user-identities-m1

Conversation

@longsizhuo

Copy link
Copy Markdown
Member

RFC #42 / ADR-001 第二阶段。基于 M0(PR #43),合并前需先合 #43

loginByProvider(loginByGithub 委托至此)

M0 只建表不改行为;M1 让登录开始维护 identity。设计遵循 ADR 的双写期语义:

  • 账号仍按 {provider}_{id} 用户名主查(github = github_{id},与历史逐字一致),M3 才翻转到 identity 主查。对现有 8 个 loginByGithub 测试零逻辑扰动。
  • identity 双写:新建/已存在都维护一行 user_identities;缺行惰性补齐(自愈),兜住 M0-M1 窗口内注册、启动回填尚未覆盖的账号。
  • 写失败不阻断登录:identity 写入异常仅记日志,与 INV-003 lazy upgrade 同策略——绝不让第二真相源的写入把用户挡在门外。
  • github_id 列双写沿用(createUser/updateProfile 本就写该列)。

OAuth state/cookie 硬化(INV-007,修登录 CSRF)

Review 指出登录 CSRF 现状就存在、该在 M1 修:

  • renderih_oauth_state cookie(httpOnly + SameSite=Lax + Secure 随 https)。
  • callback 在换 token 之前校验 URL state == cookie,缺失/不匹配即拒(error=oauth_state),不给伪造 state 触发登录的机会,也不白打 GitHub。
  • callback 端点保持 github 专用——泛化 AuthRequest 工厂需要还不存在的其它 provider 配置,留到 M3 真接 Discord(YAGNI)。泛化的是数据层 loginByProvider

新增 INV-007 进 SECURITY.md(INV-006 已被限流占用,按流水规则顺延);含"callback 不得信任 state 中用户身份"的完整理由,M2 绑定流程复用同一防线。

验证

  • 全量 257 测试通过(+5:identity 双写 3 + OAuth cookie 3 − 替换旧失败路径 1)。
  • 生产数据核查(只读):51 个 github 账号 全部符合 username = github_{github_id},0 例外——M1 用户名主查不会漏查建重复号;0 个"前缀对但缺 id"。
  • 新增测试:新用户插 identity / 已有 identity 只刷 last_login / identity 写失败不阻断登录 / render 种 cookie / 无 cookie 拒绝 / cookie 匹配放行。

🤖 Generated with Claude Code

https://claude.ai/code/session_01RtSNVtrEkCsFVHrbt4Zjgi

CopilotAI review requested due to automatic review settings July 19, 2026 09:35

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

RFC #42 / ADR-001 第二阶段。
loginByProvider(loginByGithub 委托至此):
- 账号仍按 "{provider}_{id}" 用户名主查(双写期,M3 才翻转到 identity 主查)
- 无论新建/已存在都维护一行 user_identities(identity 双写),缺行惰性补齐,
兜住 M0-M1 窗口回填未覆盖的账号;identity 写失败不阻断登录(同 INV-003 策略)
- github_id 列双写沿用(createUser/updateProfile 已写)
OAuth state/cookie 硬化(INV-007,登录 CSRF):
- render 种 httpOnly + SameSite=Lax 的 ih_oauth_state cookie
- callback 在换 token 前校验 URL state == cookie,缺失/不匹配即拒(error=oauth_state)
- callback 端点保持 github 专用(泛化 AuthRequest 工厂留到 M3 真接第二个 provider)
新增 INV-007 进 SECURITY.md(INV-006 已被限流占用,按流水规则顺延)。
全量 257 测试通过;生产数据核查:51 个 github 账号 username 约定 0 例外。
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

@longsizhuo