Skip to content

feat: replace temp password with HMAC invite links & protect owner role - #79

Merged
RyanLee-Dev merged 2 commits into
mainfrom
worktree-analyze-auth-invite
Jul 9, 2026
Merged

feat: replace temp password with HMAC invite links & protect owner role#79
RyanLee-Dev merged 2 commits into
mainfrom
worktree-analyze-auth-invite

Conversation

@RyanLee-Dev

Copy link
Copy Markdown
Collaborator

概述

用 HMAC 签名邀请链接替换临时密码机制,同时保护 owner 角色不可被编辑/移除。

邀请链接

  • Admin 创建邀请 → 拿到链接 → IM 分发
  • 被邀请人打开链接 → 自行设置密码 → 自动加入 workspace
  • Token: base64url(payload).base64url(hmac-sha256),DB 存 SHA-256 哈希
  • CAS 单次消费,72h TTL
  • 公开 accept 端点限流 10 req/min/IP
  • Token 走 POST body,避免代理日志泄露

Owner 保护

  • 后端:禁止编辑/移除 owner 角色,禁止提升为 owner(403)
  • 前端:owner 行隐藏角色下拉和移除按钮
  • Ownership 变更需要独立的转让操作(后续实现)

改动文件

区域 文件 说明
Migration 000007_workspace_invitations.sql workspace_invitations 表
后端 auth/invite/invite.go HMAC token 签发/验证
后端 store/store.go AcceptInvitation 事务、CRUD
后端 dev/routes.go 5 个新 handler + owner 保护
前端 api-invitations.ts API hooks
前端 InviteAcceptPage.tsx 邀请接受页
前端 MembersPage.tsx 邀请链接 UI + owner 保护
删除 auth/password/temp.go 临时密码生成(废弃)

🤖 Generated with Claude Code

RyanLee-Dev and others added 2 commits July 9, 2026 13:27
- Replace temp-password invitation with HMAC-SHA256 signed invite links
- Admin creates invitation → gets a link → shares via IM
- Invitee opens link → sets own password → auto-joins workspace
- Token: base64url(payload).base64url(hmac), SHA-256 hash stored in DB
- CAS pattern for single-use acceptance, 72h TTL
- Rate limit on public accept endpoint (10 req/min/IP)
- Token passed via POST body to avoid proxy log leakage
- Set workspace ID in localStorage on accept for correct routing
- Protect owner: cannot edit/remove owner role, cannot promote to owner
- Owner role dropdown hidden in UI, remove button hidden for owner
- Delete temp password generation code

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@RyanLee-Dev
RyanLee-Dev merged commit 17bf1e5 into main Jul 9, 2026
7 checks passed
Sign up for free to 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.

1 participant