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): check httpUrl, ws:// and userinfo in agent.mcp-insecure-url (#235)

Brixton Pham8fb2be7a3008
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 22d05f4..0dbc7b6 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -2,6 +2,10 @@
## Unreleased
+- Agent: `agent.mcp-insecure-url` now also checks Gemini CLI's `httpUrl` field and plain
+ WebSocket (`ws://`) URLs, strips RFC 3986 userinfo (`user:pass@`) before checking the host so
+ URLs like `http://localhost:[email protected]` and `http://[::1]@evil.example` do not look local,
+ and treats `localhost` case-insensitively and before `?` or `#`.
- Config: `config.remote-script` now reports a download piped into a shell that is named by its
path or started through `env` (`| /bin/bash`, `| /usr/bin/env bash`, `| env sh`), including
`sudo /bin/bash`.
diff --git a/docs/rules.md b/docs/rules.md
index a517869..eb3220d 100644
--- a/docs/rules.md
+++ b/docs/rules.md
@@ -97,7 +97,7 @@ Every rule safe-anything checks, generated from `safe-anything --list-rules --js
| [`agent.unrestricted-shell`](https://genai.owasp.org/llmrisk/llm062025-excessive-agency/) | high | [CWE-250](https://cwe.mitre.org/data/definitions/250.html) | LLM06:2025 Excessive Agency | Every shell command is pre-approved, so the agent can run anything without asking. |
| [`agent.mcp-unpinned`](https://genai.owasp.org/llmrisk/llm032025-supply-chain/) | medium | [CWE-1357](https://cwe.mitre.org/data/definitions/1357.html) | LLM03:2025 Supply Chain | An MCP server is started from a package or image with no pinned version. |
| [`agent.mcp-plaintext-secret`](https://cheatsheetseries.owasp.org/cheatsheets/Secrets_Management_Cheat_Sheet.html) | high | [CWE-798](https://cwe.mitre.org/data/definitions/798.html) | LLM02:2025 Sensitive Information Disclosure | An MCP server's token or key is written in plain text in the config. |
-| [`agent.mcp-insecure-url`](https://cheatsheetseries.owasp.org/cheatsheets/Transport_Layer_Security_Cheat_Sheet.html) | high | [CWE-319](https://cwe.mitre.org/data/definitions/319.html) | A02:2021 Cryptographic Failures | A remote MCP server is reached over plain HTTP. |
+| [`agent.mcp-insecure-url`](https://cheatsheetseries.owasp.org/cheatsheets/Transport_Layer_Security_Cheat_Sheet.html) | high | [CWE-319](https://cwe.mitre.org/data/definitions/319.html) | A02:2021 Cryptographic Failures | A remote MCP server is reached over plain HTTP or WebSocket. |
## Mobile (9)
diff --git a/src/rules/agent.rs b/src/rules/agent.rs
index 9a5d071..98f1550 100644
--- a/src/rules/agent.rs
+++ b/src/rules/agent.rs
@@ -1,5 +1,6 @@
use std::borrow::Cow;
use std::collections::HashMap;
+use std::net::Ipv6Addr;
use serde_json::Value;
@@ -162,7 +163,7 @@ pub static STRUCTURED: &[(&str, Severity, &str, &str)] = &[
(
"agent.mcp-insecure-url",
Severity::High,
- "A remote MCP server is reached over plain HTTP.",
+ "A remote MCP server is reached over plain HTTP or WebSocket.",
INSECURE_URL_FIX,
),
];
@@ -171,7 +172,8 @@ const SHELL_FIX: &str = "Allow specific commands, for example \"Bash(npm test:*)
const UNPINNED_FIX: &str =
"Pin an exact version ([email protected], pkg==1.2.3, or an image digest) and update on purpose.";
const PLAINTEXT_FIX: &str = "Reference an environment variable (\"${VAR}\") and keep the value out of files that get shared or committed.";
-const INSECURE_URL_FIX: &str = "Use https:// for every MCP server that is not on this machine.";
+const INSECURE_URL_FIX: &str =
+ "Use https:// or wss:// for every MCP server that is not on this machine.";
/// Where a plaintext MCP secret sits in the source so `rules::check` can mask both the raw JSON
/// string (including escapes like `\/`, `\uXXXX`, `\"` or split lines) and any plain copy of the
@@ -306,6 +308,9 @@ fn check_server(
None,
));
}
+ let server_keys = value_object(text.src, start)
+ .map(|at| object_keys(text.src, at))
+ .unwrap_or_default();
// Local servers get credentials in `env`; remote ones in `headers` (`http_headers` is Codex's
// name for it).
for (field, header) in [
@@ -319,8 +324,9 @@ fn check_server(
};
// Find each key inside its own object, so the same name in `args`, in `env` or as a value
// does not take its line.
- let field_keys = value_object(text.src, start)
- .and_then(|at| object_keys(text.src, at).get(field).copied())
+ let field_keys = server_keys
+ .get(field)
+ .copied()
.and_then(|at| value_object(text.src, at))
.map(|at| object_keys(text.src, at))
.unwrap_or_default();
@@ -377,40 +383,91 @@ fn check_server(
}
}
}
- if let Some(url) = server
- .get("url")
- .or_else(|| server.get("serverUrl"))
- .and_then(Value::as_str)
- && let Some(rest) = url
- .get(..7)
- .filter(|prefix| prefix.eq_ignore_ascii_case("http://"))
- .map(|_| &url[7..])
- {
- let host = match rest.find(']') {
- Some(end) if rest.starts_with('[') => &rest[..end + 1],
- _ => rest.split(['/', ':']).next().unwrap_or(""),
+ // `url` is standard, `serverUrl` is Windsurf's key, and `httpUrl` is Gemini CLI's Streamable
+ // HTTP key. Check all of them so an insecure `httpUrl` is not hidden behind an `https://` `url`.
+ for field in ["url", "serverUrl", "httpUrl"] {
+ let Some(url) = server.get(field).and_then(Value::as_str) else {
+ continue;
};
- if !matches!(host, "localhost" | "127.0.0.1" | "[::1]") {
- let line = line_after(text, start, url);
- out.push((
- finding(
- file,
- text,
- line,
- Meta {
- id: "agent.mcp-insecure-url",
- family: Family::Agent,
- severity: Severity::High,
- message: "A remote MCP server is reached over plain HTTP, so its tools and your data can be read or changed on the way.",
- fix: INSECURE_URL_FIX,
- },
- ),
- None,
- ));
- }
+ let Some(scheme) = insecure_remote_scheme(url) else {
+ continue;
+ };
+ let line = server_keys
+ .get(field)
+ .copied()
+ .map_or_else(|| line_after(text, start, url), |at| text.line_of(at));
+ let (message, fix) = match scheme {
+ "ws" => (
+ "A remote MCP server is reached over plain WebSocket (ws://), so its tools and your data can be read or changed on the way.",
+ "Use wss:// for every MCP server that is not on this machine.",
+ ),
+ _ => (
+ "A remote MCP server is reached over plain HTTP, so its tools and your data can be read or changed on the way.",
+ "Use https:// for every MCP server that is not on this machine.",
+ ),
+ };
+ out.push((
+ finding(
+ file,
+ text,
+ line,
+ Meta {
+ id: "agent.mcp-insecure-url",
+ family: Family::Agent,
+ severity: Severity::High,
+ message,
+ fix,
+ },
+ ),
+ None,
+ ));
}
}
+/// Returns `"http"` or `"ws"` when `url` uses plain `http://` or `ws://` for a host other than
+/// `localhost`, `127.0.0.1` or `[::1]`. Strips RFC 3986 authority userinfo (`user:pass@`) and
+/// requires both RFC 3986 (`/`, `?`, `#`) and WHATWG (`/` , `\`, `?`, `#`) authority boundaries to
+/// resolve to a local host, so `http://localhost:[email protected]`, `http://[::1]@evil.example`,
+/// `http://evil.example\@localhost/mcp` and `http://localhost\@evil.example/mcp` do not look local.
+fn insecure_remote_scheme(url: &str) -> Option<&'static str> {
+ let (scheme, rest) = if let Some(rest) = url
+ .get(..7)
+ .filter(|prefix| prefix.eq_ignore_ascii_case("http://"))
+ .map(|_| &url[7..])
+ {
+ ("http", rest)
+ } else {
+ let rest = url
+ .get(..5)
+ .filter(|prefix| prefix.eq_ignore_ascii_case("ws://"))
+ .map(|_| &url[5..])?;
+ ("ws", rest)
+ };
+ let authority_rfc = rest.split(['/', '?', '#']).next().unwrap_or("");
+ let authority_whatwg = rest.split(['/', '\\', '?', '#']).next().unwrap_or("");
+ let local = is_local_authority(authority_rfc) && is_local_authority(authority_whatwg);
+ (!local).then_some(scheme)
+}
+
+fn is_local_authority(authority: &str) -> bool {
+ let hostport = authority.rsplit('@').next().unwrap_or(authority);
+ let host = match hostport.find(']') {
+ Some(end)
+ if hostport.starts_with('[')
+ && (hostport[end + 1..].is_empty() || hostport[end + 1..].starts_with(':')) =>
+ {
+ &hostport[..end + 1]
+ }
+ _ => hostport.split(':').next().unwrap_or(""),
+ };
+ let ipv6_loopback = host
+ .strip_prefix('[')
+ .and_then(|s| s.strip_suffix(']'))
+ .and_then(|ip| ip.parse::<Ipv6Addr>().ok())
+ .is_some_and(|ip| ip.is_loopback());
+ host.eq_ignore_ascii_case("localhost") || host == "127.0.0.1" || ipv6_loopback
+}
+
/// Whether a value points at a credential kept elsewhere instead of holding one. After the auth
/// scheme (`Bearer`, `Basic`, ...): it starts with `$` or `<`, or what is left once every
/// `${VAR}` and `{env:VAR}` is taken out is shorter than 8 characters. So `Bearer ${TOKEN}`,
@@ -1124,4 +1181,45 @@ mod tests {
.all(|(f, _)| f.rule == "agent.unrestricted-shell")
);
}
+
+ #[test]
+ fn mcp_insecure_url_checks_http_url_ws_and_authority_parsing() {
+ let gemini = FileInfo::new(".gemini/settings.json");
+ let cfg = r#"{
+ "mcpServers": {
+ "gemini-http": { "httpUrl": "http://mcp.example.net/mcp" },
+ "gemini-both": { "url": "https://mcp.example.net/sse", "httpUrl": "http://mcp.example.net/mcp" },
+ "ws-remote": { "url": "ws://mcp.example.net/ws" },
+ "ws-upper": { "serverUrl": "WS://203.0.113.5:8080/ws" },
+ "userinfo-localhost": { "url": "http://localhost:[email protected]/mcp" },
+ "userinfo-ipv4": { "url": "http://127.0.0.1:[email protected]/mcp" },
+ "userinfo-ipv6": { "url": "http://[::1]@mcp.example.net/mcp" },
+ "ipv6-trailing": { "url": "http://[::1]evil.example/mcp" },
+ "backslash-whatwg": { "url": "http://mcp.example.net\\@localhost/mcp" },
+ "backslash-rfc": { "url": "http://localhost\\@mcp.example.net/mcp" },
+ "ipv4-mapped-loopback": { "url": "http://[::ffff:127.0.0.1]:8080/mcp" },
+ "local-upper": { "httpUrl": "http://LOCALHOST:3000/mcp" },
+ "local-query": { "url": "http://localhost?debug=1" },
+ "local-v6-expanded": { "url": "http://[0:0:0:0:0:0:0:1]:8080/mcp" },
+ "local-v6-padded": { "url": "http://[0000::0001]:8080/mcp" },
+ "ws-local": { "url": "ws://localhost:3000/ws" },
+ "ws-local-v4": { "url": "ws://127.0.0.1:3000/ws" },
+ "ws-local-v6": { "url": "ws://[::1]:3000/ws" },
+ "wss-remote": { "url": "wss://mcp.example.net/ws" },
+ "https-remote": { "httpUrl": "https://mcp.example.net/mcp" },
+ "utf8-short": { "url": "ééé" }
+ }
+}"#;
+ let findings = structured(&gemini, &Text::new(cfg));
+ let mut lines: Vec<usize> = findings.iter().map(|(f, _)| f.line).collect();
+ lines.sort_unstable();
+ assert_eq!(lines, vec![3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]);
+ assert!(
+ findings
+ .iter()
+ .all(|(f, _)| f.rule == "agent.mcp-insecure-url")
+ );
+ let ws = findings.iter().find(|(f, _)| f.line == 5).unwrap();
+ assert!(ws.0.fix.contains("wss://"), "{}", ws.0.fix);
+ }
}
diff --git a/tests/fixtures/agent/.gemini/settings.json b/tests/fixtures/agent/.gemini/settings.json
new file mode 100644
index 0000000..aadf2a1
--- /dev/null
+++ b/tests/fixtures/agent/.gemini/settings.json
@@ -0,0 +1,7 @@
+{
+ "mcpServers": {
+ "remote-http": { "httpUrl": "http://mcp.acme-tools.io/mcp" },
+ "remote-https": { "httpUrl": "https://mcp.acme-tools.io/mcp" },
+ "local-http": { "httpUrl": "http://localhost:3000/mcp" }
+ }
+}
diff --git a/tests/fixtures/agent/.mcp.json b/tests/fixtures/agent/.mcp.json
index 82247ab..7e43b68 100644
--- a/tests/fixtures/agent/.mcp.json
+++ b/tests/fixtures/agent/.mcp.json
@@ -88,6 +88,12 @@
},
"mapped": { "type": "http", "url": "http://[::ffff:203.0.113.5]:8080/mcp" },
"upper": { "type": "http", "url": "HTTP://203.0.113.5/mcp" },
- "local-v6": { "type": "http", "url": "http://[::1]:8080/mcp" }
+ "local-v6": { "type": "http", "url": "http://[::1]:8080/mcp" },
+ "local-v6-expanded": { "type": "http", "url": "http://[0:0:0:0:0:0:0:1]:8080/mcp" },
+ "local-upper": { "type": "http", "url": "http://LOCALHOST:3000/mcp" },
+ "ws-remote": { "url": "ws://mcp.acme-tools.io/ws" },
+ "ws-local": { "url": "ws://localhost:3000/ws" },
+ "wss-remote": { "url": "wss://mcp.acme-tools.io/ws" },
+ "userinfo-bypass": { "url": "http://[::1]@mcp.acme-tools.io/mcp" }
}
}
diff --git a/tests/fixtures/agent/EXPECTED b/tests/fixtures/agent/EXPECTED
index d260917..0a11118 100644
--- a/tests/fixtures/agent/EXPECTED
+++ b/tests/fixtures/agent/EXPECTED
@@ -63,3 +63,6 @@ cline_mcp_settings.json:4 agent.mcp-insecure-url
.config/zed/settings.json:8 agent.mcp-unpinned
.mcp.json:89 agent.mcp-insecure-url
.mcp.json:90 agent.mcp-insecure-url
+.mcp.json:94 agent.mcp-insecure-url
+.mcp.json:97 agent.mcp-insecure-url
+.gemini/settings.json:3 agent.mcp-insecure-url