Skip to content

feat(worker): 每账号频道配额+创建限速 + 每频道 WS 连接上限,堵账单攻击面(#137 成本滥用)#327

Merged
leeguooooo merged 1 commit into
mainfrom
feat/account-channel-quota-137
Jul 11, 2026
Merged

feat(worker): 每账号频道配额+创建限速 + 每频道 WS 连接上限,堵账单攻击面(#137 成本滥用)#327
leeguooooo merged 1 commit into
mainfrom
feat/account-channel-quota-137

Conversation

@leeguooooo

Copy link
Copy Markdown
Owner

补什么(#137 成本滥用,dimension 3)

POST /api/channels 无每账号配额/创建限速——每频道一个 Durable Object,任一 ap_ token 可无限造 DO + D1 行(面向跨公司外部 agent 发 token 的产品,真实账单攻击面)。DO 内也无每频道 WS 连接上限。

做了(真熔断,仿既有限速/队列上限手法)

  • 每账号频道配额:owned 频道数硬上限 MAX_CHANNELS_PER_ACCOUNT(超 → quota_exceeded/403),按 owner_account 从 D1 计数。
  • 创建限速:滚动窗 MAX_CHANNEL_CREATES_PER_WINDOW/小时(超 → rate_limited/429)。
  • legacy fail-open:无账号 token(account==null)不计入、不受限(与建表处 owner_account=null 过渡口径一致)。
  • 每频道 WS 连接上限:do.ts onConnect 排除刚接入的自己后计存活连接,>= maxConnectionsPerChannel()(缺省 MAX_CONNECTIONS_PER_CHANNEL、worker env 可覆盖调参)则拒新连接。
  • 默认宽松,单团队正常用不会撞;文档在常量注释。

门禁(对 origin HEAD rebase 后亲验)

  • worker account-channel-quota 5/5;worker tsc 0;rebase 无冲突。
  • 变异:配额检查短路(false &&)→ 超额建频道测试红。复绿。

🤖 opus agent 实现、收尾截断我接管(审+提交+复验)。

POST /api/channels 无配额——每频道一个 DO,任一 ap_ token 可无限造 DO+D1 行(账单攻击面)。
加:owned 频道数硬上限(MAX_CHANNELS_PER_ACCOUNT,quota_exceeded/403)+ 滚动窗创建限速
(MAX_CHANNEL_CREATES_PER_WINDOW,rate_limited/429),按 owner_account 计;legacy 无账号
token fail-open 不受限。do.ts onConnect 加每频道 WS 连接上限。默认宽松,单团队不会撞。
@leeguooooo leeguooooo merged commit 85569e2 into main Jul 11, 2026
18 checks passed
@leeguooooo leeguooooo deleted the feat/account-channel-quota-137 branch July 11, 2026 15:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant