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
Harden installer source selection, ROCm helper staging and npm scanner cleanup (#12402)
Daniel Han953f99f2a01a
diff --git a/install.sh b/install.shindex 99ccb34a86f..fbf82c98712 100755--- a/install.sh+++ b/install.sh@@ -4412,8 +4412,8 @@ _ZOO_GIT_SPEC="unsloth-zoo @ git+https://github.com/unslothai/unsloth-zoo@${_ZOO# ── Helper: find no-torch-runtime.txt (local repo or site-packages) ──_find_no_torch_runtime() {- # Check local repo first (for --local installs)- if [ -f "$_REPO_ROOT/studio/backend/requirements/no-torch-runtime.txt" ]; then+ # Local copy only for a --local checkout run: a piped install's _REPO_ROOT is the caller's cwd.+ if [ "$_REPO_IS_CHECKOUT" = "1" ] && [ -f "$_REPO_ROOT/studio/backend/requirements/no-torch-runtime.txt" ]; thenecho "$_REPO_ROOT/studio/backend/requirements/no-torch-runtime.txt"returnfi@@ -6328,7 +6328,11 @@ _maybe_bootstrap_rocm_wsl() {_rw_helper="${_REPO_ROOT:-.}/scripts/install_rocm_wsl_strixhalo.sh"_rw_tmp=""if [ "$_REPO_IS_CHECKOUT" != "1" ] || [ ! -r "$_rw_helper" ]; then- _rw_tmp="$(mktemp 2>/dev/null || echo /tmp/_unsloth_rocm_wsl.sh)"+ # Never fall back to a fixed /tmp name: this file runs with sudo, and another user could own it.+ if ! _rw_tmp="$(mktemp 2>/dev/null)" || [ -z "$_rw_tmp" ]; then+ substep "Could not create a private temp file for the ROCm-on-WSL helper; using CPU fallback." "$C_WARN"+ return 0+ fiif download "https://raw.githubusercontent.com/unslothai/unsloth/${_ROCM_WSL_HELPER_REF}/scripts/install_rocm_wsl_strixhalo.sh" "$_rw_tmp" 2>/dev/null; then_rw_helper="$_rw_tmp"elsediff --git a/scripts/scan_npm_packages.py b/scripts/scan_npm_packages.pyindex 4699cce470d..ae307376611 100644--- a/scripts/scan_npm_packages.py+++ b/scripts/scan_npm_packages.py@@ -1599,8 +1599,8 @@ def scan_extracted_tree(pkg: PackageEntry, root: Path) -> list[Finding]:def scan_one(pkg: PackageEntry, workspace: Path) -> tuple[list[Finding], str | None]:"""Download, extract and scan a single package, cleaning up its dir. Returns (findings, error); `error` is non-None only on hard failures (download, integrity mismatch, malformed tarball), and on a clean run with findings the caller decides the exit code from severity."""- pkg_dir = workspace / f"{pkg.name.replace('/', '_')}-{pkg.version}"- pkg_dir.mkdir(parents = True, exist_ok = True)+ # Opaque dir: lockfile names and versions are untrusted path components, and this dir is rmtree'd.+ pkg_dir = Path(tempfile.mkdtemp(prefix = "pkg-", dir = workspace))tarball = pkg_dir / "pkg.tgz"extract = pkg_dir / "x"try:diff --git a/tests/security/test_scan_npm_packages.py b/tests/security/test_scan_npm_packages.pyindex dfd9845c9d2..11d05ef540e 100644--- a/tests/security/test_scan_npm_packages.py+++ b/tests/security/test_scan_npm_packages.py@@ -927,3 +927,27 @@ def test_committed_baseline_is_empty_and_valid():doc = json.loads(path.read_text(encoding = "utf-8"))assert doc.get("entries") == []assert snp._load_baseline(str(path)) == set()++[email protected]("version", ["../../victim", "1.0.0/../../../victim"])+def test_scan_one_keeps_its_cleanup_inside_the_workspace(tmp_path, monkeypatch, version):+ """Lockfile names and versions are untrusted: scan_one's rmtree must not leave the workspace."""+ workspace = tmp_path / "ws" / "inner"+ workspace.mkdir(parents = True)+ victim = tmp_path / "victim"+ victim.mkdir()+ (victim / "keep.txt").write_text("keep")+ pkg = snp.PackageEntry(+ name = "evil",+ version = version,+ resolved = "https://registry.npmjs.org/evil/-/evil-1.0.0.tgz",+ integrity = None,+ lockfile_key = "node_modules/evil",+ )+ monkeypatch.setattr(snp, "download_tarball", lambda pkg, dest: (None, "integrity missing"))++ findings, err = snp.scan_one(pkg, workspace)++ assert (findings, err) == ([], "integrity missing")+ assert (victim / "keep.txt").read_text() == "keep"+ assert list(workspace.iterdir()) == []diff --git a/tests/sh/test_install_local_source_guard.sh b/tests/sh/test_install_local_source_guard.shnew file mode 100755index 00000000000..f4041422bbe--- /dev/null+++ b/tests/sh/test_install_local_source_guard.sh@@ -0,0 +1,52 @@+#!/bin/bash+# SPDX-License-Identifier: AGPL-3.0-only+# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0+#+# A piped install's _REPO_ROOT is the caller's cwd: only a --local checkout run may read files there.+set -e++SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"+. "$SCRIPT_DIR/_harness.sh"+INSTALL_SH="$SCRIPT_DIR/../../install.sh"++_tmp="$(mktemp -d)"+trap 'rm -rf "$_tmp"' EXIT++_gate="$(sed -n '/^_REPO_IS_CHECKOUT=0$/,/^esac$/p' "$INSTALL_SH")"+_lookup="$(sed -n '/^_find_no_torch_runtime() {$/,/^}$/p' "$INSTALL_SH")"+[ -n "$_gate" ] || bad "could not extract the _REPO_IS_CHECKOUT gate"+[ -n "$_lookup" ] || bad "could not extract _find_no_torch_runtime"++mkdir -p "$_tmp/cwd/studio/backend/requirements" "$_tmp/venv/lib/studio/backend/requirements"+echo "planted" > "$_tmp/cwd/studio/backend/requirements/no-torch-runtime.txt"+echo "official" > "$_tmp/venv/lib/studio/backend/requirements/no-torch-runtime.txt"+cp "$INSTALL_SH" "$_tmp/cwd/install.sh"++_resolve() {+ # $1 = the $0 the installer sees, $2 = STUDIO_LOCAL_INSTALL+ (+ _zero="$1"+ STUDIO_LOCAL_INSTALL="$2"+ cd "$_tmp/cwd"+ _REPO_ROOT="$_tmp/cwd"+ VENV_DIR="$_tmp/venv"+ eval "$(printf '%s\n' "$_gate" | sed "s|\"\$0\"|\"$_zero\"|g; s|\\[ -r \"\$0\" \\]|[ -r \"$_zero\" ]|g")"+ eval "$_lookup"+ _find_no_torch_runtime+ )+}++echo "=== no-torch runtime requirements source ==="+assert_eq "piped install ignores a file planted in the cwd" \+ "$_tmp/venv/lib/studio/backend/requirements/no-torch-runtime.txt" "$(_resolve sh "")"+assert_eq "piped install with STUDIO_LOCAL_INSTALL still ignores the cwd" \+ "$_tmp/venv/lib/studio/backend/requirements/no-torch-runtime.txt" "$(_resolve sh true)"+assert_eq "checkout run without --local uses the installed copy" \+ "$_tmp/venv/lib/studio/backend/requirements/no-torch-runtime.txt" "$(_resolve ./install.sh "")"+assert_eq "--local checkout run uses the checkout's copy" \+ "$_tmp/cwd/studio/backend/requirements/no-torch-runtime.txt" "$(_resolve ./install.sh true)"++echo "=== ROCm-on-WSL helper staging ==="+assert_not_contains "no fixed /tmp fallback for the sudo helper" "$(cat "$INSTALL_SH")" "/tmp/_unsloth_rocm_wsl.sh"++summary