Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

fix(remote-desktop): 修复 Windows 锁屏控制授权始终失败 (#6603)

Yunjin Zhang7a97a0d61f41
diff --git a/apps/desktop/native/remote-desktop/README.md b/apps/desktop/native/remote-desktop/README.md
index ec897f6b29..47680f08a2 100644
--- a/apps/desktop/native/remote-desktop/README.md
+++ b/apps/desktop/native/remote-desktop/README.md
@@ -22,6 +22,23 @@ binding, rechecking and restoration. Run the Windows crate's `cargo test` with a
task-specific `--target-dir` outside the checkout. It is separate from Node unit
tests and does not prove lock/UAC or physical cross-device behavior.
+## Windows service pipe access
+
+The broker pipe of the lock-screen control service grants interactive clients
+data, synchronization and read-attributes access. Windows `CreateFileW` checks
+`FILE_READ_ATTRIBUTES` even when a client requests only data access, so omitting
+it leaves the service running but rejects every connection with Win32 error 5 —
+the elevated install reports a failed authorization and settings shows
+"authorization was not completed". Do not substitute generic write access, which
+would also grant creation of pipe server instances.
+
+`pipe::tests::interactive_client_can_open_service_pipe_and_exchange_probe` runs
+the production ACL from an interactive, non-SYSTEM account: it opens the client
+end, exchanges a probe, and proves the same account still cannot create a second
+server instance. Run it with the crate's `cargo test` (same task-specific
+`--target-dir` as above); an ad-hoc pipe test with a caller-owned default ACL
+does not cover this grant.
+
## macOS input helper trust boundary
The input helper authenticates its caller before inspecting any command or
diff --git a/apps/desktop/native/remote-desktop/windows-host/Cargo.toml b/apps/desktop/native/remote-desktop/windows-host/Cargo.toml
index 78928ec1d5..99bf992b0f 100644
--- a/apps/desktop/native/remote-desktop/windows-host/Cargo.toml
+++ b/apps/desktop/native/remote-desktop/windows-host/Cargo.toml
@@ -21,7 +21,7 @@ tokio = { version = "1", features = ["rt"] }
windows-sys = { version = "0.59", features = ["Win32_Foundation", "Win32_Security", "Win32_Security_Authentication_Identity", "Win32_Security_Authorization", "Win32_Storage_FileSystem", "Win32_System_IO", "Win32_System_Pipes", "Win32_System_Threading", "Win32_System_Services", "Win32_System_RemoteDesktop", "Win32_System_StationsAndDesktops", "Win32_System_Diagnostics_ToolHelp", "Win32_System_Memory", "Win32_System_Environment", "Win32_System_Com", "Win32_UI_Shell", "Win32_UI_WindowsAndMessaging", "Win32_UI_HiDpi", "Win32_Graphics_Gdi"] }
[features]
-default = ["windows-sys/Win32_System_JobObjects", "windows-sys/Win32_System_Registry", "windows-sys/Win32_System_SystemServices"]
+default = ["windows-sys/Win32_System_JobObjects", "windows-sys/Win32_System_Registry", "windows-sys/Win32_System_SystemServices", "windows-sys/Win32_UI_Input_KeyboardAndMouse"]
[profile.release]
panic = "abort"
diff --git a/apps/desktop/native/remote-desktop/windows-host/src/pipe.rs b/apps/desktop/native/remote-desktop/windows-host/src/pipe.rs
index ac83dde9f2..6f88ccfbb7 100644
--- a/apps/desktop/native/remote-desktop/windows-host/src/pipe.rs
+++ b/apps/desktop/native/remote-desktop/windows-host/src/pipe.rs
@@ -31,11 +31,13 @@ impl Pipe {
.is_some_and(|stop| stop.load(Ordering::SeqCst))
}
pub fn server(name: &str, system_only: bool) -> Result<Self> {
- // GR/GW would include FILE_CREATE_PIPE_INSTANCE. Explicit data rights only.
+ // GR/GW would include FILE_CREATE_PIPE_INSTANCE. Grant only data,
+ // synchronization and read-attributes access: CreateFileW also checks
+ // FILE_READ_ATTRIBUTES when opening the client end of a named pipe.
let sddl = wide(if system_only {
"D:P(A;;GA;;;SY)"
} else {
- "D:P(A;;GA;;;SY)(A;;0x00100003;;;IU)"
+ "D:P(A;;GA;;;SY)(A;;0x00100083;;;IU)"
});
let mut descriptor = ptr::null_mut();
if unsafe {
@@ -90,7 +92,7 @@ impl Pipe {
let handle = Handle::new(unsafe {
CreateFileW(
name.as_ptr(),
- FILE_READ_DATA | FILE_WRITE_DATA | SYNCHRONIZE,
+ FILE_READ_DATA | FILE_WRITE_DATA | FILE_READ_ATTRIBUTES | SYNCHRONIZE,
0,
ptr::null(),
OPEN_EXISTING,
@@ -251,6 +253,39 @@ mod tests {
use crate::capture_protocol::OVERLAY_RESPONSE_LIMIT;
use serde_json::json;
+ #[test]
+ fn interactive_client_can_open_service_pipe_and_exchange_probe() {
+ let nonce = std::time::SystemTime::now()
+ .duration_since(std::time::UNIX_EPOCH)
+ .unwrap()
+ .as_nanos();
+ let name = format!(
+ r"\\.\pipe\cindy-service-acl-test-{}-{nonce}",
+ std::process::id()
+ );
+ // Exercise the real service ACL from an interactive, non-SYSTEM account.
+ // The framing test below uses a caller-owned default ACL and cannot catch
+ // missing rights in the SYSTEM service's interactive-client grant.
+ let mut server = Pipe::server(&name, false).unwrap();
+ let mut client = Pipe::client(&name).unwrap();
+ server.accept(1000).unwrap();
+ assert_eq!(server.client_pid().unwrap(), std::process::id());
+ assert_eq!(client.server_pid().unwrap(), std::process::id());
+ client.write(b"{\"mode\":\"probe\"}\n").unwrap();
+ assert_eq!(server.line(1024).unwrap(), b"{\"mode\":\"probe\"}\n");
+ server.write(b"ready\n").unwrap();
+ assert_eq!(client.line(1024).unwrap(), b"ready\n");
+ // Data access must not let interactive clients impersonate the service
+ // by creating another server instance at its existing pipe name.
+ assert_eq!(
+ Pipe::server(&name, false)
+ .err()
+ .expect("client cannot create a server instance")
+ .kind(),
+ io::ErrorKind::PermissionDenied
+ );
+ }
+
#[test]
fn transfers_large_negotiated_frames_without_raising_other_write_limits() {
let nonce = std::time::SystemTime::now()