Skip to content

armgit / cua

Public Imported from GitHub
0

Scale computer-use 2.0 with open-source drivers, cross-OS sandboxes, and benchmarks for training, evaluation, and data generation.

fix(cua-driver): reject misplaced MCP permission flags (#3085)

Francesco Bonaccia5bc2651c10d
diff --git a/.github/scripts/cua-driver-mcp-compat/verify.mjs b/.github/scripts/cua-driver-mcp-compat/verify.mjs
index 7ad9afb24a..205d50896f 100644
--- a/.github/scripts/cua-driver-mcp-compat/verify.mjs
+++ b/.github/scripts/cua-driver-mcp-compat/verify.mjs
@@ -27,10 +27,11 @@ const EXPECTED_OUTPUT_SCHEMA_COUNT =
const DRIVER_ARGS = [
"mcp",
"--direct",
- "--dangerously-bypass-approvals",
];
const PROBE_ENV = {
...process.env,
+ CUA_DRIVER_PERMISSION_MODE: "unrestricted",
+ CUA_DRIVER_DANGEROUSLY_BYPASS_APPROVALS: "1",
CUA_DRIVER_RS_TELEMETRY_ENABLED: "false",
CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC: "1",
DISABLE_AUTOUPDATER: "1",
diff --git a/libs/cua-driver/rust/crates/cua-driver/src/cli.rs b/libs/cua-driver/rust/crates/cua-driver/src/cli.rs
index e531ed13dc..665c42d176 100644
--- a/libs/cua-driver/rust/crates/cua-driver/src/cli.rs
+++ b/libs/cua-driver/rust/crates/cua-driver/src/cli.rs
@@ -233,6 +233,33 @@ const VALUE_FLAGS: &[&str] = &[
"--experimental-pip-geometry",
];
+/// Authorization selectors are trusted-daemon startup inputs. Direct MCP
+/// accepts their environment-variable equivalents, while a daemon-backed MCP
+/// client inherits the already-fixed profile through `--socket`. Silently
+/// consuming these flags on `mcp` would leave the default profile active while
+/// telling the operator nothing.
+const SERVE_ONLY_AUTHORIZATION_FLAGS: &[&str] = &[
+ "--permission-mode",
+ "--capability-manifest",
+ "--approve-capability-manifest",
+ "--session-policy",
+ "--approve-session-policy",
+ "--dangerously-bypass-approvals",
+ "--allow-legacy-existing-profile-approval",
+ "--no-permissions-gate",
+];
+
+fn serve_only_authorization_flag(args: &[String]) -> Option<&'static str> {
+ SERVE_ONLY_AUTHORIZATION_FLAGS.iter().copied().find(|flag| {
+ args.iter().any(|arg| {
+ arg == flag
+ || arg
+ .strip_prefix(flag)
+ .is_some_and(|remainder| remainder.starts_with('='))
+ })
+ })
+}
+
/// Classify the requested finite command without parsing its arguments. The
/// parent process uses this before `parse_command` so invalid JSON and other
/// parser exits are still observed as completed failures.
@@ -655,6 +682,15 @@ pub fn parse_command() -> Command {
}
}
+ if matches!(positionals.first().copied(), None | Some("mcp")) {
+ if let Some(flag) = serve_only_authorization_flag(&args) {
+ eprintln!("cua-driver mcp does not accept {flag}; authorization flags belong to `cua-driver serve`.");
+ eprintln!("For direct MCP, use CUA_DRIVER_PERMISSION_MODE and the related CUA_DRIVER_* environment variables.");
+ eprintln!("Otherwise start a configured daemon and connect with `cua-driver mcp --socket <path>`." );
+ process::exit(64);
+ }
+ }
+
let claude_code_compat = args
.iter()
.any(|a| a == "--claude-code-computer-use-compat");
diff --git a/libs/cua-driver/rust/crates/cua-driver/tests/permission_policy_startup_test.rs b/libs/cua-driver/rust/crates/cua-driver/tests/permission_policy_startup_test.rs
index e6b3007b9c..7dda802d8e 100644
--- a/libs/cua-driver/rust/crates/cua-driver/tests/permission_policy_startup_test.rs
+++ b/libs/cua-driver/rust/crates/cua-driver/tests/permission_policy_startup_test.rs
@@ -1,7 +1,7 @@
//! Explicit permission-policy configuration must fail before a daemon exposes
//! an action endpoint.
-use std::process::Command;
+use std::process::{Command, Stdio};
fn test_socket(directory: &tempfile::TempDir, suffix: &str) -> String {
#[cfg(unix)]
@@ -35,6 +35,74 @@ fn rejected_serve(socket: &str, extra_args: &[&str]) -> std::process::Output {
.expect("run rejected cua-driver serve configuration")
}
+#[test]
+fn mcp_rejects_serve_only_authorization_flags() {
+ let cases: &[(&[&str], &str)] = &[
+ (
+ &["mcp", "--direct", "--permission-mode", "bounded"],
+ "--permission-mode",
+ ),
+ (
+ &["mcp", "--capability-manifest", "unused.yaml"],
+ "--capability-manifest",
+ ),
+ (
+ &["mcp", "--approve-capability-manifest"],
+ "--approve-capability-manifest",
+ ),
+ (
+ &["mcp", "--dangerously-bypass-approvals"],
+ "--dangerously-bypass-approvals",
+ ),
+ (
+ &["mcp", "--session-policy", "unused.yaml"],
+ "--session-policy",
+ ),
+ (
+ &["mcp", "--approve-session-policy"],
+ "--approve-session-policy",
+ ),
+ (&["--permission-mode=bounded"], "--permission-mode"),
+ ];
+
+ for (args, rejected_flag) in cases {
+ let output = Command::new(env!("CARGO_BIN_EXE_cua-driver"))
+ .args(*args)
+ .stdin(Stdio::null())
+ .env("CUA_DRIVER_RS_TELEMETRY_ENABLED", "false")
+ .output()
+ .expect("run cua-driver mcp with a serve-only authorization flag");
+ assert_eq!(output.status.code(), Some(64), "args={args:?}");
+ let stderr = String::from_utf8_lossy(&output.stderr);
+ assert!(
+ stderr.contains(&format!("does not accept {rejected_flag}")),
+ "args={args:?}, stderr={stderr}"
+ );
+ assert!(
+ stderr.contains("CUA_DRIVER_PERMISSION_MODE"),
+ "args={args:?}, stderr={stderr}"
+ );
+ assert!(
+ stderr.contains("mcp --socket"),
+ "args={args:?}, stderr={stderr}"
+ );
+ }
+}
+
+#[test]
+fn direct_mcp_still_reads_permission_profile_from_environment() {
+ let output = Command::new(env!("CARGO_BIN_EXE_cua-driver"))
+ .args(["mcp", "--direct"])
+ .stdin(Stdio::null())
+ .env("CUA_DRIVER_PERMISSION_MODE", "bounded")
+ .env("CUA_DRIVER_RS_TELEMETRY_ENABLED", "false")
+ .output()
+ .expect("run direct MCP with bounded profile from the environment");
+
+ assert!(!output.status.success());
+ assert!(String::from_utf8_lossy(&output.stderr).contains("requires --capability-manifest"));
+}
+
#[test]
fn missing_configured_policy_prevents_daemon_startup() {
let directory = tempfile::tempdir().expect("temporary policy test directory");