fix: 邮件 token 改用 UUID,避免 base32 填充被邮件链路破坏#523
Merged
yokowu merged 1 commit intochaitin:mainfrom Apr 17, 2026
Merged
Conversation
问题:
邮箱绑定 / 重置密码 token 由 crypto.Simple 生成,为 base32 编码
且必然以 6 个 `=` 填充结尾。邮件经过 MTA、quoted-printable
归一化或链接重写器时,末尾 `=` 会被吃掉,导致 base32 解码在
byte 82 报错 "illegal base32 data at input byte 82",用户无法
完成邮箱绑定(100% 复现)。
方案:
将 token 改为 uuid.NewString():字符集仅 [0-9a-f-],URL 安全,
长度 36,没有 padding;熵 122 bit 反而高于原 5 字节随机。过期
由 Redis TTL 控制。
改动:
- biz/user/usecase/user.go
SendBindEmailVerification / VerifyBindEmail:
Redis key 由 bind_email_token:{userID} 改为 bind_email_token:{token},
value 由 {token}:{email} 改为 {userID}:{email},
去掉 ValidateSimple 及冗余的 storedToken 比对。
- biz/team/usecase/user.go
generateResetPWDToken 内部改为 uuid.NewString(),签名保持不变
以最小化调用方改动(verify 侧 auth.go 无需修改)。
注意:
语义变化——原实现 key 为 {userID},同用户多次请求只有最新 token
有效;新实现下多次请求的 token 并存有效(均受 24h TTL 控制)。
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.
问题:
邮箱绑定 / 重置密码 token 由 crypto.Simple 生成,为 base32 编码
且必然以 6 个
=填充结尾。邮件经过 MTA、quoted-printable归一化或链接重写器时,末尾
=会被吃掉,导致 base32 解码在byte 82 报错 "illegal base32 data at input byte 82",用户无法
完成邮箱绑定(100% 复现)。
方案:
将 token 改为 uuid.NewString():字符集仅 [0-9a-f-],URL 安全,
长度 36,没有 padding;熵 122 bit 反而高于原 5 字节随机。过期
由 Redis TTL 控制。
改动:
注意:
语义变化——原实现 key 为 {userID},同用户多次请求只有最新 token
有效;新实现下多次请求的 token 并存有效(均受 24h TTL 控制)。