Scale computer-use 2.0 with open-source drivers, cross-OS sandboxes, and benchmarks for training, evaluation, and data generation.
Rust agentai-agentapplecomputer-usecomputer-use-agentcontainerizationcuadesktop-automationhacktoberfestlumemacosmanusoperatorswiftvirtualizationvirtualization-frameworkwindowswindows-sandbox
fix(cua-driver): scope bounded launch_app to resources.apps launch grants (#5690)
injaneity6012aa7e4700
diff --git a/docs/content/docs/cua-driver/guides/permissions.mdx b/docs/content/docs/cua-driver/guides/permissions.mdxindex 7b9436f927..b0528ac1cb 100644--- a/docs/content/docs/cua-driver/guides/permissions.mdx+++ b/docs/content/docs/cua-driver/guides/permissions.mdx@@ -116,6 +116,8 @@ resources:- Apps: `bundle_id` on macOS, an absolute `executable` on Windows and Linux.`terminate: driver_launched` only kills a process this runtime started.+ `launch_app` needs `launch: true` on a matching entry, and the call must name+ the app by that exact `bundle_id` or absolute path, not by display name.- Files: roots are compared by canonical path component; `recursive: false`allows direct children only.- `desktop.display: true` allows full-display capture and screen-coordinatediff --git a/libs/cua-driver/rust/crates/cua-driver-core/src/session_manifest.rs b/libs/cua-driver/rust/crates/cua-driver-core/src/session_manifest.rsindex 38546612bd..08394dfc62 100644--- a/libs/cua-driver/rust/crates/cua-driver-core/src/session_manifest.rs+++ b/libs/cua-driver/rust/crates/cua-driver-core/src/session_manifest.rs@@ -59,7 +59,6 @@ pub struct SessionManifest {struct ApplicationGrant {bundle_id: Option<String>,executable: Option<String>,- #[allow(dead_code)]launch: bool,all_windows: bool,terminate: TerminationGrant,@@ -148,11 +147,80 @@ impl SessionManifest {.ok_or_else(|| "bounded browser navigation requires url".to_owned())?;self.authorize_browser_url(url)?;}+ "launch_app" => self.authorize_launch(args)?,_ => {}}Ok(())}+ /// Admit a launch only when every identity the request names matches a+ /// `resources.apps` entry with `launch: true`. Platforms resolve these+ /// fields in different orders (Linux ignores `bundle_id`, Windows prefers+ /// `launch_path` and `path`), so each one present must pass on its own.+ /// A display name or command cannot be tied to an identity before the+ /// platform resolves it, so only exact bundle ids and absolute paths pass.+ fn authorize_launch(&self, args: &serde_json::Value) -> Result<(), String> {+ let mut identified = false;+ for field in ["bundle_id", "aumid", "name", "path", "launch_path"] {+ let Some(value) = args.get(field) else {+ continue;+ };+ let value = value+ .as_str()+ .map(str::trim)+ .filter(|value| !value.is_empty())+ .ok_or_else(|| format!("bounded launch requires {field} to be a string"))?;+ identified = true;+ let allowed = match field {+ "bundle_id" | "aumid" => self.launch_grant_for_bundle_id(value),+ _ => self.launch_grant_for_path(value),+ };+ if !allowed {+ return Err(format!(+ "launch_app {field} '{value}' is outside the capability manifest"+ ));+ }+ }+ if identified {+ Ok(())+ } else {+ Err("bounded launch requires a bundle_id or an absolute application path".to_owned())+ }+ }++ fn launch_grant_for_bundle_id(&self, bundle_id: &str) -> bool {+ self.applications.iter().any(|application| {+ application.launch+ && application.bundle_id.as_deref().is_some_and(|allowed| {+ !is_windows_path_identity(allowed) && allowed == bundle_id+ })+ })+ }++ fn launch_grant_for_path(&self, path: &str) -> bool {+ let windows_path = is_windows_path_identity(path)+ .then(|| normalize_windows_executable_path(path))+ .flatten();+ self.applications.iter().any(|application| {+ application.launch+ && (application+ .executable+ .as_deref()+ .is_some_and(|allowed| Path::new(path).is_absolute() && allowed == path)+ || windows_path.as_deref().is_some_and(|actual| {+ [+ application.bundle_id.as_deref(),+ application.executable.as_deref(),+ ]+ .into_iter()+ .flatten()+ .filter(|allowed| is_windows_path_identity(allowed))+ .filter_map(normalize_windows_executable_path)+ .any(|allowed| allowed == actual)+ }))+ })+ }+/// Validate a live top-level document after redirects and before input.pub fn authorize_browser_url(&self, raw: &str) -> Result<(), String> {let origin = canonical_origin(raw)?;@@ -1530,6 +1598,93 @@ ask:);}+ #[cfg(feature = "yaml")]+ #[test]+ fn launch_app_is_scoped_to_application_grants_with_launch() {+ let executable = std::fs::canonicalize(std::env::current_exe().unwrap()).unwrap();+ let executable = executable.to_string_lossy().into_owned();+ let loaded = manifest(&format!(+ r#"+version: 3+allow:+ tools: [launch_app]+resources:+ apps:+ - bundle_id: com.apple.TextEdit+ launch: true+ - bundle_id: com.apple.Preview+ launch: false+ - executable: {executable:?}+ launch: true+ - bundle_id: 'C:\Tools\viewer.exe'+ launch: true+"#+ ))+ .unwrap();+ let launch = |args: serde_json::Value| loaded.authorize_call("launch_app", &args);++ // Listed with launch: true.+ launch(serde_json::json!({"bundle_id": "com.apple.TextEdit"})).unwrap();+ launch(serde_json::json!({"name": executable})).unwrap();+ launch(serde_json::json!({"path": executable, "launch_path": executable})).unwrap();+ launch(serde_json::json!({"path": r"c:/TOOLS/Viewer.exe"})).unwrap();++ // Listed, but launch is not granted.+ assert_eq!(+ launch(serde_json::json!({"bundle_id": "com.apple.Preview"})).unwrap_err(),+ "launch_app bundle_id 'com.apple.Preview' is outside the capability manifest"+ );++ // Not listed, including identities that only resemble a grant.+ assert_eq!(+ launch(serde_json::json!({"bundle_id": "com.apple.calculator"})).unwrap_err(),+ "launch_app bundle_id 'com.apple.calculator' is outside the capability manifest"+ );+ assert_eq!(+ launch(serde_json::json!({"name": "Calculator"})).unwrap_err(),+ "launch_app name 'Calculator' is outside the capability manifest"+ );+ assert_eq!(+ launch(serde_json::json!({"aumid": r"C:\Tools\viewer.exe"})).unwrap_err(),+ r"launch_app aumid 'C:\Tools\viewer.exe' is outside the capability manifest"+ );+ assert_eq!(+ launch(serde_json::json!({"launch_path": format!("{executable} --flag")})).unwrap_err(),+ format!(+ "launch_app launch_path '{executable} --flag' is outside the capability manifest"+ )+ );++ // A granted identity does not admit a second, platform-preferred one.+ assert_eq!(+ launch(serde_json::json!({+ "bundle_id": "com.apple.TextEdit",+ "name": "gnome-calculator"+ }))+ .unwrap_err(),+ "launch_app name 'gnome-calculator' is outside the capability manifest"+ );++ // Missing or malformed identities fail closed.+ for args in [+ serde_json::json!({}),+ serde_json::json!({"urls": ["https://example.com"]}),+ ] {+ assert_eq!(+ launch(args).unwrap_err(),+ "bounded launch requires a bundle_id or an absolute application path"+ );+ }+ assert_eq!(+ launch(serde_json::json!({"bundle_id": " "})).unwrap_err(),+ "bounded launch requires bundle_id to be a string"+ );+ assert_eq!(+ launch(serde_json::json!({"bundle_id": 7})).unwrap_err(),+ "bounded launch requires bundle_id to be a string"+ );+ }+#[cfg(feature = "yaml")]#[test]fn version_three_lifetimes_are_enforced_when_declared() {diff --git a/libs/cua-driver/rust/crates/cua-driver-core/src/tool.rs b/libs/cua-driver/rust/crates/cua-driver-core/src/tool.rsindex e0576a2844..91c34d524f 100644--- a/libs/cua-driver/rust/crates/cua-driver-core/src/tool.rs+++ b/libs/cua-driver/rust/crates/cua-driver-core/src/tool.rs@@ -4385,6 +4385,51 @@ mod runtime_isolation_tests {}}+ #[tokio::test]+ async fn manifest_launch_reaches_the_platform_only_for_launchable_apps() {+ const MANIFEST: &str = "version: 3\nexpires_after: 1h\nidle_timeout: 30m\nresources:\n apps:\n - bundle_id: com.apple.TextEdit\n launch: true\n - bundle_id: com.apple.Preview\n launch: false\nallow:\n tools: [launch_app]\n";+ // A loaded manifest narrows every mode, so the launch grant applies to+ // standard and unrestricted runtimes as well as bounded ones.+ for mode in [+ PermissionMode::Bounded,+ PermissionMode::Standard,+ PermissionMode::Unrestricted,+ ] {+ for (bundle_id, expected_allowed) in [+ ("com.apple.TextEdit", true),+ ("com.apple.Preview", false),+ ("com.apple.calculator", false),+ ] {+ let hits = Arc::new(AtomicUsize::new(0));+ let registry = observation_registry_for("launch_app", None, hits.clone());+ let context = manifest_context(mode, MANIFEST);+ let result = registry+ .invoke_with_context(+ "launch_app",+ serde_json::json!({"bundle_id": bundle_id, "session": "review"}),+ context,+ )+ .await;+ assert_eq!(+ hits.load(Ordering::SeqCst),+ usize::from(expected_allowed),+ "{mode:?} {bundle_id}"+ );+ if expected_allowed {+ assert_ne!(result.is_error, Some(true));+ } else {+ let structured = result.structured_content.unwrap();+ assert_eq!(structured["refusal"]["code"], "permission_denied");+ let expected = format!(+ "Permission denied: launch_app bundle_id '{bundle_id}' {}",+ "is outside the capability manifest"+ );+ assert_eq!(structured["refusal"]["message"], expected, "{mode:?}");+ }+ }+ }+ }+#[tokio::test]async fn bounded_observation_uses_only_the_manifest_without_a_protected_host() {let hits = Arc::new(AtomicUsize::new(0));