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(teleport): read Chrome cookies WAL-safely and explain v20 (#4438)
ddupont6fbcdf97b6ed
diff --git a/libs/cua/crates/cua-teleport/src/browser_cookies.rs b/libs/cua/crates/cua-teleport/src/browser_cookies.rsindex b4b9a65b55..2a5acdacae 100644--- a/libs/cua/crates/cua-teleport/src/browser_cookies.rs+++ b/libs/cua/crates/cua-teleport/src/browser_cookies.rs@@ -257,7 +257,7 @@ fn read_rows(db: &Path) -> Result<Vec<Row>, TeleportError> {let result = (|| -> rusqlite::Result<Vec<Row>> {let conn = rusqlite::Connection::open_with_flags(tmp.path(),- rusqlite::OpenFlags::SQLITE_OPEN_READ_ONLY,+ rusqlite::OpenFlags::SQLITE_OPEN_READ_WRITE,)?;let mut stmt = conn.prepare("SELECT host_key, name, value, encrypted_value, path, expires_utc, is_secure, \@@ -292,13 +292,19 @@ impl TempCopy {impl Drop for TempCopy {fn drop(&mut self) {- let _ = std::fs::remove_file(&self.0);+ // The private directory holds the copy and its journal sidecars.if let Some(dir) = self.0.parent() {- let _ = std::fs::remove_dir(dir);+ let _ = std::fs::remove_dir_all(dir);}}}+/// Copies `src` and its `-wal`, `-shm` and `-journal` sidecars to a private+/// directory. Chrome may be running: a WAL-mode database keeps recent commits+/// only in `-wal`, and a rollback-journal database mid-write has a hot+/// `-journal`; copying the main file alone would miss or tear them. SQLite+/// replays/rolls back the sidecars on open, so the copy reads as a consistent+/// snapshot while the original is never opened, locked or modified.fn tempfile_copy(src: &Path) -> Result<TempCopy, TeleportError> {let dir = std::env::temp_dir().join(format!("cua-cookies-{:016x}", rand::random::<u64>()));std::fs::create_dir(&dir)@@ -309,8 +315,18 @@ fn tempfile_copy(src: &Path) -> Result<TempCopy, TeleportError> {let _ = std::fs::set_permissions(&dir, std::fs::Permissions::from_mode(0o700));}let dst = dir.join("Cookies");+ // Sidecars first: a checkpoint between the two copies then only makes the+ // main file newer than the log, which replays idempotently.+ for suffix in ["-wal", "-shm", "-journal"] {+ let mut from = src.as_os_str().to_owned();+ from.push(suffix);+ let from = PathBuf::from(from);+ if from.is_file() {+ let _ = std::fs::copy(&from, dir.join(format!("Cookies{suffix}")));+ }+ }std::fs::copy(src, &dst).map_err(|e| {- let _ = std::fs::remove_dir(&dir);+ let _ = std::fs::remove_dir_all(&dir);TeleportError::Provider(format!("copying Cookies failed: {e}"))})?;Ok(TempCopy(dst))@@ -532,6 +548,37 @@ mod tests {assert_eq!(read_linux(&profile).unwrap().len(), 1);}+ /// Chrome is running: its newest cookies are only in the `-wal` file. The+ /// reader must see them (and never touch the live database).+ #[test]+ fn reads_cookies_that_only_exist_in_the_wal_of_a_running_chrome() {+ let dir = tempfile::tempdir().unwrap();+ let profile = dir.path().join("Default");+ write_network_cookies_db_for_tests(&profile, &[]).unwrap();+ let db = profile.join("Network/Cookies");+ let live = rusqlite::Connection::open(&db).unwrap();+ let mode: String = live+ .query_row("PRAGMA journal_mode=WAL", [], |r| r.get(0))+ .unwrap();+ assert_eq!(mode, "wal");+ live.execute_batch("PRAGMA wal_autocheckpoint=0").unwrap();+ let row = &one_row()[0];+ live.execute(+ "INSERT INTO cookies (host_key, name, value, encrypted_value, path, expires_utc, \+ is_secure, is_httponly, samesite) VALUES (?1, ?2, '', ?3, ?4, 0, 1, 1, 1)",+ rusqlite::params![row.host_key, row.name, row.encrypted_value, row.path],+ )+ .unwrap();+ assert!(db.with_file_name("Cookies-wal").metadata().unwrap().len() > 0);+ let before = std::fs::read(&db).unwrap();+ let got = read_linux(&profile).unwrap();+ assert_eq!(got.len(), 1);+ assert_eq!(got[0].value.as_str(), "gh-session-abc");+ // The live database was only copied, never written.+ assert_eq!(std::fs::read(&db).unwrap(), before);+ drop(live);+ }+#[test]fn cookies_store_prefers_network_and_falls_back_to_legacy() {use cua_teleport_bundle::layout::chrome::cookies_store;diff --git a/libs/cua/crates/cua-teleport/src/safe_storage.rs b/libs/cua/crates/cua-teleport/src/safe_storage.rsindex 327760fe34..a017c1ffef 100644--- a/libs/cua/crates/cua-teleport/src/safe_storage.rs+++ b/libs/cua/crates/cua-teleport/src/safe_storage.rs@@ -125,6 +125,7 @@ impl<'a> SafeStorageKeys<'a> {let key = *self.v11()?;chromium_crypto::decrypt(&key, &value[3..])}+ Some(b"v20") => Err(app_bound_unsupported()),_ if self.platform == Platform::Windows => Err(windows_unsupported()),_ => Err(TeleportError::Provider("a Safe-Storage-encrypted value uses an encryption version this build does not \@@ -135,6 +136,18 @@ impl<'a> SafeStorageKeys<'a> {}}+/// Chrome 127+ on Windows encrypts new cookies with App-Bound Encryption+/// (`v20`): the key is bound to Chrome's own elevation service, so no other+/// program, this one included, can decrypt the values.+fn app_bound_unsupported() -> TeleportError {+ TeleportError::Provider(+ "these cookies are protected by Chrome's App-Bound Encryption (v20, Windows Chrome \+ 127+), which only Chrome itself can decrypt, so they cannot be teleported. Sign in \+ again in the destination browser instead."+ .into(),+ )+}+fn windows_unsupported() -> TeleportError {TeleportError::Provider("decrypting Chromium's Safe-Storage-encrypted values on Windows (DPAPI) is not \@@ -149,6 +162,17 @@ mod tests {use crate::host::{FakeHost, HostOutput};use std::sync::Arc;+ #[test]+ fn v20_values_get_a_clear_app_bound_message_on_every_platform() {+ for platform in [Platform::Windows, Platform::MacOS, Platform::Linux] {+ let host = FakeHost::new();+ let mut keys = SafeStorageKeys::new(&host, platform, "Chrome Safe Storage");+ let err = keys.decrypt(b"v20\x00\x01\x02").unwrap_err().to_string();+ assert!(err.contains("App-Bound Encryption"), "{err}");+ assert!(err.contains("Sign in again"), "{err}");+ }+ }+#[test]fn macos_v10_reads_the_named_service_through_the_host() {let host = Arc::new(FakeHost::new().with_responder(|c| {