Repository navigation
fix(email): preserve legacy verification attempt budgets - #7920
Open
MrCrazyLeo wants to merge 2 commits into
Open
MrCrazyLeo wants to merge 2 commits into
MrCrazyLeo wants to merge 2 commits into
Conversation
Contributor
|
All contributors have signed the CLA. ✅ |
Author
|
I have read the CLA Document and I hereby sign the CLA |
riofutab
added a commit
to riofutab/sub2api
that referenced
this pull request
Oct 9, 2026
- 合入上游 Wei-Shaw#7920:升级前生成的验证码把已消耗的尝试次数继承到独立计数器,不再多给猜测机会 测试:随整合分支统一验证(unit 全量、golangci-lint、前端检查)。
riofutab
added a commit
to riofutab/sub2api
that referenced
this pull request
Oct 9, 2026
- 合入上游已合并的 Wei-Shaw#7618:平台改为数据驱动,接入 Command Code 与 Cline,Go 升级到 1.27.2,golangci-lint 升级到 v2.14.0。 - 合入开放 PR Wei-Shaw#7920 Wei-Shaw#7924 Wei-Shaw#7928 Wei-Shaw#7930 Wei-Shaw#7931 Wei-Shaw#7933 Wei-Shaw#7935 Wei-Shaw#7936 Wei-Shaw#7939 Wei-Shaw#7941 Wei-Shaw#7947 Wei-Shaw#7951 Wei-Shaw#7954 Wei-Shaw#7956 Wei-Shaw#7960。 - 新增 Decisions 决策接口(Wei-Shaw#7922)及其与 TypeSafe System One 的双向互转(Wei-Shaw#7948),上游 404 时切换账号。 - Haiku 5.5 的 top_p 违规请求在网关直接拒绝,OAuth 伪装不再在 top_p 旁补 temperature,工具集 beta 过滤覆盖 Haiku 5.5。 - 修正新增代码的静态检查告警。 全量 unit 测试、golangci-lint、前端全量 vitest 均已通过;集成测试本机无 Docker,待 CI 验证。
…fication-attempts
Author
This was referenced Oct 21, 2026
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.
问题与触发条件
本 PR 修复 #7676 引入独立验证码计数器后,对升级前已有 Redis 数据的兼容缺口:旧验证码已消耗的尝试次数没有被继承到独立计数器,导致仍有效的旧验证码获得额外猜测机会。
触发条件:
Attempts字段中。:attempts独立计数器不存在,或其值落后于 JSON 中的次数。例如,JSON 中已有
Attempts: 4、独立计数器不存在时,修复前的INCR从 0 递增到 1,第五次错误输入没有耗尽既有的五次尝试额度。修复后先继承 4,再递增到 5,该次错误输入立即返回ErrVerifyCodeMaxAttempts;随后即使输入正确验证码,也会因额度已耗尽而被拒绝。根因
#7676 将验证码尝试次数改为独立 Redis key,以支持原子递增。读取验证码的
getCode已取 JSON 与独立计数器的较大值,但旧版incrAttemptsScript仅检查验证码 key 是否存在,然后直接递增独立计数器,没有继承旧 JSON 的Attempts。因此,读取到的历史次数与递增返回的次数可能不一致;业务层用于本次额度判断的递增结果会落后于升级前已经消耗的次数。
改动范围
本 PR 共 1 个提交、2 个文件,新增 139 行、删除 5 行。生产代码仅修改共享的计数 Lua 脚本,其余为回归测试。
backend/internal/repository/email_cache.goincrAttemptsScript对旧 JSON 次数的继承,并保留验证码剩余 TTLbackend/internal/repository/email_cache_atomic_test.goLua 脚本在同一次原子操作中完成:
PTTL,对不存在或剩余 TTL 为 0 的验证码返回失效结果。Attempts和独立计数器,以两者较大值为基础递增;已有独立计数器领先时,不将其回退到旧 JSON 的较小值。计数规则为
max(legacy Attempts, separate counter) + 1,例如:以上是缓存递增行为;业务校验仍会在读取到已达上限的次数时提前拒绝,不代表允许超过五次进行验证码比较。
影响范围与行为边界
两类验证码共用
incrCodeAttempts和此次修改的 Lua 脚本:verify_code:<email>及其:attemptskeyEmailService.VerifyCode→verifyCodeWithAttempts→IncrVerificationCodeAttemptsnotify_verify:<email>及其:attemptskeyUserService.VerifyAndAddNotifyEmail→verifyNotifyCode→verifyCodeWithAttempts→IncrNotifyVerifyCodeAttemptssetCode清理旧计数器的行为,新验证码重新开始计数。回归测试
新增 3 个顶层测试:
TestEmailCacheLegacyAttemptCountAndRemainingTTLTestEmailCacheLegacyCodeStillStopsAtFifthWrongAttemptTestEmailCacheLegacyAttemptsConcurrentAndResend同一测试文件内已有的并发尝试上限、新验证码计数重置、密码重置 token 哈希存储和一次性消费测试也包含在下面的定向命令中。
验证结果与未覆盖项
提交前已完成的验证(沿用原 PR 的验证记录):
go test -mod=readonly -tags=unit ./internal/repository -run TestEmailCache -count=1:7 个顶层测试和 14 个子测试通过。gofmt和git diff --check通过。证据边界:上述缓存测试使用 miniredis,业务上限测试调用真实 service 校验逻辑;不等同于真实 Redis 集成、HTTP/浏览器端到端、生产部署或新旧节点同时处理同一验证码的完整滚动升级验收。本次正文更新没有重新执行测试,也没有修改代码提交。
CLA 已签署,原失败的
cla-check重跑后通过。当前 CI 与 Security Scan 仍等待上游维护者批准运行,尚无这两项工作流的测试结果;后续全量测试、lint 和安全扫描结果以 GitHub 工作流为准。