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.

Studio: stop refusing C:\path\app.exe and dot-directory programs as the blocked command '.' (#13347)

Daniel Han6603095fb97a
diff --git a/studio/backend/core/inference/tools.py b/studio/backend/core/inference/tools.py
index 9ce71eb923a..869a68e15c4 100644
--- a/studio/backend/core/inference/tools.py
+++ b/studio/backend/core/inference/tools.py
@@ -1412,14 +1412,20 @@ def _blocked_word_re(assignment_prefixes: bool):
"""
if not _BLOCKED_COMMANDS:
return None
+ # `.` (source) is left to the token walk: here `\b` let it match only a dot glued to a word, never `source`, so
+ # `.venv/bin/python` and `C:/x/app.exe` were refused as `.` (#12054).
+ words = sorted(w for w in _BLOCKED_COMMANDS if w[:1].isalnum() or w[:1] == "_")
+ if not words:
+ return None
return re.compile(
# No `coproc` alternative here, deliberately: with no quoting or command-position context this pass refused
# `grep coproc rm file`. The token scan above knows where a command starts and handles the keyword.
r"(?:^|[;&|`\n(]\s*|[$]\(\s*|<\(\s*)"
+ (r"(?:[A-Za-z_]\w*=[^\s'\"]*\s+)*" if assignment_prefixes else r"")
- + r"(?:[\w./\\-]*/|[a-zA-Z]:[/\\][\w./\\-]*)?"
+ # Both prefixes end at a separator, so the name is a whole path segment.
+ + r"(?:[\w./\\-]*/|[a-zA-Z]:[/\\](?:[\w./\\-]*[/\\])?)?"
+ r"("
- + "|".join(re.escape(w) for w in sorted(_BLOCKED_COMMANDS))
+ + "|".join(re.escape(w) for w in words)
+ r")"
+ r"(?:\.(?:exe|com|bat|cmd))?\b"
)
diff --git a/studio/backend/tests/test_windows_bash_shell.py b/studio/backend/tests/test_windows_bash_shell.py
index 8f7cf094267..ebe2b28e46b 100644
--- a/studio/backend/tests/test_windows_bash_shell.py
+++ b/studio/backend/tests/test_windows_bash_shell.py
@@ -427,3 +427,53 @@ def test_a_program_path_is_not_read_as_a_cmd_switch(monkeypatch, _windows_blockl
# token as a flag, and never reach the shell name behind it.
assert not tools._CMD_SWITCH_RE.fullmatch("/bin/bash")
assert _screen_on_windows(monkeypatch, _WINDOWS_SHELLS[0], '/bin/bash -c "rm -rf x"') == {"rm"}
+
+
+def _windows_backstop(monkeypatch, _windows_blocklist):
+ # The command-position backstop is compiled from _BLOCKED_COMMANDS at import as well.
+ monkeypatch.setattr(tools, "_BLOCKED_WORD_RE", tools._blocked_word_re(False))
+ monkeypatch.setattr(tools, "_BLOCKED_WORD_RE_WITH_ASSIGNMENTS", tools._blocked_word_re(True))
+
+
[email protected]("bash", _WINDOWS_SHELLS)
+ "command",
+ [
+ # #12054: each was refused as "Blocked command(s) for safety: .".
+ r"C:\flutter\bin\flutter.bat create C:\src\my_app",
+ "C:/flutter/bin/flutter.bat create my_app",
+ r"C:\Python312\python.exe -m pip list",
+ "c:/tools/node.exe -v",
+ r"cd C:\src && D:\sdk\dart.exe --version",
+ r"C:\Users\me\.venv\Scripts\python.exe -m pip list",
+ r"C:\Users\me\.cargo\bin\cargo.exe build",
+ ".venv/bin/python -m pip list",
+ "ls; /home/me/.local/bin/tool",
+ ],
+)
+def test_an_absolute_windows_program_path_stays_runnable(
+ monkeypatch, bash, command, _windows_backstop
+):
+ assert not _screen_on_windows(monkeypatch, bash, command)
+
+
[email protected]("bash", _WINDOWS_SHELLS)
+ ("command", "expected"),
+ [
+ (r"C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -c ls", "powershell"),
+ ("C:/Windows/System32/WindowsPowerShell/v1.0/powershell.exe", "powershell"),
+ (r"C:\pwsh.exe -c ls", "pwsh"),
+ (r"echo hi; C:\tools\rm.exe -rf x", "rm"),
+ ],
+)
+def test_a_blocked_program_behind_a_drive_path_is_still_screened(
+ monkeypatch, bash, command, expected, _windows_backstop
+):
+ assert expected in _screen_on_windows(monkeypatch, bash, command)
+
+
[email protected]("command", ["echo hi; . script.sh", "x=$(. script.sh)", ". ./env.sh"])
+def test_dot_as_a_command_is_still_screened(monkeypatch, command, _windows_backstop):
+ assert "." in _screen_on_windows(monkeypatch, _WINDOWS_SHELLS[0], command)