Skip to content

Find the holes before someone else does. A fast, 100% Rust vulnerability scanner: XSS, SQL injection, leaked secrets, dependency CVEs and AI agent setups.

fix(agent): don't panic on an empty or non-ASCII npx argument (#63)

Manuel Gasparini1d6b6a0dcac1
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 237877c..e4c195e 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -2,6 +2,8 @@
## Unreleased
+- Agent: an MCP config whose `npx` (or `pnpm dlx`) argument is empty or starts with a non-ASCII
+ character no longer crashes the scan.
- Dependencies: `pubspec.lock` is read, so Dart and Flutter packages are checked against OSV.dev
(`Pub` ecosystem). Packages from the `sdk` source, like `flutter`, are skipped.
- Secrets: new rule `secret.gitlab-token` (critical) for GitLab personal access tokens (`glpat-` followed by 20 characters).
diff --git a/src/rules/agent.rs b/src/rules/agent.rs
index acfbc86..f2a6c0d 100644
--- a/src/rules/agent.rs
+++ b/src/rules/agent.rs
@@ -263,7 +263,7 @@ fn unpinned(argv: &[String]) -> Option<String> {
let rest = &argv[1..];
let positional = |skip: &[&str]| {
rest.iter()
- .find(|a| !a.starts_with('-') && !skip.contains(&a.as_str()))
+ .find(|a| !a.is_empty() && !a.starts_with('-') && !skip.contains(&a.as_str()))
.cloned()
};
match base {
@@ -275,7 +275,10 @@ fn unpinned(argv: &[String]) -> Option<String> {
if rest.first().map(String::as_str) == Some("dlx")
|| rest.first().map(String::as_str) == Some("x") =>
{
- let pkg = rest[1..].iter().find(|a| !a.starts_with('-')).cloned()?;
+ let pkg = rest[1..]
+ .iter()
+ .find(|a| !a.is_empty() && !a.starts_with('-'))
+ .cloned()?;
(!npm_pinned(&pkg)).then_some(pkg)
}
"uvx" | "pipx" => {
@@ -326,9 +329,13 @@ fn npm_pinned(pkg: &str) -> bool {
if pkg.starts_with('.') || pkg.starts_with('/') {
return true;
}
- match pkg[1..].rfind('@') {
+ // The first character is skipped so the `@` of a scope is not taken for a version.
+ let Some((start, _)) = pkg.char_indices().nth(1) else {
+ return false;
+ };
+ match pkg[start..].rfind('@') {
Some(i) => {
- let v = &pkg[i + 2..];
+ let v = &pkg[start + i + 1..];
!v.is_empty() && v != "latest" && v.chars().next().is_some_and(|c| c.is_ascii_digit())
}
None => false,
diff --git a/tests/fixtures/agent/.mcp.json b/tests/fixtures/agent/.mcp.json
index d9afb4c..0567855 100644
--- a/tests/fixtures/agent/.mcp.json
+++ b/tests/fixtures/agent/.mcp.json
@@ -17,6 +17,9 @@
"box": { "command": "docker", "args": ["run", "-i", "--rm", "acme/mcp"] },
"remote": { "url": "http://mcp.acme-tools.io/sse" },
"local": { "url": "http://localhost:3000/mcp" },
- "tls": { "url": "https://mcp.acme-tools.io/mcp" }
+ "tls": { "url": "https://mcp.acme-tools.io/mcp" },
+ "empty": { "command": "npx", "args": [""] },
+ "empty-dlx": { "command": "pnpm", "args": ["dlx", ""] },
+ "accent": { "command": "npx", "args": ["é@1.0.0"] }
}
}