Skip to content

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.

Check the weight index of dot-named Sentence Transformers module folders (#14952)

Daniel Hanf172aec43737
diff --git a/studio/backend/tests/test_account_path_confinement.py b/studio/backend/tests/test_account_path_confinement.py
index ecc9e0ca94d..f6f429c5698 100644
--- a/studio/backend/tests/test_account_path_confinement.py
+++ b/studio/backend/tests/test_account_path_confinement.py
@@ -382,3 +382,43 @@ def test_a_module_at_the_model_root_is_not_flagged(tmp_path, path):
tmp_path / "st", {"modules.json": [{"idx": 0, "name": "0", "path": path, "type": "x"}]}
)
assert escaping_weight_references(folder) == []
+
+
+# "..." and "...." are ordinary folder names, not the model root: their index is read too.
+_DOT_NAMED_MODULE_PATHS = ["...", "./...", "..../", "....", "0_Transformer/..."]
+if os.name != "nt":
+ # On POSIX a backslash is part of the folder name, as Path(folder, sub) opens it.
+ _DOT_NAMED_MODULE_PATHS.append(".\\...")
+
+
[email protected]("path", _DOT_NAMED_MODULE_PATHS)
+def test_a_dot_named_module_folder_index_outside_the_model_is_flagged(tmp_path, path):
+ from utils.security.file_security import escaping_weight_references
+
+ folder = _write(
+ tmp_path / "st", {"modules.json": [{"idx": 0, "name": "0", "path": path, "type": "x"}]}
+ )
+ module = Path(folder, path)
+ depth = len(module.resolve().relative_to(folder.resolve()).parts)
+ victim = "../" * (depth + 1) + "victim/model.safetensors"
+ _write(module, {"model.safetensors.index.json": {"weight_map": {"w": victim}}})
+ assert escaping_weight_references(folder)
+ _write(module, {"model.safetensors.index.json": {"weight_map": {"w": "model.safetensors"}}})
+ assert escaping_weight_references(folder) == []
+
+
[email protected]("path", ["0_Transformer", ".", "./"])
+def test_a_normal_module_folder_keeps_its_verdict(tmp_path, path):
+ from utils.security.file_security import escaping_weight_references
+
+ folder = _write(
+ tmp_path / "st", {"modules.json": [{"idx": 0, "name": "0", "path": path, "type": "x"}]}
+ )
+ module = Path(folder, path)
+ _write(module, {"model.safetensors.index.json": {"weight_map": {"w": "model.safetensors"}}})
+ assert escaping_weight_references(folder) == []
+ _write(
+ module,
+ {"model.safetensors.index.json": {"weight_map": {"w": "../../victim/model.safetensors"}}},
+ )
+ assert escaping_weight_references(folder)
diff --git a/studio/backend/utils/security/file_security.py b/studio/backend/utils/security/file_security.py
index e9dc5966530..5d828892bea 100644
--- a/studio/backend/utils/security/file_security.py
+++ b/studio/backend/utils/security/file_security.py
@@ -139,9 +139,18 @@ def escaping_weight_references(folder) -> list:
if _escapes_folder(sub):
names.append(sub)
continue
- if not sub.strip("./\\"):
+ # Sentence Transformers opens Path(folder, sub): "\\" separates on Windows only, so judge
+ # both spellings. Only a path normalizing to "." is the model root; "..." is a real folder.
+ windows = sub.replace("\\", "/")
+ posix = "/".join(part.replace("\\", "_") for part in sub.split("/"))
+ spellings = {posixpath.normpath(p) for p in (windows, posix) if p} - {"."}
+ if any(_escapes_folder(spelled) for spelled in spellings):
+ names.append(sub)
continue
- names.extend(_in_subfolder(sub, name) for name in _weight_names(folder / sub))
+ if spellings:
+ module_names = _weight_names(folder / sub)
+ for spelled in spellings:
+ names.extend(_in_subfolder(spelled, name) for name in module_names)
# Spark-TTS / BiCodec load their transformers model from LLM/.
if (folder / "LLM").is_dir():
names.extend(_in_subfolder("LLM", name) for name in _weight_names(folder / "LLM"))