fix: auto-login types the OS password only at the logon or lock screen

A remote-control login on Windows and macOS now reports is_logon_screen
in platform_additions, and the client skips auto-login when the peer
reports false. Peers that don't report it (older ones, Linux) keep
today's behaviour, so this narrows the leak into the focused window
without closing it: the value is a snapshot taken at login.

Windows 7 and Server 2008 R2 report the WTS lock flag reversed, so
there only LogonUI.exe tells the lock screen apart.

Refs #16510, #15261

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01P1grQ39ByRWPUtTBdTzEBF
This commit is contained in:
rustdesk
2026-10-10 16:43:00 +08:00
co-authored by Claude Opus 5.5
parent 67090d3aa1
commit 7cd70b3d18
4 changed files with 73 additions and 0 deletions
+45
View File
@@ -3056,12 +3056,29 @@ impl LoginConfigHandler {
let a = !self.get_option("auto-login").is_empty();
let p = self.get_option("os-password");
if !p.is_empty() && l && a {
if self.peer_reports_not_logon_screen() {
log::info!("Skip auto login, the peer is not at the logon or lock screen");
return "".to_owned();
}
p
} else {
"".to_owned()
}
}
// Peers that don't report `is_logon_screen` (older ones, Linux) keep auto-login. The value is
// taken when the peer answers the login, so the screen can still lock or unlock before the
// password is typed.
fn peer_reports_not_logon_screen(&self) -> bool {
let Some(pi) = self.peer_info.as_ref() else {
return false;
};
serde_json::from_str::<serde_json::Value>(&pi.platform_additions)
.ok()
.and_then(|v| v.get("is_logon_screen")?.as_bool())
== Some(false)
}
/// Load [`PeerConfig`].
pub fn load_config(&self) -> PeerConfig {
debug_assert!(self.id.len() > 0);
@@ -5221,6 +5238,34 @@ mod port_forward_mux_tests {
}
}
#[cfg(test)]
mod auto_login_tests {
use super::*;
#[test]
fn auto_login_skips_a_peer_that_reports_no_logon_screen() {
let mut lc = LoginConfigHandler::default();
lc.config.lock_after_session_end.v = true;
lc.config
.options
.insert("os-password".to_owned(), "os-pass".to_owned());
lc.config
.options
.insert("auto-login".to_owned(), "Y".to_owned());
let mut with_additions = |additions: &str| {
lc.peer_info = Some(PeerInfo {
platform_additions: additions.to_owned(),
..Default::default()
});
lc.should_auto_login()
};
assert_eq!(with_additions(r#"{"is_logon_screen":false}"#), "");
assert_eq!(with_additions(r#"{"is_logon_screen":true}"#), "os-pass");
assert_eq!(with_additions(r#"{"is_installed":true}"#), "os-pass");
assert_eq!(with_additions(""), "os-pass");
}
}
pub async fn hc_connection(
feedback: i32,
rendezvous_server: String,
+4
View File
@@ -767,6 +767,10 @@ pub fn is_locked() -> bool {
}
}
pub fn is_logon_screen() -> bool {
is_prelogin() || is_locked()
}
pub fn is_root() -> bool {
crate::username() == "root"
}
+12
View File
@@ -1283,6 +1283,18 @@ pub fn is_logon_ui() -> ResultType<bool> {
.any(|pid| get_session_id_of_process(pid) == Some(current_sid)))
}
// Windows 7 and Server 2008 R2 report the WTS lock flag reversed (see WTSINFOEX_LEVEL1), so
// there only LogonUI.exe tells the lock screen apart.
pub fn is_logon_screen() -> bool {
let lock_flag_works = base::platform::windows::is_windows_version_or_greater(6, 2, 0, 0, 0);
is_prelogin()
|| (lock_flag_works && is_locked())
|| is_logon_ui().unwrap_or_else(|e| {
log::error!("Failed to detect logon UI: {:?}", e);
false
})
}
pub fn is_root() -> bool {
// https://stackoverflow.com/questions/4023586/correct-way-to-find-out-if-a-service-is-running-as-the-system-user
unsafe { is_local_system() == TRUE }
+12
View File
@@ -2015,6 +2015,18 @@ impl Connection {
platform_additions.insert("support_view_camera".into(), json!(true));
}
// A client's auto-login types the OS password into whatever has focus. It skips that
// when this is false.
#[cfg(any(target_os = "windows", target_os = "macos"))]
if self.is_remote() {
match tokio::task::spawn_blocking(crate::platform::is_logon_screen).await {
Ok(is_logon_screen) => {
platform_additions.insert("is_logon_screen".into(), json!(is_logon_screen));
}
Err(e) => log::error!("Failed to check the logon screen: {}", e),
}
}
#[cfg(any(target_os = "linux", target_os = "windows", target_os = "macos"))]
if !platform_additions.is_empty() {
pi.platform_additions = serde_json::to_string(&platform_additions).unwrap_or("".into());