Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.
Python agentaichatgptdeepseekfine-tuninggemmaimage-generationllamallmllmsopenaipythonqwenreinforcement-learningself-hostedstable-diffusiontext-to-speechttsuiunsloth
Studio: open //host links as web links; run apt-get by absolute path; ignore the dev Studio home (#14190)
Daniel Han551dc28123ac
diff --git a/.gitignore b/.gitignoreindex 8b281a8ca4b..4a359f7efcb 100644--- a/.gitignore+++ b/.gitignore@@ -207,6 +207,8 @@ resources/tmp/**/node_modules/auth.db+# The README's dev install keeps the Studio home in the checkout: accounts, chats, keys and a venv.+/.studio/# Tauri local build/generated outputstudio/src-tauri/target/diff --git a/studio/frontend/src/lib/open-link.ts b/studio/frontend/src/lib/open-link.tsindex 2b5121c6c90..b5696e6cd39 100644--- a/studio/frontend/src/lib/open-link.ts+++ b/studio/frontend/src/lib/open-link.ts@@ -30,6 +30,12 @@ export function openLink(url: string): boolean {if (!url) return false;// The URL parser drops tabs and newlines, so `https:\t//host` navigates like `https://host`.url = url.replace(/[\t\n\r]/g, "");+ // It also strips leading and trailing C0 controls and spaces, so ` //host` is another site too.+ let start = 0;+ let end = url.length;+ while (start < end && url.charCodeAt(start) <= 0x20) start++;+ while (end > start && url.charCodeAt(end - 1) <= 0x20) end--;+ url = url.slice(start, end);// `https:host` (no slashes) is absolute too: open it as a web link instead of letting native navigation replace// Studio's page.@@ -41,6 +47,16 @@ export function openLink(url: string): boolean {}}+ // `//host/path` (or with backslashes, which browsers read the same way) is another site, not a path in Studio:+ // native navigation would replace Studio's page (the Desktop main window) with it.+ if (/^[\\/]{2}/.test(url)) {+ try {+ url = new URL(`https:${url}`).href;+ } catch {+ return true;+ }+ }+// Anchor links scroll within the page, don't open externallyif (url.startsWith("#")) {window.location.hash = url;diff --git a/studio/frontend/tests/open-link-scheme-without-slashes.test.ts b/studio/frontend/tests/open-link-scheme-without-slashes.test.tsindex d18eba71adf..314f057e3d2 100644--- a/studio/frontend/tests/open-link-scheme-without-slashes.test.ts+++ b/studio/frontend/tests/open-link-scheme-without-slashes.test.ts@@ -34,6 +34,20 @@ test("https: without slashes opens as a web link instead of navigating Studio's}});+test("protocol-relative links open as web links instead of navigating Studio's page", () => {+ for (const [href, expected] of [+ ["//evil.example/x", "https://evil.example/x"],+ ["\\\\evil.example\\x", "https://evil.example/x"],+ ["/\\evil.example/x", "https://evil.example/x"],+ [" //evil.example/x", "https://evil.example/x"],+ ["\u0001\t//evil.example/x ", "https://evil.example/x"],+ ]) {+ opened.length = 0;+ assert.equal(openLink(href), true, href);+ assert.deepEqual(opened, [expected], href);+ }+});+test("relative, anchor and ordinary web links are unchanged", () => {opened.length = 0;assert.equal(openLink("/chat?thread=1"), false);diff --git a/studio/src-tauri/src/install.rs b/studio/src-tauri/src/install.rsindex a17b3d644f8..94fd9d4958a 100644--- a/studio/src-tauri/src/install.rs+++ b/studio/src-tauri/src/install.rs@@ -1312,6 +1312,10 @@ pub fn stop_install(state: &InstallState) -> Result<(), String> {}}+/// Run by absolute path: the elevated command must not resolve `apt-get` through a PATH the user controls.+#[cfg(target_os = "linux")]+const APT_GET: &str = "/usr/bin/apt-get";+/// Install apt system packages with elevated permissions (Linux only)./// Uses `elevated-command` crate for native auth dialog.#[cfg(target_os = "linux")]@@ -1356,7 +1360,7 @@ pub fn install_system_packages(// install.sh reports Debian package names. Do not pass them to dnf,// zypper, or pacman where names differ; show an explicit support boundary// instead of offering an elevation flow that is likely to fail.- if !Path::new("/usr/bin/apt-get").exists() {+ if !Path::new(APT_GET).exists() {let msg = "Automatic system package installation is supported on apt-based Linux distributions (Ubuntu/Debian) only. Install the missing dependencies with your package manager and retry.".to_string();finish_elevation_failure(diagnostics, elevation_attempt.as_ref(), None, msg.clone());@@ -1369,7 +1373,7 @@ pub fn install_system_packages(packages.join(", "));- let mut update_cmd = StdCommand::new("apt-get");+ let mut update_cmd = StdCommand::new(APT_GET);update_cmd.args(["update", "-y"]);match elevated_command::Command::new(update_cmd).output() {Ok(elevated_update) => {@@ -1422,7 +1426,7 @@ pub fn install_system_packages(}}- let mut install_cmd = StdCommand::new("apt-get");+ let mut install_cmd = StdCommand::new(APT_GET);install_cmd.args(["install", "-y"]).args(packages);let elevated_install = match elevated_command::Command::new(install_cmd).output() {diff --git a/tests/test_installer_elevation_report.py b/tests/test_installer_elevation_report.pyindex 790187f81b0..148285031c0 100644--- a/tests/test_installer_elevation_report.py+++ b/tests/test_installer_elevation_report.py@@ -339,3 +339,17 @@ def test_desktop_repair_marker_does_not_change_the_update_contract():assert (forbidden not in block), f"{path.name}: the repair block must be marker-only, found {forbidden!r}"+++def test_the_elevated_apt_install_runs_apt_get_by_absolute_path():+ # Elevated commands must not resolve apt-get through a PATH the user controls.+ code = INSTALL_RS.read_text(encoding = "utf-8")+ assert 'StdCommand::new("apt-get")' not in code+ assert 'const APT_GET: &str = "/usr/bin/apt-get";' in code+ assert code.count("StdCommand::new(APT_GET)") == 2+++def test_the_readme_dev_studio_home_is_ignored_by_git():+ # README's dev install uses UNSLOTH_STUDIO_HOME="$PWD/.studio": `git add .` must not stage it.+ assert 'UNSLOTH_STUDIO_HOME="$PWD/.studio"' in _read(REPO_ROOT / "README.md")+ assert "/.studio/" in _read(REPO_ROOT / ".gitignore").splitlines()