Repository navigation
Studio: scope the seeded bootstrap password auto-fill to loopback clients - #7131
danielhanchen merged 12 commits into
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces a security check _is_loopback_client to prevent the bootstrap admin password from being leaked to LAN peers when binding to a wildcard address (0.0.0.0), along with comprehensive unit tests. The review feedback correctly identifies a compatibility issue with ipv4_mapped on Python versions prior to 3.12 and provides a robust fallback implementation to prevent test failures on older Python environments.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 150f37f06a
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 95b7cc132d
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
|
@codex review |
|
Codex Review: Didn't find any major issues. Can't wait for the next one! Reviewed commit: ℹ️ About Codex in GitHubCodex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback". |
|
Thanks for this. The loopback scoping is correct, and the Cloudflare tunnel and DNS rebinding cases are both handled well. I pushed one small addition on top: a regression test for the On the earlier note about Rest looks good to me. |
…nnel headers and malformed Host)
|
Pushed a follow-up (4b71e47) to tighten the "is this a local client" gate. Three cases could still receive the seeded bootstrap password: 1. Reverse proxies other than Cloudflare. The gate only rejected 2. Malformed or absent Host. 3. Colab shareable link. The decision is now a single Verified on a real |
|
Pushed one more hardening (d602843) after a broad cross-platform and cross-version simulation. While simulating the loopback classifier I found a small gap in my own change. Simulation summary, all green:
No dependency or API changes: the gate uses only |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 795900bb6a
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| if host.startswith("["): # [IPv6](:port) | ||
| host = host[1:].split("]", 1)[0] |
There was a problem hiding this comment.
Fail closed on malformed loopback Host headers
This parser strips a bracketed Host down to the text before ] without validating that the bracket exists or that the suffix is empty/a port, so values like [::1]attacker or [::1 are reduced to ::1 and accepted as loopback. In the loopback-terminating proxy/tunnel case this gate is meant to defend, if the proxy omits the listed forwarding headers, a remote top-level GET has no Origin and can choose such a malformed Host to still receive the bootstrap script despite the fail-closed Host check.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Good catch, fixed in 9220109. The bracket branch now requires a real closing bracket followed only by a port, so [::1]evil, [::1 and [::1]x no longer reduce to ::1 and instead fail closed. Added regression cases for the smuggling variants.
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: b27e8a3273
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if any(request.headers.get(h) is not None for h in _PROXIED_CLIENT_HEADERS): | ||
| return False | ||
| return _host_header_is_loopback(request.headers.get("host")) |
There was a problem hiding this comment.
Block headerless loopback reverse proxies
When Studio sits behind a minimal reverse proxy on the same host, this gate still returns true for remote users: for example, NGINX with just proxy_pass http://127.0.0.1:8902; connects from 127.0.0.1 and, per the official proxy docs, defaults Host to $proxy_host while only redefining Host/Connection unless extra proxy_set_header directives are added (https://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_set_header). A top-level browser GET has no Origin, none of the headers in _PROXIED_CLIENT_HEADERS are present, and the loopback Host makes _host_header_is_loopback() pass, so the bootstrap password is still embedded for a remote client through this common proxy configuration.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Confirmed, this is a real gap. With a minimal same-host reverse proxy (for example nginx proxy_pass http://127.0.0.1:PORT; with no extra proxy_set_header lines) nginx connects from loopback, forwards Host: $proxy_host (a loopback authority), sets none of the forwarded-client headers, and a top-level GET carries no Origin, so _should_inject_bootstrap returns true for a remote user. No socket, Host, or port signal can separate that from a genuine local browser, because the proxy connects to the same loopback socket and can present the same values.
Two notes on scope. This is pre-existing: the same-origin-only gate before this change embedded the password for that nginx config too. And the bootstrap timeout does not arm for a loopback bind (_is_exposed_bind is false for 127.0.0.1), so a proxied loopback instance is never torn down either. This change still strictly tightens the direct-LAN, Cloudflare-tunnel, and DNS-rebinding paths.
The robust fix is to stop trusting network position and require an unforgeable local proof: a single-use setup token that Studio prints only to the local terminal and gates injection on (the same shape as Jupyter's ?token=). A proxied remote user never sees the terminal, so cannot obtain it. That reworks the first-login startup emission, so it is better as a focused follow-up than folded into this loopback-scoping change.
There was a problem hiding this comment.
Confirmed the nginx default (Host becomes $proxy_host and no X-Forwarded-For is added), so the observation is accurate. It is out of scope for this change for two reasons. First, it is indistinguishable at the HTTP layer from a genuine local client: a loopback peer with a loopback Host and no forwarding headers is exactly what a local browser sends, so no request-based or bind-based check can block it without also breaking the legitimate local autofill this gate exists to provide. Second, a correctly configured reverse proxy forwards the client via X-Forwarded-For (or Forwarded / X-Real-IP), all of which _PROXIED_CLIENT_HEADERS already treats as remote; the exposure only remains for a proxy that forwards no client-identifying header at all, which is a misconfiguration that also loses the real client IP in logs and breaks virtual-host routing. It is also pre-existing (the same-origin-only gate before this PR served the seed to this same setup) and limited to the pre-first-password-change window. Fully removing even the misconfigured-proxy case would mean not embedding the seed in-page at all (it is always printed to the terminal and saved to .bootstrap_password), which is a separate design decision rather than part of scoping the auto-fill to loopback.
|
@codex review |
|
Codex Review: Didn't find any major issues. Delightful! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
Follow-up to #7131. That change scoped the in-page auto-fill of the seeded admin bootstrap password to loopback clients, but "is this a local client" cannot be decided from a request. A default nginx `proxy_pass http://127.0.0.1:PORT;` forwards `Host: 127.0.0.1:PORT` from a loopback socket with no forwarding headers, which is byte-for-byte identical to what a genuine local browser sends. No request-based or bind-based check separates the two, so the seed could still reach a remote user during the pre-first-password-change window. This removes the injection entirely rather than tightening a gate that cannot hold. The seed is saved to .bootstrap_password (0600, deleted on rotation) and the startup banner points at it, so the operator reads it from there on first login. That closes the LAN, tunnel and reverse-proxy exposure classes together and deletes the Origin/loopback/Host detection code. - studio/backend/main.py: _build_index_response serves the SPA shell without ever embedding window.__UNSLOTH_BOOTSTRAP__. Removes _inject_bootstrap, _should_inject_bootstrap, _is_local_bootstrap_request, _host_header_is_loopback, _is_loopback_ip, _PROXIED_CLIENT_HEADERS, _is_same_origin_request, _canonical_origin, _DEFAULT_PORTS and the now-unused ipaddress import. _CSP_SCRIPT_NONCE_HEADER stays: the vendored Swagger/ReDoc pages still use it. - Replaces the origin/loopback suites with test_index_no_bootstrap_injection.py, which asserts the served page never contains the seed over the root and SPA-fallback routes, with a pending password change and a seed present. The four first-boot Playwright drivers now go through a shared helper, _playwright_robust.fill_bootstrap_current_password, which asserts window.__UNSLOTH_BOOTSTRAP__ is undefined and that #current-password is visible and empty BEFORE it types. The previous `if cur_pw.count():` guard passed whether or not the injection was removed, so the browser smoke could not have detected the injection coming back. The IME and model-config workflow steps now read, mask and export the bootstrap password, which they previously did not need. Behavioural notes: the index response no longer sets Vary: Origin (nothing depends on it; Cache-Control: no-store still applies). auth-form.tsx keeps its window.__UNSLOTH_BOOTSTRAP__ branch, which is now permanently inert; it is left in place so a mixed-version frontend cannot lose the Current password field, and test_auth_form_input_count.py still locks its derivation. Its docstring no longer points at the deleted _inject_bootstrap. tests/studio/test_model_config_bootstrap_password.py is a source-contract guard, and no CI job currently runs tests/studio as a directory, so it and the inverted test_composer_rtl_bidi_attribute.py guards run locally only.
On a wildcard bind (
unsloth studio -H 0.0.0.0), the servedindex.htmlauto-injects the seeded admin bootstrap password so the first-login form can pre-fill. The gate for that (PR #5739) only checks same-origin, not who is connecting, so a LAN peer that opens the host gets the default admin credential in-page. Studio's server-side Python and terminal tools are on by default, so that credential is a remote code-execution surface.Fix
Also require the client to be on this machine. The gate is now same-origin AND (Colab OR loopback client). A remote peer reads the password from the terminal instead (still printed at startup and saved to
.bootstrap_password); login is unchanged. Colab is exempted because its trusted forwarded headers make every peer look remote and a notebook is a single-user sandbox.Verification
Ran a real
-H 0.0.0.0server: a loopback request still auto-fills, a request from the machine's LAN IP does not. Added regression tests for the loopback classifier; the bootstrap-origin suite stays green (34 passed).