Repository navigation
fix(security): 认证限速只剩 IP 维度(删掉无消费端的 username 维度) - #12
Merged
Merged
Conversation
此前用户名维度与 IP 维度一样能单独触发封锁,于是攻击者只要知道真实用户名、 换着 IP 连猜,就能把合法用户从**全球所有 IP** 锁 15 分钟(限速是削峰控制, 不是鉴权边界)。 三信号模型: - ip:<ip> 可硬封锁 - pair:<ip>:<user> 可硬封锁(凭据攻击的精确形态) - user:<user> 只统计/告警,绝不单独封锁 Worker 与 DO 两侧共用 isHardBlockKey 前缀白名单(新增信号默认不封锁)。 验收:固定 IP+固定用户 429;固定 IP 换用户仍 429(ip 桶);换 IP 固定用户 不产生全局硬锁且合法用户仍可登录;无 cf-connecting-ip 不封锁。 - src/rateLimit.ts:新增 pair 键、authLimitPairKey、isHardBlockKey; checkAuthRateLimit 与 mergeBlocks 只认可硬封锁的键。 - src/durable/SyncClipboardHub.ts:blocks 只上报 ip/pair; connectionAuthFailure 预检同判据。 - test/rate-limit.test.ts:键模型单测(成员与可封锁性)。 - test/hardening.test.ts:重写归因制用例为三信号四条判据(含换 IP 不锁死人)。 - README:安全说明与排障条目更新为三信号口径。
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
评审反馈:#12 的 pair 桶与 IP 桶用同一套阈值 ⇒ 永远不可能早于 IP 生效,只增加 Map/persist/prune 开销;且它在 key 循环里 countBurst,让一次失败 burst +3, AUTH_RATE_LIMIT_BURST_WARN=50 约 17 个请求就触顶。 - 删 pair 键与 authLimitPairKey;HARD_BLOCK_PREFIXES 只剩 ip。 - DO report:countBurst 移出 key 循环,每个失败请求只 +1。 - test/rate-limit:键模型改为 ip/user 两键;新增 burst 按请求计一次用例(判别力实测)。 - test/hardening:三信号 → 两信号(去掉 pair 提及)。 - README:安全说明与排障条目按两信号口径改写。
评审反馈:user:<username> 没有真正的消费端 —— 不封锁、无单列告警、不返回 Worker、 不进 UI/诊断 API(现有 burst 告警是 global)。它只增加 Map entry、DO 持久化、prune 与测试/文档成本,安全性没有提升。 - 删 authLimitUserKey、user 键、isHardBlockKey/HARD_BLOCK_PREFIXES(白名单里只剩 ip, 两个过滤点都成了恒真)。 - checkAuthRateLimit / noteAuthFailure / noteAuthSuccess / authLimitKeys 去掉 username 参数。 - basicAuthUsername(仅为此维度而导出)删除;index.ts 的 login 中间件不再读 body 取用户名 (连带删掉 readUsername 与那次 clone+读体)。 - 模型收敛为:IP hard block + global burst warning。 - 测试:键模型只测 ip;hardening 四条判据改为「只有 ip 可封锁」;burst 用例保留(多键只 +1)。 - README:安全说明与排障条目改为 IP-only 口径。 验证:tsc 0、eslint 0;全量 22/22·501 通过。
评审反馈:burst 的注释仍写着'一次失败通常有 ip + user 两个键',但模型已只剩 IP。 改成当前事实:burst 按一次失败报告计一次,与报告里携带多少 key 无关。 (保留该测试:内部接口仍接受 keys[],它防止 countBurst 被塞回 key 循环。) 另修 rate-limit.test.ts 的两处'用户名维度唯一'旧措辞。
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.
问题
原实现按
ip/pair/user三个维度计数并(部分)封锁。两轮评审后收敛:pair(来源+账户)与 IP 桶用同一套阈值 ⇒ 永远不可能早于 IP 生效,只增加 Map/持久化/prune 开销(已删)。user桶没有真正的消费端 —— 不封锁、无单列告警、不返回 Worker、不进 UI/诊断 API(现有 burst 告警是 global)。而已知真实用户名后换 IP 猜同一账户,本就无法安全地按用户名封锁(会把合法用户从所有 IP 锁死)。改动:只有 IP 维度
ip:<cf-connecting-ip>authLimitUserKey、pair键、isHardBlockKey/HARD_BLOCK_PREFIXES(白名单只剩 ip,过滤点恒真)。checkAuthRateLimit/noteAuthFailure/noteAuthSuccess/authLimitKeys去掉username参数。basicAuthUsername(仅为此维度而导出);index.ts的 login 中间件不再读 body 取用户名。未引入滑动窗口 / token bucket / 指数退避 / Captcha / 第三方 KV。
验证
tsc0 错;eslint0 告警;全量 22/22·501 通过。cf-connecting-ip→ 不封锁;burst 多键只 +1。