Skip to content

Unsloth Studio / Desktop: linked instances get no tools unless the owner allows them, and the proxy relays only media - #12388

Draft
LeoBorcherding wants to merge 83 commits into
unslothai:mainfrom
LeoBorcherding:feat/studio-linked-security
Draft

LeoBorcherding wants to merge 83 commits into
unslothai:mainfrom
LeoBorcherding:feat/studio-linked-security

Conversation

@LeoBorcherding

Copy link
Copy Markdown
Collaborator

Builds on #12093 (linked model picker), which builds on #12092 (linked instances). Review those first; the diff includes their commits until they merge.

Linking another machine (Colab, WSL, a PC on the LAN) makes its models usable here as @name/model. Before this PR, the request was forwarded as-is, tool fields included. So any caller with an API key on this machine could ask @wsl/... for enable_tools: true, enabled_tools: ["python"], permission_mode: "off", and the remote would run that code with no prompt anywhere. This PR keeps tools off for a linked instance until its owner turns them on, and stops the proxy from serving a remote's HTML or scripts from this app's origin.

What changes

  • Tools are off by default per linked instance.
    • forward() drops every tool field (enable_tools, enabled_tools, mcp_enabled, permission_mode, bypass_permissions, confirm_tool_calls, deep_research_armed) and sends an explicit enable_tools: false, so the remote's own default can't turn tools back on.
    • Each strip is logged as linked_instance_tools_stripped, with the instance and the fields dropped.
    • New allow_tools column, migrated in with DEFAULT 0, so existing links start with tools off.
  • Allow tools switch on each row in Settings → API keys → Linked instances. Turning it on asks for confirmation first: tools run on that machine, under its permission settings, and nothing on this machine prompts for them.
  • First-use notice, once per instance, before the first chat or image job goes to it. It says the prompts, files and images are sent there. For a tunnel link it adds that Cloudflare relays the traffic. It also says whether tools are on.
  • Proxy hardening. A relayed body is served from this origin, so:
    • Only image/, video/, audio/, application/octet-stream and text/event-stream keep their type. Anything else, including a missing type or a body that claimed JSON and wasn't, goes out as application/octet-stream with Content-Disposition: attachment.
    • Every relayed response gets X-Content-Type-Options: nosniff, a sandbox CSP and X-Frame-Options: DENY.
    • The remote's Content-Disposition is kept only on media types.
  • The new text is added to all 12 locales, in English for now, the same way other new keys landed.

Screenshots

Coming in a follow-up comment, from a full test pass on a second machine: Settings before and after, the Allow tools confirm, and the first-use notice in the chat and Images pickers.

Where it was run so far

Measured at edd2f08172, on Windows 11 + R9700 (Unsloth Desktop debug build), with an Unsloth Studio instance in WSL2 Ubuntu 24.04 linked as @wsl.

Check Before (810655de03) After (edd2f08172)
/v1/chat/completions to @wsl/unsloth/Qwen3.5-0.8B-MTP-GGUF with python enabled and permission_mode: "off", asking it to write /tmp/unsloth_linked_probe Tool ran on @wsl; the file was written No tool ran, no file; log shows enable_tools, enabled_tools, permission_mode stripped
A remote answering an allowlisted proxy path with text/html Relayed as text/html (local server returning HTML) Covered by unit test only: the proxy needs a UI session, so an API key can't drive it end to end
Backend tests (test_linked_instances.py) 40 pass 50 pass
Frontend typecheck, i18n parity clean clean

Still to run, on the second machine:

  • @wsl or a LAN instance with Allow tools on, to confirm tools still reach the remote when allowed. A unit test covers it, but there's no live run yet.
  • The first-use notice in the chat and Images pickers, including that it shows once per instance.
  • A Colab tunnel link. Only the LAN and WSL path has been exercised.

Not in this PR

  • Key exposure on a stale tunnel URL. If a trycloudflare.com hostname is reused by someone else, they receive the instance's API key. The fix is to pin the remote's identity from /api/system; that's a follow-up.
  • Plain http to a LAN address sends the key in cleartext. There's no warning for it yet.
  • A persistent chat banner while a linked model is selected. Right now the trigger shows the machine name, plus the one-time notice.

