Repository navigation
登录按邮箱和 IP 计失败、注册按 IP 限频,超了回 429 带 Retry-After - #82
Merged
Merged
Conversation
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Be3SZps2JjqvyrJ1vbLmni
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Be3SZps2JjqvyrJ1vbLmni
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Be3SZps2JjqvyrJ1vbLmni
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Be3SZps2JjqvyrJ1vbLmni
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Be3SZps2JjqvyrJ1vbLmni
joesmart
force-pushed
the
joesmart/sec-auth-ratelimit
branch
from
October 23, 2026 13:53
5d3c953 to
57f89cd
Compare
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.
改了什么
packages/control-plane/src/http/auth-limits.ts:进程内定窗计数器AttemptCounter(键做 sha256 摘要、每个计数器最多一万个键、过期的先丢)和取来源 IP 的clientIp。阈值都是命名常量:同一邮箱 15 分钟失败 5 次、同一 IP 15 分钟失败 200 次、同一 IP 一小时注册 20 次。/api/auth/login:超阈值回 429,带Retry-After和「尝试太多次了,请 N 分钟后再试」。锁定期内密码对了也是 429。登录成功清掉该邮箱的计数,退回这一次的 IP 计数。/api/register:按 IP 限频,超了同样回 429。TRUSTED_PROXY_HOPS=n,才取X-Forwarded-For右数第 n 项。.env.example、docs/开发.md、deploy/README.md都写了;远程 compose 前面有一层 Caddy,默认设成1。为什么这么改
X-Forwarded-For客户端能随便填,默认不信它。测试和验收靠每个控制面实例各有一份计数来避开上限,不给本机开 IP 白名单。怎么验证的
新加的测试:
control-plane/test/auth-rate-limit.test.ts(8 条):到阈值回 429 带 Retry-After;锁定期内正确密码也 429;换邮箱不受影响;同 IP 换邮箱到阈值也 429;成功登录清计数;并发;默认不信 XFF;信一层代理时取最右一项;注册限频。control-plane/test/auth-limits.test.ts(3 条):窗口、退回和清零、键数上限。control-plane/test/env.test.ts:TRUSTED_PROXY_HOPS的解析。web/e2e/01-auth.spec.ts:登录和注册收到 429 时页面显示的提示。Closes #21
🤖 Generated with Claude Code
https://claude.ai/code/session_01Be3SZps2JjqvyrJ1vbLmni