Repository navigation
[Bug] Models settings page returns HTTP 403 when browser sends a port-less loopback Origin #894
Replies: 1 comment
|
Hi, we hit exactly the same issue: Chrome/Chromium strips the port from the Origin header for loopback URLs ( We filed a bug report with the root cause and a suggested fix (compare hostname only, ignore the port): We also maintain a green "double-click to run" launcher distribution that already fixes this with an idempotent patch (Origin check changed to hostname comparison; in LAN mode it also merges the machine's LAN IPs into trustedHosts). Feel free to reference the approach or use it directly:
你好,我们遇到了完全一样的问题:Chrome/Chromium 对回环地址( 同时我们维护的绿色整合版启动器已经解决该问题(自动打幂等补丁:Origin 校验改 hostname 比较,局域网模式自动并入本机局域网 IP),欢迎参考方案或直接使用:
本回复由 AI 辅助撰写 / This reply was drafted with AI assistance. |
Uh oh!
There was an error while loading. Please reload this page.
Summary
On Settings → Models, the provider catalog fails to load (the page reports a load error). Root cause: the
/api/*browser-trust fence inpackages/client/connection/src/api-request-trust.tsrequires an exactOrigin.host === Hostmatch including the port. When the browser sends a loopback Origin without the explicit port (e.g.http://127.0.0.1while the Host is127.0.0.1:3080), the comparison fails and the request is rejected with 403 forbidden, so the frontend shows the load failure.Environment
git clone --depth 1 https://github.com/deepseek-ai/deepseek-harness.git && pnpm install && pnpm run build && pnpm dsh web)Steps to reproduce
dsh web(listens on http://127.0.0.1:3080/).Originheader, or other local interception layers.POST /api/llm.providersreturning 403.Minimal reproduction (curl)
Simulating the browser's exact headers — note
Origin: http://127.0.0.1has no port:→ Returns
HTTP/1.1 403 forbidden.A standard browser that sends
Origin: http://127.0.0.1:3080(with port) passes. The failure only occurs when the port is omitted from the Origin.Root cause
packages/client/connection/src/api-request-trust.ts, insideisTrustedApiRequest:new URL("http://127.0.0.1").hostis127.0.0.1(port omitted, defaults to 80), whilehostUrl.hostis127.0.0.1:3080. The strict equality fails and the request is fenced out — even though both authorities are the same loopback host.Suggested fix
When both the request Host and the Origin are loopback addresses, treat them as same-origin regardless of port (the bound dev port is often not the Origin's default port). Cross-site / non-loopback Origins are still refused, preserving the DNS-rebinding / confused-deputy defense:
(
isLoopbackHostnameis already imported in this file.)Security note
This only relaxes the check for two loopback authorities. A genuine cross-site attacker Origin (e.g.
Origin: http://evil.com, or across-sitesec-fetch-siteheader) is still rejected — verified:Origin: http://evil.com→ 403.All reactions