Repository navigation
Studio: retire the seeded password on Desktop and keep API callers on Sandbox High - #14422
Conversation
… Sandbox High A desktop-owned backend no longer embeds the seeded admin password in index.html. The desktop shell signs in with its own secret and never reads the page credential, so serving it only exposed it to other local processes on the loopback port. A verified desktop-login also clears the in-memory bootstrap password, the same way logout and change-password already do. Web installs (unsloth studio, Colab) keep the first-run autofill. API-key and keyless callers asking for sandbox_level "low" (Python and Terminal without the OS sandbox) are now refused with a 400, matching how full access is already refused for them. UNSLOTH_STUDIO_ALLOW_API_FULL_ACCESS=1 restores it, and Unsloth UI and Desktop sessions are unchanged.
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
@codex review |
|
@codex security review |
|
@codex review |
🛡️ Codex Security ReviewSecurity review completed. No security issues were found in this pull request. Reviewed commit: Only the user who started this review can view the report in Codex. ℹ️ About Codex security reviews in GitHubThis is an experimental Codex feature. Security reviews are triggered when:
Once complete, Codex will leave suggestions, or a comment if no findings are found. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 428448e022
ℹ️ 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".
| # The shell owns this backend and never uses the seeded password: stop serving it to the page. | ||
| try: | ||
| request.app.state.bootstrap_password = None |
There was a problem hiding this comment.
Preserve bootstrap autofill on ownerless backends
When the Desktop app attaches to an existing terminal-started, same-root backend, backend_desktop_auth_status explicitly treats that ownerless backend as adoptable and the shell posts its valid desktop secret here. This unconditional clear then removes the bootstrap credential from subsequent ordinary browser pages even though the backend is not Desktop-owned and the default password still requires changing, regressing the web first-run autofill. Guard this clear by Desktop ownership, as _inject_bootstrap already does.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 385711c: the clear now only runs when the backend is Desktop-owned; an ownerless backend the shell attached to keeps the web first-run autofill (test added).
…p-owned backend [skip ci]
|
@codex review |
1 similar comment
|
@codex review |
|
Codex Review: Didn't find any major issues. What shall we delve into next? 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". |
[skip ci]
…ox (unslothai#14757) ## Problem unslothai#14345 and unslothai#14422 set the rule that an API key (or keyless API access) never runs Python or Terminal without the OS sandbox unless the server sets `UNSLOTH_STUDIO_ALLOW_API_FULL_ACCESS=1`: Full access, `bypass_permissions`, `disable_sandbox` and `sandbox_level: "low"` are all refused for API callers. The tool approval path was not part of that rule. In `auto` and `ask` modes a call that names a host path outside the sandbox roots parks for confirmation, and an approved one launches with software safeguards only (`_prepare_tool_launch`, fault `user_approved_host_access`). `POST /api/inference/tool-confirm` accepts an approval from any authenticated caller, API keys included, and the request that started the run receives the approval id in its own stream. So an API caller could approve its own parked host-path call and get the unsandboxed launch the other checks refuse. A second gap made the launch side unable to tell: for an owner-scoped API key, `account_tool_stream` ran the tool thread without rebinding the account, so the thread lost the "admitted by an API key" flag. ## Change - `/tool-confirm`: an `allow` from an API-key or keyless caller for a parked call that would reach host paths gets 403, naming the env opt-in. `deny` is accepted from everyone, and approving a call that stays in the sandbox is unchanged. - The three tool loops (`studio_tool_loop`, `llama_cpp`, `safetensors_agentic`) flag a parked call as host access when it is registered, using the same `_reaches_host_paths` check the executor applies before honouring an approval (`approval_grants_host_access`). The flag is set before the approval id is sent to the client. - Launch side, independent of who approved: `_prepare_tool_launch` ignores an approval for a call that came from an API-key request and keeps it in the OS sandbox in `required` mode, so a sandbox that is unavailable refuses instead of falling back to software safeguards. The Windows cmd Terminal path applies the same check. - `account_tool_stream` now rebinds the account for owner API-key requests too, so the tool thread sees the same API-key flag the request had (this also makes the existing `require_tool_access` check inside `execute_tool` effective for owner keys). - `UNSLOTH_STUDIO_ALLOW_API_FULL_ACCESS=1` restores the previous behaviour for API callers. Unsloth UI and Desktop sessions are unchanged. ## Tests New `studio/backend/tests/test_api_key_tool_confirm.py` drives each of the three tool loops end to end with a real approval slot, the real `/tool-confirm` route (API-key auth faked as in `test_api_key_sandbox_level.py`) and the real `_prepare_tool_launch` decision (OS sandbox stubbed): | case | main | this PR | |---|---|---| | API key approves a host-path call | 200, launches with software safeguards | 403, call does not run | | UI approves a host-path call from an API-key request | software safeguards | OS sandbox, `required` | | API key with `UNSLOTH_STUDIO_ALLOW_API_FULL_ACCESS=1` | software safeguards | software safeguards | | UI session approves its own host-path call | software safeguards | software safeguards | | API key denies | 200, not run | 200, not run | | API key approves a sandboxed call (`ask` mode) | 200, OS sandbox | 200, OS sandbox | 14 of the 26 new tests fail on main and all 26 pass on this branch. The 25 existing studio backend test files that touch tool approvals, `host_access_approved`, the API Full access opt-in, `sandbox_level` or `_prepare_tool_launch`, plus the new file (CPU, Linux): 4334 passed on this branch and 4320 on main. The same 36 tests fail on both: the MCP tests in `test_account_tool_isolation.py`, plus tests in `test_llama_admission_compat_matrix.py`, `test_mcp_image.py`, `test_llama_cpp_tool_loop.py::test_web_search_keeps_to_the_requested_domains` and the Terminal cases of `test_tool_sandbox_wiring.py`. The only other difference is the 14 new tests, which fail on main. ## Not covered - A project folder the owner picked keeps running with software safeguards for every call in `auto`, approved or not. That is unchanged here, for API callers too. - When the OS sandbox is unavailable, `auto` falls back to software safeguards for calls that never park. That is unchanged too. Only the approved host-path call from an API key is now refused. - Tested on Linux with the OS sandbox stubbed. No live backend run, and the Windows and macOS sandbox backends were not exercised. --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
…allowlist (#16674) Fixes #16625 (the host allowlist part) ## Problem Python tool code that reaches a host outside the built in allowlist (for example `requests.get("https://example.com/")`) is flagged as risky, so in **Ask for approval** and **Approve for me** the user gets an approval prompt. Clicking Approve did nothing: `_python_exec` re-ran the same static check and refused the call with `Blocked: host not in sandbox allowlist`. The only way to reach such a host was **Full access**, which also turns off every file restriction. That is exactly the "soften the network while keeping file access strict" gap from the issue. Measured on main (Linux, software safeguards): | Python code | asks first | approved | result | |---|---|---|---| | `urlopen("https://example.com/")` | yes | no | `Blocked: host not in sandbox allowlist` | | `urlopen("https://example.com/")` | yes | yes | `Blocked: host not in sandbox allowlist` | ## Fix `_check_code_safety` takes `host_approved`; when set it drops only the `untrusted_host_blocked` findings. `_python_exec` passes it for a call the user approved, the same way an approved `rm` is already let through in `_bash_exec`. - The allowlist is advisory today: every sandbox backend reports `unrestricted_network` (see #13345), so this changes no boundary. - Cloud-metadata hosts, uploads, non-literal destinations and every other static check stay blocked, approved or not. - File isolation is unchanged: the call still runs in the OS sandbox unless it names host paths, which was already the rule for approved calls. - API-key requests keep the allowlist even after an approval, matching #14345 / #14422. - Run automatically and unapproved calls behave exactly as before. No UI change. - A remembered "Always allow" for Python in a chat counts as an approval here, the same way it already does for host file access. After the fix: | Python code | approved | result | |---|---|---| | `urlopen("https://example.com/")` | no | `Blocked: host not in sandbox allowlist` (unchanged) | | `urlopen("https://example.com/")` | yes | `200` | | `urlopen("http://169.254.169.254/...")` | yes | `Blocked: cloud-metadata host` (unchanged) | | `urlopen("https://pypi.org/simple/")` | either | `200` (unchanged) | ## Tests `tests/test_sandbox_tools.py::TestApprovedHostLiftsOnlyTheAllowlist` (5 cases) fails on main and passes here: the approved host goes through, metadata / upload / non-literal destinations stay blocked, and an API-key caller is still refused. Base vs head over the 11 test files that touch the changed code (`test_sandbox_tools`, `test_tool_sandbox_*`, `test_api_key_tool_confirm`, `test_approved_rm`, `test_permission_mode*`, the tool loop tests, `test_windows_cmd_terminal_profile`): base 6 failed / 4336 passed, head 1 failed / 4341 passed. The 5 new tests are the only change; the remaining failure (`test_llama_cpp_tool_loop.py::test_web_search_keeps_to_the_requested_domains`) fails on main too. Extra folders and per-tool allow rules from the issue are separate features and are not part of this PR.
Hardening from a security review of the Studio tool sandbox. Nothing changes for Desktop sign-in, the first-run password change in the web UI or Colab, or notebooks.
Problem 1: the seeded owner password stays in the page on Desktop. While the default
unslothpassword is still pending a change,index.htmlcarries it for a direct loopback client so the first-run screen can fill it in. A Desktop backend never retires it: the shell signs in through/api/auth/desktop-login, which answersmust_change_password = False, so the pending state can last forever. Tool code runs in a jail that shares the host network on purpose (tools download models), so it reaches the loopback port like a local browser and can read that password.Change. A Desktop-owned backend no longer injects the seeded password, and a successful
desktop-loginclears it from memory. The Tauri shell loads its own bundled frontend and signs in with its own secret; the only reader of the injected value is the change-password form, which the shell skips. The web UI,unsloth studioand Colab first-run autofill are unchanged.http://127.0.0.1:<port>in an ordinary browser before ever setting a password now sees a "Current password" field instead of an autofilled one (the password is in.bootstrap_password, as before). After the password is set in Desktop, browser login is unchanged.Problem 2: API callers can still pick Sandbox Low. #14345 keeps API-key and keyless callers out of Full access,
bypass_permissionsanddisable_sandbox, butsandbox_level: "low"(Python and Terminal on software safeguards only, no OS sandbox) was not part of that check.Change.
require_tool_accessalso refusessandbox_level: "low"for API-key and keyless callers, with the same 400 and the sameUNSLOTH_STUDIO_ALLOW_API_FULL_ACCESS=1opt-in. The default ishigh, the UI (session login) keeps Sandbox Low, and one check covers/v1/chat/completions,/v1/responses,/v1/messagesand durable chat runs.Both changes are pure checks; nothing is stored, so repeating them is a no-op.
Tests.
test_desktop_bootstrap_retired.pyandtest_api_key_sandbox_level.py: 13 of 19 fail on main, all 19 pass here. The 90 existing modules that exercise these files give the same result on both sides (one test,test_desktop_auth.py::test_health_response_reports_desktop_capability_fields, already fails on main).Before / after. A first launch with the Desktop owner variables set, opened in a plain browser tab. Before, the page carries the seeded password and the setup form fills it in silently (no "Current password" field); after, the page no longer contains it and the form asks for the current password. The Desktop app itself signs in through
/api/auth/desktop-loginand does not use this page.