Skip to content

fix: 避免绑定令牌重复#191

Merged
he0119 merged 5 commits into
mainfrom
codex/secure-bind-token
May 25, 2026
Merged

fix: 避免绑定令牌重复#191
he0119 merged 5 commits into
mainfrom
codex/secure-bind-token

Conversation

@he0119
Copy link
Copy Markdown
Owner

@he0119 he0119 commented May 25, 2026

变更内容

  • 将绑定令牌生成从 random.randint 切换为 secrets.randbelow
  • 生成绑定令牌时跳过仍在有效期内的已有 token,避免碰撞时覆盖旧绑定上下文。
  • 为重复 token 场景补充测试,并在测试夹具中清理全局 token 缓存,避免用例之间互相影响。
  • CHANGELOG.mdUnreleased 中记录本次修复。

影响范围

  • 用户侧 /bind 流程和 6 位数字令牌格式不变。
  • 令牌碰撞时会重新生成,避免旧 token 被新绑定流程覆盖。
  • 极端情况下连续生成重复 token 会抛出明确错误,避免无限循环。

验证

  • uv run ruff check
  • uv run ruff format --check
  • uv run pytest tests/test_bind_private.py tests/test_bind_group.py

备注:AGENTS.md 编码指南已经在当前分支基线中,包含 nb orm CLI 迁移约定。

@codecov
Copy link
Copy Markdown

codecov Bot commented May 25, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (79cf94f) to head (7105daf).
⚠️ Report is 1 commits behind head on main.
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff            @@
##              main      #191   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            7         7           
  Lines          238       242    +4     
=========================================
+ Hits           238       242    +4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@he0119 he0119 added the change label May 25, 2026
@he0119 he0119 changed the title [codex] 使用安全随机生成绑定令牌 fix: 使用安全随机生成绑定令牌 May 25, 2026
@he0119 he0119 force-pushed the codex/secure-bind-token branch from 569c312 to 691ade5 Compare May 25, 2026 08:58
@he0119 he0119 marked this pull request as ready for review May 25, 2026 08:59
@he0119 he0119 changed the title fix: 使用安全随机生成绑定令牌 fix: 避免绑定令牌重复 May 25, 2026
@he0119 he0119 marked this pull request as draft May 25, 2026 08:59
@he0119 he0119 added bug Something isn't working and removed change labels May 25, 2026
@he0119 he0119 marked this pull request as ready for review May 25, 2026 09:28
@he0119 he0119 marked this pull request as draft May 25, 2026 09:34
@he0119 he0119 marked this pull request as ready for review May 25, 2026 09:41
@he0119 he0119 merged commit 6e92cff into main May 25, 2026
22 checks passed
@he0119 he0119 deleted the codex/secure-bind-token branch May 25, 2026 09:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant