Skip to content

Commit 8d7ce49

Browse files
鲁工鲁工
authored andcommitted
fix: keep pre-1.8.3 gateways stoppable and classify client aborts by signal
Two regressions in the unreleased 1.8.3 hardening: 1. `ccmr stop` required a local identity record that pre-1.8.3 gateways never wrote, while `ccmr claude` refused to reuse them - circular guidance with manual `kill` as the only exit. Gateways that do not advertise an instance_id now keep the 1.8.2 trust level (self-reported pid via /health); the strict identity check applies only to gateways that opted in by advertising one. 2. abort(reason) rejects fetch with the caller's reason, whose name is not 'AbortError', so a client disconnect was classified as a retryable connection error: it logged failover attempts and polluted /usage error counters. Aborts are now classified by the signal and never trigger failover or error accounting. Adds first direct coverage of the default identity-verification path (write/read roundtrip, legacy trust, unmatched instance_id).
1 parent 13bfbf9 commit 8d7ce49

14 files changed

Lines changed: 305 additions & 51 deletions

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ claude
104104

105105
复用网关前会比较配置路径、路由内容、`.env` 来源及 API Key 的不可逆摘要。若端口上的网关来自另一个项目,`ccmr claude` 会拒绝复用并提示换端口或先停止旧网关,避免提示词发往错误的供应商账号。
106106

107-
> `ccmr stop` 会同时校验 `/health` 身份和 `~/.ccmr/gateway-<port>.identity.json` 中的本机随机身份记录,匹配后才会发送信号。只伪造 HTTP 响应不能诱导它停止任意 PID。
107+
> `ccmr stop` 会同时校验 `/health` 身份和 `~/.ccmr/gateway-<port>.identity.json` 中的本机随机身份记录,匹配后才会发送信号。只伪造 HTTP 响应不能诱导它停止任意 PID。由 v1.8.2 及更早版本启动的旧网关没有身份记录,沿用其 `/health` 自报 PID 停止,升级后仍可正常回收。
108108
109109
> **安全提示**:网关默认绑定到 `127.0.0.1`(仅本机可访问)。网关会用你本地配置的各厂商 API Key 代理上游请求,因此任何能访问该端口的人都能消耗你的额度。
110110
> 若确需通过 `--host 0.0.0.0` 暴露到局域网,必须设置环境变量 `CCMR_REQUIRED_AUTH_TOKEN`,此时调用方需在 `x-api-key``Authorization: Bearer <token>` 中携带该令牌。未设置时网关默认拒绝启动;仅在已隔离且明确接受风险时使用 `--allow-insecure-network`。远程未认证的 `/health` 只返回基础存活信息,不暴露 PID、路径或 Key 状态。
@@ -475,10 +475,10 @@ DeepSeek Anthropic 兼容接口会忽略 `metadata` 字段,但某些 Claude Co
475475
### v1.8.3
476476

477477
- 阻止 detached 网关跨项目复用错误的配置、端点或 API Key
478-
- 流式转发改用增量 UTF-8 解码,兼容 CRLF SSE;客户端断开会取消上游请求并处理背压
478+
- 流式转发改用增量 UTF-8 解码,兼容 CRLF SSE;客户端断开会取消上游请求并处理背压,且不再误判为连接错误而触发 failover 或污染用量统计
479479
- `.env` 删除 Key 后会真正撤销,入站鉴权支持热轮换;内置客户端统一使用相同令牌
480480
- 非回环无鉴权监听改为默认拒绝,远程 `/health` 隐藏本机路径、PID 与 Key 状态
481-
- `ccmr stop` 增加本机随机身份记录校验,不再只信任 HTTP 自报 PID
481+
- `ccmr stop` 增加本机随机身份记录校验,不再只信任 HTTP 自报 PID(旧版网关没有身份记录,沿用原停止方式,升级后仍可回收)
482482
- 显式配置路径、YAML、端口、超时和 CLI 数值参数改为严格校验;YAML/env/CLI 优先级保持一致
483483
- 实现兼容 `/v1/messages/count_tokens` 转发,并执行 streaming/tools 能力声明
484484
- 修复流式断连继续计费、生产依赖漏洞和缺失 LICENSE;CI/发布前新增依赖审计

dist/cli.js

Lines changed: 18 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/cli.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/gateway-control.d.ts.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/gateway-control.js

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/gateway-control.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)