Skip to content

Dodaios is an open-source agent OS for your desktop: it runs your coding agents, browser and apps by voice or chat, on your own machine. Formerly Personal Jarvis.

fix(security): check uvx options after --from and guard spaced or quoted diff names (#940)

Ruben Lütkef7f9de3b591d
diff --git a/dodaios/marketplace/agent_plugins_loader.py b/dodaios/marketplace/agent_plugins_loader.py
index 93aef5ef82..da42172691 100644
--- a/dodaios/marketplace/agent_plugins_loader.py
+++ b/dodaios/marketplace/agent_plugins_loader.py
@@ -341,6 +341,7 @@ def _validate_stdio_args(server: str, launcher: str, args: list[str]) -> None:
if launcher == "uvx":
index = 0
+ from_package = False
while index < len(args) and args[index].startswith("-"):
flag, sep, inline = args[index].partition("=")
if flag not in _UVX_FLAGS:
@@ -360,7 +361,15 @@ def _validate_stdio_args(server: str, launcher: str, args: list[str]) -> None:
f"{value!r} is not a pinned PyPI package — use "
"`--from my-mcp==1.2.0`, never a git ref, URL or path"
)
- # `--from` names the package; what follows is the entry point.
+ # `--from` names the package; the entry point follows. Keep
+ # checking: uv still reads options (`--with`, `--index-url`)
+ # placed between `--from` and that entry point.
+ from_package = True
+ if from_package:
+ if index >= len(args):
+ raise fail(
+ "uvx --from needs an entry point, e.g. `--from my-mcp==1.2.0 my-mcp`"
+ )
return
if index >= len(args):
raise fail("uvx needs a package to run, e.g. `uvx my-mcp==1.2.0`")
diff --git a/dodaios/missions/safety/path_guard.py b/dodaios/missions/safety/path_guard.py
index 9b0076fc9d..5be6fd473b 100644
--- a/dodaios/missions/safety/path_guard.py
+++ b/dodaios/missions/safety/path_guard.py
@@ -121,6 +121,112 @@ _DIFF_HEADER_RE: Final[re.Pattern[str]] = re.compile(
re.MULTILINE,
)
+# Git's C-style quoting for names holding tabs, quotes, backslashes,
+# control characters and (with core.quotePath) non-ASCII bytes.
+_C_ESCAPES: Final[dict[str, int]] = {
+ "a": 7, "b": 8, "t": 9, "n": 10, "v": 11, "f": 12, "r": 13, '"': 34, "\\": 92,
+}
+
+#: Lines after the header that name a file on their own, up to end of line.
+_NAME_LINE_PREFIXES: Final[tuple[tuple[str, bool], ...]] = (
+ # (prefix, strip a/ or b/)
+ ("--- ", True),
+ ("+++ ", True),
+ ("rename from ", False),
+ ("rename to ", False),
+ ("copy from ", False),
+ ("copy to ", False),
+)
+
+
+def _unquote_c(text: str) -> tuple[str, str]:
+ """Decode one C-quoted git name at the start of ``text``.
+
+ Returns ``(name, rest)``; ``text`` must start with a double quote.
+ """
+ out = bytearray()
+ index = 1
+ while index < len(text):
+ char = text[index]
+ if char == '"':
+ return out.decode("utf-8", "replace"), text[index + 1 :]
+ if char == "\\" and index + 1 < len(text):
+ nxt = text[index + 1]
+ octal = text[index + 1 : index + 4]
+ if len(octal) == 3 and all(c in "01234567" for c in octal):
+ out.append(int(octal, 8) & 0xFF)
+ index += 4
+ continue
+ out.append(_C_ESCAPES.get(nxt, ord(nxt) & 0xFF))
+ index += 2
+ continue
+ out.extend(char.encode("utf-8"))
+ index += 1
+ return out.decode("utf-8", "replace"), ""
+
+
+def _git_name(raw: str, *, strip_prefix: bool) -> str | None:
+ """One file name from a ``---``/``+++``/rename/copy line's remainder."""
+ raw = raw.rstrip("\r\n")
+ if raw.startswith('"'):
+ name, _rest = _unquote_c(raw)
+ else:
+ # Git ends an unquoted name that contains a space with a tab.
+ name = raw.split("\t", 1)[0]
+ if name == "/dev/null" or not name:
+ return None
+ if strip_prefix:
+ if name[:2] not in ("a/", "b/"):
+ return None
+ name = name[2:]
+ return name
+
+
+def _header_names(rest: str) -> list[str]:
+ """Both names from what follows ``diff --git `` (quoted, spaced or plain)."""
+ names: list[str] = []
+ if rest.startswith('"'):
+ first, tail = _unquote_c(rest)
+ names.append(first)
+ tail = tail.lstrip(" ")
+ if tail.startswith('"'):
+ names.append(_unquote_c(tail)[0])
+ else:
+ names.append(tail)
+ elif rest.endswith('"') and ' "' in rest:
+ split = rest.rindex(' "')
+ names.extend([rest[:split], _unquote_c(rest[split + 1 :])[0]])
+ else:
+ # Unquoted: `a/P b/P` when nothing was renamed (P may hold spaces);
+ # a rename with spaces also has `rename from/to` lines, read below.
+ half = (len(rest) - 1) // 2
+ if len(rest) % 2 == 1 and rest[half] == " " and rest[2:half] == rest[half + 3 :]:
+ names.extend([rest[:half], rest[half + 1 :]])
+ else:
+ names.extend(rest.split(" "))
+ return [name[2:] for name in names if name[:2] in ("a/", "b/")]
+
+
+def changed_diff_paths(diff_text: str) -> set[str]:
+ """Every file name a `git diff` names, in any of git's spellings.
+
+ Reads the ``diff --git`` header (plain, spaced or C-quoted), the
+ ``---``/``+++`` lines and ``rename``/``copy`` lines, so a name with a
+ space, a tab or non-ASCII bytes is still checked.
+ """
+ paths: set[str] = set()
+ for line in diff_text.splitlines():
+ if line.startswith("diff --git "):
+ paths.update(_header_names(line[len("diff --git ") :].rstrip()))
+ continue
+ for prefix, strip in _NAME_LINE_PREFIXES:
+ if line.startswith(prefix):
+ name = _git_name(line[len(prefix) :], strip_prefix=strip)
+ if name:
+ paths.add(name)
+ break
+ return paths
+
def filter_diff_paths(
diff_text: str,
@@ -145,6 +251,9 @@ def filter_diff_paths(
p = match.group(key)
if is_blocked(p, extra_globs=extra_globs):
paths.add(p)
+ for p in changed_diff_paths(diff_text):
+ if is_blocked(p, extra_globs=extra_globs):
+ paths.add(p)
return sorted(paths)
diff --git a/tests/missions/test_path_guard.py b/tests/missions/test_path_guard.py
index 514c3db741..6954051082 100644
--- a/tests/missions/test_path_guard.py
+++ b/tests/missions/test_path_guard.py
@@ -183,6 +183,53 @@ rename to new/.env
assert ".env" in [p.rsplit("/", 1)[-1] for p in blocked]
+ ("diff", "expected"),
+ [
+ # A space in the name: the header no longer splits on whitespace.
+ (
+ "diff --git a/my dir/.env b/my dir/.env\n"
+ "--- a/my dir/.env\t\n+++ b/my dir/.env\t\n@@ -1 +1 @@\n-a\n+b\n",
+ ["my dir/.env"],
+ ),
+ # An empty new file has no ---/+++ lines; only the spaced header.
+ (
+ "diff --git a/x y/.env b/x y/.env\nnew file mode 100644\n"
+ "index 0000000..e69de29\n",
+ ["x y/.env"],
+ ),
+ # C-quoted names (a tab, and octal non-ASCII bytes).
+ (
+ 'diff --git "a/k\\tey/id_rsa" "b/k\\tey/id_rsa"\nnew file mode 100600\n',
+ ["k\tey/id_rsa"],
+ ),
+ (
+ 'diff --git "a/caf\\303\\251/.env" "b/caf\\303\\251/.env"\n'
+ '--- /dev/null\n+++ "b/caf\\303\\251/.env"\n',
+ ["café/.env"],
+ ),
+ # A rename whose names hold spaces: read from the rename lines.
+ (
+ "diff --git a/notes one.txt b/keys dir/server.pem\n"
+ "similarity index 100%\n"
+ "rename from notes one.txt\nrename to keys dir/server.pem\n",
+ ["keys dir/server.pem"],
+ ),
+ ],
+)
+def test_filter_diff_reads_spaced_and_quoted_names(diff: str, expected: list[str]) -> None:
+ """Audit #353: a name git spells with spaces or quotes is still guarded."""
+ assert filter_diff_paths(diff) == expected
+
+
+def test_filter_diff_spaced_names_not_blocked_stay_clean() -> None:
+ diff = (
+ "diff --git a/my dir/readme.md b/my dir/readme.md\n"
+ "--- a/my dir/readme.md\t\n+++ b/my dir/readme.md\t\n"
+ )
+ assert filter_diff_paths(diff) == []
+
+
# --- check_prompt_for_blocked_paths ---
diff --git a/tests/unit/marketplace/test_agent_plugins_loader.py b/tests/unit/marketplace/test_agent_plugins_loader.py
index 900e3dba3b..9c0523b063 100644
--- a/tests/unit/marketplace/test_agent_plugins_loader.py
+++ b/tests/unit/marketplace/test_agent_plugins_loader.py
@@ -207,6 +207,14 @@ def test_unpinned_stdio_package_rejected() -> None:
("uvx", ["--with", "evil-pkg", "todofox-mcp==1.2.0"], "uvx option"),
("uvx", ["--from", "git+https://evil.example/x.git", "todofox"], "pinned"),
("uvx", ["--from=git+https://evil.example/x.git", "todofox"], "pinned"),
+ # Options after a pinned --from are still uv options, not the tool's.
+ ("uvx", ["--from", "todofox-mcp==1.2.0", "--with", "evil-pkg", "todofox"], "uvx option"),
+ (
+ "uvx",
+ ["--from", "todofox-mcp==1.2.0", "--index-url=https://evil.example/simple", "x"],
+ "uvx option",
+ ),
+ ("uvx", ["--from", "todofox-mcp==1.2.0"], "entry point"),
# A container that can read and write the user's whole machine.
("docker", ["run", "-v", "/:/host", "--privileged", "alpine:3.19"], "docker option"),
("docker", ["run", "--network=host", "todofox/mcp:1.2"], "docker option"),
@@ -233,6 +241,7 @@ def test_launcher_option_that_would_run_anything_is_rejected(
("npx", ["-y", "@todofox/[email protected]", "--verbose"]),
("uvx", ["todofox-mcp==1.2.0"]),
("uvx", ["--from", "todofox-mcp==1.2.0", "todofox-server"]),
+ ("uvx", ["--from=todofox-mcp==1.2.0", "todofox-server", "--verbose"]),
("docker", ["run", "-i", "--rm", "todofox/mcp:1.2.0"]),
("docker", ["run", "-i", "--rm", "-e", "TODOFOX_TOKEN", "todofox/mcp:1.2.0"]),
("docker", ["run", "--rm", f"todofox/mcp@sha256:{'a' * 64}"]),