Skip to content

fix(studio): serve desktop SPA on loopback listener - #10847

Merged
danielhanchen merged 7 commits into
unslothai:mainfrom
Souravrajvi0:feat/loopback-studio-ui-6a2e
Oct 1, 2026
Merged

danielhanchen merged 7 commits into
unslothai:mainfrom
Souravrajvi0:feat/loopback-studio-ui-6a2e

Conversation

@Souravrajvi0

@Souravrajvi0 Souravrajvi0 commented Sep 13, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Desktop runs the backend --api-only on 127.0.0.1, and the packaged web UI was only served to the Cloudflare edge or the LAN listener, so http://127.0.0.1:8888 and http://localhost:8888 returned 404 while the LAN IP worked.
  • Loopback is a browser secure context, so this also blocked mic dictation (getUserMedia) in the browser.
  • The SPA gate now also admits a direct browser on the loopback listener, using the same check that already gates bootstrap password injection: loopback socket, loopback peer, loopback Host, and no Forwarded / X-Forwarded-* / X-Real-IP / CF-Connecting-IP header. Bootstrap injection itself is unchanged.

Fixes #10786

Test plan

  • Real uvicorn server, desktop tunnel_only mount, base vs head:
request base head
GET / via 127.0.0.1 404 200
GET / with Host: localhost 404 200
GET /assets/app.js 404 200
GET /chat (deep link) 404 200
GET / with X-Forwarded-For 404 404
GET / with CF-Connecting-IP 404 404
GET / with Host: evil.example (rebinding) 404 404
  • pytest tests/test_lan_access_settings.py tests/test_middleware.py tests/test_account_desktop_network.py: 246 passed; the three updated tests fail on main.

chatgpt-codex-connector[bot]

This comment was marked as outdated.

@Souravrajvi0

This comment has been minimized.

Desktop api-only mode used tunnel_only to block the web UI on the primary
127.0.0.1 listener while still serving it on the LAN socket, which broke
documented http://127.0.0.1:8888 access and secure-context features such
as speech dictation. Admit the SPA when the accepting socket is loopback,
using scope server rather than the Host header.

Fixes unslothai#10786
Apply the same peer, Host, and proxy-header checks as bootstrap injection
before admitting requests on the loopback listener. Blocks cloudflared or
local reverse proxies that dial 127.0.0.1 from serving the packaged UI.
…0786)

Require Host to include the accepting socket port on non-default listeners
so a header-stripping reverse proxy that rewrites Host to bare 127.0.0.1
cannot reach the packaged SPA on 127.0.0.1:8888. Expand proxied-client
header detection, admit Starlette TestClient's synthetic peer, and add
regression tests for stripped Host and CF-on-loopback cases.
@Souravrajvi0
Souravrajvi0 force-pushed the feat/loopback-studio-ui-6a2e branch from e0b686d to fac6c70 Compare September 17, 2026 04:21
@Souravrajvi0

This comment has been minimized.

Drop the Host authority parser, the extra proxy headers and the testclient
peer special case: the SPA gate now admits exactly the requests that already
qualify for bootstrap injection (loopback peer, loopback Host, no forwarding
headers) when the accepting socket is loopback. Bootstrap injection itself is
unchanged, so SSH or IDE port forwards to a different local port keep their
autofill.
@danielhanchen

Copy link
Copy Markdown
Member

Review record for #10847, carried over from the mirror it was reviewed on: danielhanchen/unsloth-staging-review#290.

Findings are quoted as posted and attributed to the account that posted them. The reactions shown are the triage recorded on the mirror; none were re-applied here. Commits are named as the mirror's, with this PR's equivalent where one was found.

Round 1: reviewed mirror 8d137dbcdf (this PR's 97ffce33d)

chatgpt-codex-connector[bot] (on the mirror)

Codex Review: Didn't find any major issues. Chef's kiss.

Reviewed commit: 8d137dbcdf

No triage reaction was recorded on the mirror

Verdict

The round converged at mirror 8d137dbcdf (this PR's 97ffce33d).

This is the review as it stood at that commit. Anything pushed to this PR afterwards was not part of it.

@danielhanchen
danielhanchen merged commit 9dd4977 into unslothai:main Oct 1, 2026
7 of 55 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] On web browser, UI returns 404 on loopback (127.0.0.1 / localhost) but serves fine on LAN IP

2 participants