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 take PATH, AUTHOR or MONKEY for an MCP secret key (#77)

Onur Ugurd41d5607a17f
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 35fbcf3..01a2bca 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -10,6 +10,10 @@
`$POSTGRES_PASSWORD`) is skipped.
- Agent: an MCP config whose `npx` (or `pnpm dlx`) argument is empty or starts with a non-ASCII
character no longer crashes the scan.
+- Agent: `agent.mcp-plaintext-secret` no longer takes an env key for a secret when its credential word is
+ only part of an ordinary word, so `PATH`, `PYTHONPATH`, `NODE_PATH`, `DISPATCH_MODE`, `AUTHOR`,
+ `MONKEY_PATCH` and `KEYCHAIN_PROFILE` are not reported. `GITHUB_PAT`, `githubPat`, `OPENAI_APIKEY`,
+ `daemonKey`, `patHash` and `clientSecret` still are.
- 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 b15e0a0..dda8b58 100644
--- a/src/rules/agent.rs
+++ b/src/rules/agent.rs
@@ -240,21 +240,7 @@ fn check_server(
};
for (k, v) in env {
let Some(v) = v.as_str() else { continue };
- let secretish = {
- let k = k.to_ascii_lowercase();
- [
- "token",
- "key",
- "secret",
- "password",
- "pat",
- "auth",
- "credential",
- ]
- .iter()
- .any(|s| k.contains(s))
- };
- if secretish
+ if secret_like_key(k)
&& v.len() >= 8
&& !v.starts_with('$')
&& !v.starts_with('<')
@@ -303,6 +289,86 @@ fn check_server(
}
}
+/// Whether an env key names a credential. Each part of the key (split at every character that
+/// is not a letter or digit) is searched for the credential words, as before, except where the
+/// word only shows up as part of an ordinary one: a part that starts with `monkey`, `keyboard`
+/// or `author`, and `pat` in `path`, `patch` or `compat`. A camelCase word of its own always
+/// counts. So `PATH`, `DISPATCH_MODE`, `AUTHOR` and `MONKEY_PATCH` don't count, and
+/// `daemonKey`, `patHash`, `GITHUB_PAT` and `PATv2` do.
+fn secret_like_key(key: &str) -> bool {
+ // Found anywhere in a part, as on main: these don't hide inside ordinary words.
+ const ANYWHERE: &[&str] = &["token", "secret", "password", "credential"];
+ // Ordinary words that start a part and contain `key` or `auth`. Only taken out at the start,
+ // so `snapshotKey` and `apiKeyChain` still count.
+ const NOT_KEY: &[&str] = &[
+ "monkey",
+ "donkey",
+ "turkey",
+ "hockey",
+ "jockey",
+ "whiskey",
+ "lackey",
+ "latchkey",
+ "keychain",
+ "keyboard",
+ "keynote",
+ "keyword",
+ "keystroke",
+ ];
+ const NOT_AUTH: &[&str] = &["authority", "authorities", "authors", "author"];
+ let after_word = |part: &str, words: &[&str]| -> String {
+ let rest = words
+ .iter()
+ .find_map(|w| part.strip_prefix(w))
+ .unwrap_or(part);
+ rest.to_string()
+ };
+ key.split(|c: char| !c.is_alphanumeric())
+ .filter(|part| !part.is_empty())
+ .any(|original| {
+ let part = original.to_lowercase();
+ let part = part.as_str();
+ // `hotKey`, `patHash`, `gitlabComPat`: a camelCase word that is the credential word.
+ let camel = camel_words(original);
+ camel.iter().any(|w| {
+ let w = w.strip_suffix('s').unwrap_or(w);
+ matches!(w, "key" | "pat" | "auth")
+ }) || ANYWHERE.iter().any(|w| part.contains(w))
+ || after_word(part, NOT_KEY).contains("key")
+ // `authorization` and `authentication` start like `author` but are credentials.
+ || ["authoriz", "authoris", "authent"]
+ .iter()
+ .any(|w| part.contains(w))
+ || after_word(part, NOT_AUTH).contains("auth")
+ || pat_word(part)
+ })
+}
+
+/// The lower-case words of a camelCase part: `githubPatHash` gives `github`, `pat`, `hash`. A
+/// part with no lower-to-upper change (`GITHUBPAT`, `pythonpath`) is one word.
+fn camel_words(part: &str) -> Vec<String> {
+ let mut words = vec![String::new()];
+ let mut prev_lower = false;
+ for c in part.chars() {
+ if c.is_uppercase() && prev_lower {
+ words.push(String::new());
+ }
+ prev_lower = c.is_lowercase() || c.is_ascii_digit();
+ words.last_mut().unwrap().extend(c.to_lowercase());
+ }
+ words
+}
+
+/// Whether a lower-case part has `pat` other than inside `path`, `patch`, `pattern`, `patient`,
+/// `patron`, `patio`, `patent`, `spatial`, `spatula` or `compat`.
+fn pat_word(part: &str) -> bool {
+ const NOT_AFTER: &[&str] = &["h", "ch", "tern", "ien", "ron", "io", "ent", "ial", "ula"];
+ part.match_indices("pat").any(|(i, _)| {
+ let after = &part[i + 3..];
+ !part[..i].ends_with("com") && !NOT_AFTER.iter().any(|w| after.starts_with(w))
+ })
+}
+
fn unpinned(argv: &[String]) -> Option<String> {
let cmd = argv.first()?;
let base = cmd
diff --git a/tests/cli.rs b/tests/cli.rs
index db355ef..e0813d1 100644
--- a/tests/cli.rs
+++ b/tests/cli.rs
@@ -45,7 +45,16 @@ fn terminal_report_shows_file_line_rule_and_fix() {
assert!(out.contains(".mcp.json:5"), "{out}");
assert!(out.contains("agent.mcp-unpinned"), "{out}");
assert!(out.contains("Pin an exact version"), "{out}");
- assert!(out.contains("18 findings"), "{out}");
+ let expected = std::fs::read_to_string(Path::new(&fixture("agent")).join("EXPECTED"))
+ .unwrap()
+ .lines()
+ .filter(|l| !l.trim().is_empty() && !l.starts_with('#'))
+ .count();
+ assert!(
+ out.lines()
+ .any(|l| l.starts_with(&format!("{expected} findings"))),
+ "{out}"
+ );
}
#[test]
diff --git a/tests/fixtures/agent/.mcp.json b/tests/fixtures/agent/.mcp.json
index 0567855..59f77c3 100644
--- a/tests/fixtures/agent/.mcp.json
+++ b/tests/fixtures/agent/.mcp.json
@@ -20,6 +20,38 @@
"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"] }
+ "accent": { "command": "npx", "args": ["é@1.0.0"] },
+ "local-tool": {
+ "command": "/opt/tools/bin/local-mcp",
+ "env": {
+ "PATH": "/usr/local/bin:/usr/bin:/bin",
+ "PYTHONPATH": "/opt/tools/lib",
+ "NODE_PATH": "/opt/tools/node_modules",
+ "DISPATCH_MODE": "round-robin",
+ "AUTHOR": "Jane Example",
+ "MONKEY_PATCH": "enabled-always",
+ "KEYCHAIN_PROFILE": "default-profile",
+ "TURKEY_REGION": "europe-west-1",
+ "COMPAT_MODE": "legacy-v1-mode",
+ "PATTERN_FILE": "/opt/tools/patterns.txt"
+ }
+ },
+ "gh-pat": {
+ "command": "/opt/tools/bin/gh-mcp",
+ "env": {
+ "GITHUB_PAT": "EXAMPLE_NOT_A_REAL_PAT_VALUE",
+ "githubPat": "EXAMPLE_NOT_A_REAL_PAT_VALUE",
+ "OPENAI_APIKEY": "EXAMPLE_NOT_A_REAL_KEY_VALUE",
+ "clientSecret": "EXAMPLE_NOT_A_REAL_SECRET",
+ "BASIC_AUTH": "EXAMPLE_NOT_A_REAL_AUTH",
+ "API_KEY1": "EXAMPLE_NOT_A_REAL_KEY_VALUE",
+ "SSHKEY": "EXAMPLE_NOT_A_REAL_KEY_VALUE",
+ "GITHUB_OAUTH": "EXAMPLE_NOT_A_REAL_TOKEN",
+ "APIKEYVALUE": "EXAMPLE_NOT_A_REAL_KEY_VALUE",
+ "dbPassWord": "EXAMPLE_NOT_A_REAL_PASSWORD",
+ "daemonKey": "EXAMPLE_NOT_A_REAL_KEY_VALUE",
+ "GITHUBPATVALUE": "EXAMPLE_NOT_A_REAL_PAT_VALUE"
+ }
+ }
}
}
diff --git a/tests/fixtures/agent/EXPECTED b/tests/fixtures/agent/EXPECTED
index 9522a4b..505a328 100644
--- a/tests/fixtures/agent/EXPECTED
+++ b/tests/fixtures/agent/EXPECTED
@@ -11,6 +11,18 @@
.mcp.json:15 agent.mcp-unpinned
.mcp.json:17 agent.mcp-unpinned
.mcp.json:18 agent.mcp-insecure-url
+.mcp.json:42 agent.mcp-plaintext-secret
+.mcp.json:43 agent.mcp-plaintext-secret
+.mcp.json:44 agent.mcp-plaintext-secret
+.mcp.json:45 agent.mcp-plaintext-secret
+.mcp.json:46 agent.mcp-plaintext-secret
+.mcp.json:47 agent.mcp-plaintext-secret
+.mcp.json:48 agent.mcp-plaintext-secret
+.mcp.json:49 agent.mcp-plaintext-secret
+.mcp.json:50 agent.mcp-plaintext-secret
+.mcp.json:51 agent.mcp-plaintext-secret
+.mcp.json:52 agent.mcp-plaintext-secret
+.mcp.json:53 agent.mcp-plaintext-secret
.mcp.json:5 agent.mcp-unpinned
.mcp.json:7 agent.mcp-plaintext-secret
.mcp.json:7 secret.github-token