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: refuse a chained dataset media path whose first hop is not an archive (#14529)
Daniel Han5914b64cd634
diff --git a/studio/backend/tests/test_dataset_media_decode_guard.py b/studio/backend/tests/test_dataset_media_decode_guard.pyindex 0ef806c6774..6a66692bf8b 100644--- a/studio/backend/tests/test_dataset_media_decode_guard.py+++ b/studio/backend/tests/test_dataset_media_decode_guard.py@@ -7,6 +7,7 @@ the Hub with the server's own token; the owner decodes as before."""from __future__ import annotationsimport io+import osimport pytestfrom fastapi import HTTPException@@ -80,6 +81,35 @@ def test_managed_image_cell_naming_a_host_file_is_refused(outside_png):assert 400 <= exc.value.status_code < 500+def test_managed_chained_cell_whose_first_hop_reads_a_host_file_is_refused(outside_png):+ # fsspec opens the first hop of `file://x::hf://...`; only archive hops read through.+ # Windows: tmp_path (C:) and the checkout (D:) can sit on different drives, so relpath+ # raises; the drive-letter form `file://C:/...::hf://...` exercises the same guard.+ try:+ first_hop = os.path.relpath(outside_png)+ except ValueError:+ first_hop = outside_png.as_posix()+ path = f"file://{first_hop}::hf://datasets/a/b@main/c.png"+ name = _upload([{"image": {"bytes": None, "path": path}, "text": "a cat"}])+ with pytest.raises(HTTPException) as exc:+ _check(name)+ assert 400 <= exc.value.status_code < 500+++def test_managed_zip_member_of_own_archive_still_previews():+ import zipfile++ def own_zip():+ path = storage_roots.dataset_uploads_root() / "own.zip"+ path.parent.mkdir(parents = True, exist_ok = True)+ with zipfile.ZipFile(path, "w") as archive:+ archive.writestr("in.png", _png((0, 0, 255)))+ return f"zip://in.png::{path}"++ name = _upload([{"image": {"bytes": None, "path": run_as(ALICE, own_zip)}, "text": "x"}])+ assert _check(name).preview_samples[0]["image"]["type"] == "image"++def test_managed_image_cell_with_embedded_bytes_still_previews():name = _upload([{"image": {"bytes": _png((0, 255, 0)), "path": None}, "text": "a cat"}])response = _check(name)diff --git a/studio/backend/utils/security/dataset_media.py b/studio/backend/utils/security/dataset_media.pyindex 6aa2e283a82..6a72cfb7b45 100644--- a/studio/backend/utils/security/dataset_media.py+++ b/studio/backend/utils/security/dataset_media.py@@ -102,6 +102,11 @@ def require_readable_media(path) -> None:_require_readable(str(path))+_READ_THROUGH_PROTOCOLS = frozenset(+ {"zip", "tar", "gzip", "bz2", "xz", "lz4", "zstd", "simplecache", "filecache", "blockcache"}+)++def _permitted_tokens(value, token_per_repo_id):"""The token mapping the decoder may use for ``value``; raises for a path the account may not read."""if isinstance(value, str):@@ -116,8 +121,11 @@ def _permitted_tokens(value, token_per_repo_id):from datasets.utils.file_utils import is_local_pathfrom datasets.utils.py_utils import string_to_dict- # A chained URL ("zip://inner::<outer>") reads the outer location.- source = path.split("::")[-1]+ # A chained URL ("zip://inner::<outer>") reads the outer location, but only an archive,+ # compression or cache hop reads through to the next one: `file://x::hf://...` opens x.+ *hops, source = path.split("::")+ if any(hop.split("://", 1)[0] not in _READ_THROUGH_PROTOCOLS for hop in hops):+ _refuse(path)if is_local_path(source):_require_readable(source)return token_per_repo_id