[Bug] SSRF 加固后配置大模型获取模型列表提示参数无效
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 4.7k
- Forks
- 719
- Avg merge
- 4h 30m
- Merged PRs (30d)
- 83
Description
用户信息
- UID:019d5da5-27a2-7679-b28e-f6fb5d1e78b5
- 发生位置:设置 -> AI 大模型 -> 配置大模型
问题描述
升级到包含 SSRF 加固的版本后,配置大模型并打开模型名称列表时,请求失败。旧版本同样的配置可以正常获取模型列表。
页面提示:
获取模型列表失败: 参数无效 [trace_id: 0f7a4151b2374fce8e6cdfce08a74ba2],可手动填写模型名称
复现步骤
- 进入“设置 -> AI 大模型”。
- 点击配置大模型。
- 填写 API Token 和 Base URL。
- 打开模型名称下拉框,触发模型列表请求。
- 页面提示“获取模型列表失败: 参数无效”。
预期结果
合法且可访问的模型 Base URL 可以正常返回模型列表;地址被安全策略拒绝时,页面展示明确的地址安全错误。
实际结果
模型列表请求失败,地址校验、DNS、代理、上游 HTTP 等错误均可能被统一显示为“参数无效”,无法从页面判断真实原因。
回归定位
高概率与以下 2026-07-20 合入的提交有关:
b70e9379:为GetProviderModelList新增 Base URL DNS/IP 安全校验。be1f5a42:代理连接同样使用私网地址校验。d6e6d8e5:合并上述 SSRF 修复。
当前调用链:
backend/biz/setting/usecase/model.go的GetProviderModelList调用validateBaseURL。backend/pkg/netguard/guard.go拒绝私网、loopback、link-local、保留地址,以及包含任一私网解析结果的域名。- 私网 HTTP/HTTPS 出口代理也会在
dialContext阶段被拒绝。 backend/biz/setting/handler/v1/model.go将除字符串包含401之外的所有错误包装为ErrInvalidParameter。- 前端最终只能显示“参数无效”。
前端在相关版本间仍使用:
GET /api/v1/users/models/providers
api_key=<token>
base_url=<base url>
provider=<provider>
近期模型 Combobox 变更主要涉及搜索和展示,请求 endpoint 与参数构造保持一致。
可能触发条件
- 部署环境通过私网 HTTP/HTTPS 出口代理访问公网模型服务。
- 模型域名在后端容器 DNS 中解析到私网地址或公私混合地址。
- Base URL 的 DNS 解析失败。
- 上游返回 400、403、404、429、5xx 或响应格式不兼容。
- 自定义 Base URL 与隐藏的默认
provider=BaiZhiCloud不匹配。
建议修复
- Handler 保留
ErrForbiddenBaseURL的业务错误码和明确提示,避免覆盖为ErrInvalidParameter。 - 为运维侧配置的受信任出口代理建立清晰的信任边界,同时继续校验用户填写的目标地址。
- 增加私网出口代理、公私混合 DNS、静态模型列表 Provider 和错误码映射测试。
- 记录可关联响应 trace_id 的原始错误,便于线上排查。
- 检查 Base URL 变化时
provider的同步或推断逻辑。
需要进一步确认
请在生产日志中按请求时间搜索:
failed to get provider model list
重点确认原始错误是否包含:
private network address is not allowed
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with backend/biz/setting/usecase/model.go and backend/biz/setting/handler/v1/model.go, then trace validateBaseURL and backend/pkg/netguard/guard.go. Search production logs for "failed to get provider model list" and inspect the original error. Done means legitimate model-list failures and blocked addresses produce distinguishable, actionable results, with coverage for proxy and DNS cases.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- api, backend, security
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100