Repository navigation
Conversation
… smuggling
The gateway extracts the billing/admission model with gjson, which binds
the FIRST occurrence of a duplicated top-level "model" key, while the
conversion paths (encoding/json) and upstream runtimes bind the LAST one.
A body such as {"model":"cheap",...,"model":"expensive"} therefore passes
admission checks and is billed for the cheap model while the expensive
model is what actually executes upstream. The model-mapping rewrite
(sjson) only touches the first key, so the smuggled key survives mapping
too. Verified end-to-end on a live deployment: the executed model always
follows the last key while usage attribution follows the first.
Reject requests whose body contains more than one top-level "model" key
at every forwarding ingress (chat completions x2, responses, OpenAI
compatible messages x2, native Anthropic messages, embeddings), and make
ReplaceModelInBody collapse duplicate keys (keeping the last key in place
and the surrounding field order) so any path that still carries
duplicates cannot smuggle a model past the mapping rewrite. Remaining
non-forwarding endpoints (count-tokens, alpha search, realtime WS
passthrough) can adopt the same check as follow-ups.
(cherry picked from commit c461b1c)
riofutab
added a commit
to riofutab/sub2api
that referenced
this pull request
Oct 9, 2026
- 合入上游 Wei-Shaw#7951 第二个提交的入口覆盖意图,改写为复用本仓 Wei-Shaw#7909 实现,不引入第二套检测 - 重复键检测从 service 移到 pkg/requestmodel(零拷贝、大小写不敏感),新增 ValidateBody 统一检查顶层 model 与 Live 的 session、session.model,multipart 只看非文件字段 - 分组白名单中间件在白名单关闭时也检查模型载体歧义,在合成路由改写与调度前返回 400;同值重复也拒绝 - Alpha Search、图片 multipart、Live 创建(JSON 与 multipart)增加重复载体校验 - 本仓修正:Live 校验使用原始 Content-Type,避免小写化后 multipart boundary 不匹配导致检查被静默跳过 测试:requestmodel、middleware、routes 包 unit 测试与 service、handler 相关定向 unit 测试通过,go vet 通过;未跑 golangci-lint 与全量测试。
riofutab
added a commit
to riofutab/sub2api
that referenced
this pull request
Oct 9, 2026
- 合入上游已合并的 Wei-Shaw#7618:平台改为数据驱动,接入 Command Code 与 Cline,Go 升级到 1.27.2,golangci-lint 升级到 v2.14.0。 - 合入开放 PR Wei-Shaw#7920 Wei-Shaw#7924 Wei-Shaw#7928 Wei-Shaw#7930 Wei-Shaw#7931 Wei-Shaw#7933 Wei-Shaw#7935 Wei-Shaw#7936 Wei-Shaw#7939 Wei-Shaw#7941 Wei-Shaw#7947 Wei-Shaw#7951 Wei-Shaw#7954 Wei-Shaw#7956 Wei-Shaw#7960。 - 新增 Decisions 决策接口(Wei-Shaw#7922)及其与 TypeSafe System One 的双向互转(Wei-Shaw#7948),上游 404 时切换账号。 - Haiku 5.5 的 top_p 违规请求在网关直接拒绝,OAuth 伪装不再在 top_p 旁补 temperature,工具集 beta 过滤覆盖 Haiku 5.5。 - 修正新增代码的静态检查告警。 全量 unit 测试、golangci-lint、前端全量 vitest 均已通过;集成测试本机无 Docker,待 CI 验证。
This was referenced Oct 21, 2026
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.
Alpha Search、Images 和 Live 创建请求也会先读取模型做准入/路由,再把正文交给另一层解析器。补齐这些入口的模型载体检查:重复
model、重复session或 Live 的重复session.model在 Composite 改写、调度和计费前返回400 invalid_request_error;关闭模型白名单时同样生效。与 #7909 的关系
这是 #7909 的补充。该 PR 尚未合入 main,所以本分支从当前上游 main
5fc0e486c3f6a8a191b8bd140f39b60457f611cf出发,包含两个独立提交:f3f4f485ee4fc258da189b1f24232fa58600c1fc:通过cherry-pick -x保留 fix(gateway): 拒绝重复 model 键,阻断解析歧义导致的模型走私 #7909 原作者补丁,来源为c461b1c20a5fea1a5866b559049aced9357feb44。行为
pkg/requestmodel,原 fix(gateway): 拒绝重复 model 键,阻断解析歧义导致的模型走私 #7909 的入口复用它;比较解码后的键名,涵盖大小写和 Unicode 转义,同值/null 重复同样拒绝。PrereadBody回填,确保 Composite 路由改写前拒绝。直接 handler/解析器调用也有对应保护。ReplaceModelInBody用固定次数线性扫描收敛重复模型键,保留末键位置、其他字段顺序和大整数,避免重复 Delete 在大量同名字段下反复扫描。变更仅涉及上游网关代码与测试,无配置或数据库迁移。
验证
以下命令均在 backend 执行并通过;网关测试使用本地接收器/桩,并限制外部网络出站:
go test -tags=unit ./internal/handler ./internal/server/middleware ./internal/server/routes:完整三包通过(handler 42.105s、middleware 1.454s、routes 12.040s)。go test -tags=unit ./internal/pkg/requestmodel ./internal/service -run 'TestValidateBody|TestHasDuplicateTopLevelKey|TestDuplicateModelKeyParserDiscrepancy|TestReplaceModelInBody|TestParseOpenAIImagesRequest|TestOpenAIGatewayServiceParseOpenAIImagesRequest|TestValidateLiveCallRequest':通过。go build ./...、go vet ./...、golangci-lint run --timeout=30m:通过,lint 为0 issues。git diff --check:通过。新增回归覆盖关闭白名单、两个模型均在白名单内、Composite 路由前拦截、直接 handler 拒绝、Live JSON/multipart 重复 session、大小写/转义/null/同值重复、大量重复键,以及合法多图片上传。