…mote's own API; API page panel and details dialog
…w and grows on scroll, detail pane follows the newest request, no truncated labels
The rail, the settings row and the details dialog read only the first GPU, so a machine with an RX 6500 XT and an RX 5700 XT showed as one 4 GB card (and the settings row as 2x RX 6500 XT). They now name each card, sum the VRAM, and the dialog adds a Total VRAM line.
The rail groups cards by model and draws one VRAM cell per card in rows of up to 8. The details dialog puts Total VRAM first and scrolls the per-card list past two cards, numbering each card and wrapping long names instead of cutting them off.
…d images

A half pill beside On Device switches the chat and Images pickers to a linked Unsloth Studio. Recommended and On Device then list that machine's models; a pick downloads and loads there through an allowlisted proxy that adds the instance's key server-side. /v1/images/generations forwards @name/model ids, and the Images page loads and generates on the machine its model came from.
A probe that timed out marked a reachable machine offline and the panel refused to list it. The panel now tries the machine's inventory and reports only a real failure. Fit, the header and the machine menu use every card's VRAM, since llama.cpp splits a GGUF across them.
…detectCapabilities

The Images trigger names the linked machine with the cloud icon, as chat does for @-ids.
The media filter used detectCapabilities without importing it.
…s on the tab row

Linked quant rows use the local variant markup: mono label, downloaded tag, fit badge and size.
The panel widens by the machine switch so All and Recent no longer wrap.
Main's contrast-slider scan covers the rail: its bar tracks now use the contrast-wash gain.
…d UI scale checks

Read the media catalogs inside a function, since they come through the chat barrel and a module-scope read throws when the import cycle re-enters. Keep the picker's resolved memo named currentModel and call the linked-machine wrapper triggerModel, so the dropped-model label check finds the memo that consults the connections. The gallery delete test stubs ip(), which every image route goes through for the linked machine. The machine name's max width scales with --ui-space-scale.
/v1/models lists every linked instance's models as @name/id, embedding
models included, but /v1/embeddings had no linked branch, so a client that
picked one got the local embedding path or an error instead of the instance
that serves it. It now resolves and forwards like completions does. Test
added.
…CI contracts

The Hebrew and Swedish overlays arrived with the merge of main and had none
of the 61 linked-instance strings, which fails the strict i18n check. The
linked-instance routes are owner-only installation objects, so the account
isolation matrix skips them with that reason, as it does for NPU models. The
usage-examples contract reads the filtered catalog set, the API page's
overflow contract leaves the font-mono example request alone, and a blank
line from the merge resolution is formatted away.
The proxy is behind the same installation-owner check as the other
linked-instance routes, so it carries the same skip reason.
Image, speech and separation models carry a task, and none of their
endpoints forwards a linked id, so advertising them sent a client that
picked one to the local media runtime. They are left out until their
endpoint forwards. Test added.
Image generation resolves and forwards a linked id here, so text-to-image
rows stay in the linked catalog; speech and separation rows stay out.
The catalog filter ran after probe, so the status cards in Settings still
listed media models as copyable ids. The filter now runs in probe, which
both read. Test added.
…witch

Picking a model on another machine moved progress polling, Stop and the
gallery before the busy check, so Stop could go to the wrong machine. The
switch is now refused while work is running. An idle switch kept the old
machine's shelf, whose actions then went to the new machine; it is now
dropped, any listing in flight is fenced, and the new shelf is fetched.
Test added.
…gone

A removed linked instance left its id stored, so every Images request went
to its proxy and returned 404. Once the refreshed list lacks it, the page
switches to this machine through the same path a pick takes; the list is
force-refreshed on open so a removal in Settings is seen. Test added.
Chat completions ran the local tool admission before resolving a linked
model, so on a managed install a full-access request to a linked model was
refused here although the linked server applies its own policy. It now
resolves first, as responses and messages already do. Test added.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

affects UI# conflicts# new-feature# security# Moves a security boundary: sandbox, allowlist, permission or network guard >3000#

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants