Skip to content

The agent that grows with you

Port from aaif-goose/goose#11466: recognize Windows package-runner shims in OSV malware preflight

Tekniumf289aae1f55c
diff --git a/tests/tools/test_osv_check.py b/tests/tools/test_osv_check.py
index d136602f02d..2169456c2ab 100644
--- a/tests/tools/test_osv_check.py
+++ b/tests/tools/test_osv_check.py
@@ -23,6 +23,34 @@ class TestInferEcosystem:
assert _infer_ecosystem("/usr/bin/npx") == "npm"
+ def test_windows_shims(self):
+ # Real shim names installed by each runner on Windows
+ # (npm ships npx.cmd; uv ships uvx.exe; pip installs pipx.exe).
+ assert _infer_ecosystem("npx.cmd") == "npm"
+ assert _infer_ecosystem("NPX.CMD") == "npm"
+ assert _infer_ecosystem("uvx.exe") == "PyPI"
+ assert _infer_ecosystem("UVX.EXE") == "PyPI"
+ assert _infer_ecosystem("pipx.exe") == "PyPI"
+
+
+ def test_windows_paths_either_separator(self):
+ # Backslash paths must resolve even when the check runs on POSIX
+ # (config authored for Windows) — os.path.basename alone would not.
+ assert _infer_ecosystem(r"C:\Program Files\nodejs\npx.cmd") == "npm"
+ assert _infer_ecosystem("C:/Program Files/nodejs/nPx.CmD") == "npm"
+ assert _infer_ecosystem(r"C:\Users\u\.local\bin\UVX.EXE") == "PyPI"
+ assert _infer_ecosystem("C:/Users/u/.local/bin/uVx.ExE") == "PyPI"
+
+
+ def test_lookalikes_stay_fail_open(self):
+ # No broad suffix matching: only the shims each runner actually
+ # installs are recognized.
+ assert _infer_ecosystem("my-npx") is None
+ assert _infer_ecosystem("npx.exe") is None
+ assert _infer_ecosystem("npx.cmd.bak") is None
+ assert _infer_ecosystem("uvx.cmd.old") is None
+
+
def test_unknown(self):
assert _infer_ecosystem("node") is None
assert _infer_ecosystem("python") is None
diff --git a/tools/osv_check.py b/tools/osv_check.py
index e1e827ca3d2..49508e49d12 100644
--- a/tools/osv_check.py
+++ b/tools/osv_check.py
@@ -193,11 +193,17 @@ def check_package_for_malware(command: str, args: list) -> Optional[str]:
_ECOSYSTEM_BY_COMMAND = {
- "npx": "npm", "npx.cmd": "npm", "uvx": "PyPI", "uvx.cmd": "PyPI", "pipx": "PyPI"}
+ "npx": "npm", "npx.cmd": "npm",
+ "uvx": "PyPI", "uvx.cmd": "PyPI", "uvx.exe": "PyPI",
+ "pipx": "PyPI", "pipx.exe": "PyPI",
+}
def _infer_ecosystem(command: str) -> Optional[str]:
- return _ECOSYSTEM_BY_COMMAND.get(os.path.basename(command).lower())
+ # Split on BOTH separators: os.path.basename leaves ``C:\...\uvx.exe`` intact on POSIX
+ # (config authored for Windows) and the preflight would silently skip. Only the shim
+ # names each runner actually installs are listed; lookalikes stay fail-open.
+ return _ECOSYSTEM_BY_COMMAND.get(re.split(r"[\\/]", command)[-1].lower())
def _parse_package_from_args(args: list, ecosystem: str) -> Tuple[Optional[str], Optional[str]]: