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: keep refusing a symlinked spill where there is no O_NOFOLLOW (Windows) (#15887)
Daniel Hancf80abd63965
diff --git a/studio/backend/core/inference/tools.py b/studio/backend/core/inference/tools.pyindex 2b0d064fad7..6014c52e70b 100644--- a/studio/backend/core/inference/tools.py+++ b/studio/backend/core/inference/tools.py@@ -20680,13 +20680,21 @@ def _stamp_size(stamp: str) -> "int | None":def _file_digest(path: str, expected_size: "int | None" = None) -> "str | None":"""Opened with O_NOFOLLOW and O_NONBLOCK, so a symlink or FIFO swapped in at the path is rejected."""- flags = os.O_RDONLY | getattr(os, "O_NOFOLLOW", 0) | getattr(os, "O_NONBLOCK", 0)+ no_follow = getattr(os, "O_NOFOLLOW", 0)+ flags = os.O_RDONLY | no_follow | getattr(os, "O_NONBLOCK", 0)fd = Nonetry:+ # Windows has no O_NOFOLLOW: refuse a link up front, and a link swapped in before the+ # open shows up as a different file once it is open.+ named = None if no_follow else os.lstat(path)+ if named is not None and not stat.S_ISREG(named.st_mode):+ return Nonefd = os.open(path, flags)info = os.fstat(fd)if not stat.S_ISREG(info.st_mode):return None+ if named is not None and (info.st_dev, info.st_ino) != (named.st_dev, named.st_ino):+ return Noneif expected_size is not None and info.st_size != expected_size:return Nonedigest = hashlib.sha256()diff --git a/studio/backend/tests/test_tool_result_fits_window.py b/studio/backend/tests/test_tool_result_fits_window.pyindex 6bb77f67e4e..3993fb28d08 100644--- a/studio/backend/tests/test_tool_result_fits_window.py+++ b/studio/backend/tests/test_tool_result_fits_window.py@@ -620,6 +620,10 @@ class TestTheSpillStaysInsideTheSandbox:assert "saved to" not in outassert (target / f"{digest}.txt").is_symlink()+ @pytest.mark.skipif(+ os.utime not in os.supports_follow_symlinks,+ reason = "cannot date a symlink itself here (Windows), so it cannot be made the oldest",+ )def test_pruning_does_not_follow_symlinks_either(self, tmp_path):target = _own(tmp_path)victim = tmp_path / "victim.txt"@@ -1150,7 +1154,10 @@ class TestConcurrentSpillsKeepTheirRecords:root = tmp_path / tools._SPILL_DIRrecorded = set(tools._spill_manifest(str(root)))- on_disk = {str(p.relative_to(root)) for p in root.rglob("*.txt") if p.name != "victim.txt"}+ # The manifest keys are "/"-joined on every OS.+ on_disk = {+ p.relative_to(root).as_posix() for p in root.rglob("*.txt") if p.name != "victim.txt"+ }assert on_disk, results[:1]assert on_disk <= recorded, "a spill on disk that the manifest does not record"@@ -1450,6 +1457,39 @@ class TestReadingASpillCannotBeRedirected:assert tools._file_digest(str(link)) is None+ def test_without_o_nofollow_a_symlink_is_still_refused(self, tmp_path, monkeypatch):+ """Windows has no O_NOFOLLOW, so the guard above cannot rest on the open flag alone."""+ monkeypatch.delattr(os, "O_NOFOLLOW", raising = False)+ elsewhere = tmp_path / "elsewhere.txt"+ elsewhere.write_text("someone else's file")+ link = tmp_path / "abcdef123456.txt"+ link.symlink_to(elsewhere)+ plain = tmp_path / "fedcba654321.txt"+ plain.write_text("a spill")++ assert tools._file_digest(str(link)) is None+ assert tools._file_digest(str(plain)) == hashlib.sha256(b"a spill").hexdigest()++ def test_without_o_nofollow_a_link_swapped_in_before_the_open_is_refused(+ self, tmp_path, monkeypatch+ ):+ monkeypatch.delattr(os, "O_NOFOLLOW", raising = False)+ elsewhere = tmp_path / "elsewhere.txt"+ elsewhere.write_text("someone else's file")+ name = tmp_path / "abcdef123456.txt"+ name.write_text("a spill")+ real_open = os.open++ def _swap_then_open(path, *args, **kwargs):+ if os.fspath(path) == str(name):+ os.unlink(name)+ name.symlink_to(elsewhere)+ return real_open(path, *args, **kwargs)++ monkeypatch.setattr(os, "open", _swap_then_open)+ assert tools._file_digest(str(name)) is None++ @pytest.mark.skipif(not hasattr(os, "mkfifo"), reason = "no FIFOs on this OS")def test_a_fifo_is_refused_rather_than_read(self, tmp_path):fifo = tmp_path / "abcdef123456.txt"os.mkfifo(fifo)@@ -1515,6 +1555,7 @@ class TestPruningNeverMovesSomethingItCannotPutBack:assert open(os.path.join(spill, "receipts.csv")).read() == "the user's own data"assert not self._private_names(root)+ @pytest.mark.skipif(not hasattr(os, "mkfifo"), reason = "no FIFOs on this OS")def test_a_fifo_left_at_the_name_is_not_moved(self, tmp_path, monkeypatch):root, spill, owned = self._a_recorded_spill(tmp_path)os.unlink(spill)