feat(captcha)!: 加固验证码场景绑定与原子消费 - #133
Open
zzswang wants to merge 2 commits into
Open
Conversation
Add server-generated issuance keys, scoped verification, attempt limits and Redis rolling quotas. Consume challenges atomically and expose answers only in issuance responses while retaining plaintext database storage. Keep SMS and email records metadata-only, remove sensitive logs, and add migration tooling, integration coverage, API documentation and SDK checks. BREAKING CHANGE: captcha creation and verification require kind, purpose and subject. Verification consumes the challenge, DELETE uses the issuance key, and PATCH is removed. Callers and auth must migrate together and invalidate legacy challenges.
1 task
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.
验证码此前只校验 key 与答案,缺少账号和用途绑定,并发消费可能重复成功。本次将图形、短信和邮箱验证码统一绑定
kind、purpose、subject,通过 MongoDB 原子消费和 Redis 滚动限流限制重放及暴力尝试。这个 PR 完成了:
429 + Retry-After,依赖故障返回503。@loginByCode和@registerByCode,通过channel=sms/email和account统一验证码登录与注册。原有四个byPhone / byEmail接口保持兼容,与新入口共用内部流程。@registerByCode支持可选密码,校验通过后复用现有密码哈希与更新时间逻辑;注册返回 User,之后可用手机号或邮箱加密码登录。旧注册入口不增加密码字段。CAPTCHA_HMAC_SECRET。.npmrc时的 SDK 生成问题,CI 增加安全测试与 SDK 类型检查。发布建议
kind、purpose、subject;@verifyCaptcha成功即消费;删除接口传签发 key;移除 PATCH。图形验证码应在对应业务操作中消费。CAPTCHA_POLICY_JSON和CAPTCHA_REDIS_PREFIX可省略,使用服务端默认值;各实例保持相同策略和 Redis 前缀。原CAPTCHA_EXPIRES_IN_S、CAPTCHA_CODE_LENGTH不再使用。pnpm migrate:captcha-security只读统计;切换窗口暂停验证码及相关发送入口、停止旧实例写入后,执行CAPTCHA_MAINTENANCE_MODE=true pnpm migrate:captcha-security --execute,再部署新版本与调用方。params和邮件subject/content,建立新的唯一索引及 TTL 索引;脚本可重复执行。生产迁移尚未执行。验证
相关资料