Compare commits

...
Author SHA1 Message Date
rustdeskandClaude Opus 5.5 333bfc6427 Initialize libsodium where Android starts the server
Started at boot, MainService calls startServer with no Flutter engine,
so initialize never ran: the server worked with libsodium uninitialized
until the UI opened, and that first sodium_init() could land while
sessions were running. startServer now makes the call first, before it
verifies the custom client's signature or spawns the server.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PkpVy2ufxgEjKd3SjXPnJ8
2026-11-17 10:48:58 +08:00
rustdeskandClaude Opus 5.5 289f839646 Log a failed libsodium initialization and start anyway
As hbbs does: a client that does not start is worse than one that
runs with libsodium as it was before this change, and sodium_init()
fails only when it cannot lock its own mutex.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PkpVy2ufxgEjKd3SjXPnJ8
2026-11-17 10:47:06 +08:00
rustdeskandClaude Fable 5.2 3dd95ab73b Initialize libsodium before anything uses it
The client called sodium_init() only when the update signature check
or the trusted device token first ran. That call also chooses
libsodium's implementations: where a build has both, it moves Poly1305
from the default one to the SSE2 one, whose state is laid out
differently, so a secretbox or AEAD operation another thread was in
the middle of finished under the other implementation. In one thread,
a computation straddling the call gives a wrong tag. The call now runs
once at process start: first in global_init, which core_main begins
with, and at the top of the FFI initialize, which on mobile verifies a
signature before it reaches global_init.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PkpVy2ufxgEjKd3SjXPnJ8
2026-11-17 10:42:46 +08:00
fufesou 3e953e886a fix: win, reg update, check (#17040)
* fix(security): prevent privilege escalation via registry recovery (ZDI-CAN-34805)

Validate all registry recovery inputs before accessing HKEY_LOCAL_MACHINE:
  - Path must start with the graphics drivers connectivity prefix
  - Key name must be exactly "Recent"
  - Subkey cannot contain path separators, dots, or null bytes
  - Old and new values must match in type and length

Validation applies unconditionally to both force=false and force=true paths,
blocking arbitrary registry writes from low-privilege IPC clients.

Maintain existing recovery lifecycle and config persistence. Add three
regression tests covering the reported attack vector and data validation.

Reported-by: BoGeun Jang <TrendAI Zero Day Initiative>
Signed-off-by: fufesou <linlong1266@gmail.com>

* fix(windows): preserve registry recovery behavior

Restore historical type conversion and force behavior while retaining registry target validation. Replace format restrictions with a regression test for variable-length recovery records.

Signed-off-by: fufesou <linlong1266@gmail.com>

---------

Signed-off-by: fufesou <linlong1266@gmail.com>
2026-11-16 17:30:15 +08:00
fufesou bca767fcdb fix(terminal): background opacity, 1.0 (#17075)
Signed-off-by: fufesou <linlong1266@gmail.com>
2026-11-16 16:38:35 +08:00
github-actions[bot] 5b937c3a68 chore: update webpki-roots to latest Mozilla root store (#17074)
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
2026-11-16 12:29:21 +08:00
RustDesk 7949eca16c fix(android): enforce keyboard permission for remote input (#17061) 2026-11-15 22:58:36 +08:00
RustDeskandClaude Opus 5.5 506e111460 fix(android): sync input service state to enable-keyboard without the UI (#17064)
* Sync the Android input service state to enable-keyboard from Kotlin

enable-keyboard mirrors whether InputService is running, but only the
Flutter UI updated it. When the service was turned on from system
settings while the UI was not running, the option stayed N and new
connections were denied keyboard permission until the app was opened.

InputService now reports its state directly, and MainService reports it
again once startServer has set the config directory.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JAxkkiaGp2k8okvs4MpCUq

* Stop the Android UI from resetting enable-keyboard on start

ServerModel set enable-keyboard to N on every mobile UI start and relied
on the input state message to set it back. Until that message arrived,
open connections lost keyboard permission. Android now keeps the option
in step with InputService natively, so keep the reset on iOS only.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JAxkkiaGp2k8okvs4MpCUq

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-15 22:58:13 +08:00
RustDeskandClaude Opus 5.5 fcb485bb90 Ignore keyboard and clipboard switches on non-remote connections (#17062)
Android's input control and clipboard toggles call switch_permission_all,
which reaches every CM client. On a file-transfer, view-camera or
port-forward connection, the keyboard switch set keyboard = true and both
switches re-subscribed the clipboard service, so the host's clipboard
changes were sent to a peer that was not granted a remote session.


Claude-Session: https://claude.ai/code/session_01JAxkkiaGp2k8okvs4MpCUq

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-15 11:49:36 +08:00
RustDeskandClaude Opus 5.5 febee50a6e fix: subscribe clipboard services from permission switches only after authorization (#17065)
* Subscribe clipboard services from permission switches only after authorization

Permission toggles in the accept window reach the connection before the
peer is authorized. The keyboard, clipboard and file switches subscribed
the clipboard services at once, so anything the host copied while the
window was open was sent to a peer that had not been accepted.

Subscribe only once authorized, as the audio switch does; on
authorization try_sub_monitor_services subscribes from the recorded
values.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JAxkkiaGp2k8okvs4MpCUq

* Say "until authorized" in the permission switch comment

The switch arrives after the login request, so "before login" was
inaccurate.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JAxkkiaGp2k8okvs4MpCUq

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-15 11:20:09 +08:00
11 changed files with 123 additions and 14 deletions

No files matched your search

Generated
+6 -6
View File
@@ -3724,7 +3724,7 @@ dependencies = [
"url",
"users",
"uuid",
"webpki-roots 1.0.11",
"webpki-roots 1.0.12",
"webrtc",
"whoami",
"x11 2.21.0",
@@ -3922,7 +3922,7 @@ dependencies = [
"tokio",
"tokio-rustls",
"tower-service",
"webpki-roots 1.0.11",
"webpki-roots 1.0.12",
]
[[package]]
@@ -6916,7 +6916,7 @@ dependencies = [
"wasm-bindgen",
"wasm-bindgen-futures",
"web-sys",
"webpki-roots 1.0.11",
"webpki-roots 1.0.12",
]
[[package]]
@@ -9539,14 +9539,14 @@ version = "0.26.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "521bc38abb08001b01866da9f51eb7c5d647a19260e00054a8c7fd5f9e57f7a9"
dependencies = [
"webpki-roots 1.0.11",
"webpki-roots 1.0.12",
]
[[package]]
name = "webpki-roots"
version = "1.0.11"
version = "1.0.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f5f280bbb2b287bc8e7de7e3852945a0ff50d1bbcb5ed42b6c7a568c546df171"
checksum = "7265c9301c16a8711c992c2d8da90ee77ef54b1ed51482d6dfeb00dc756b1297"
dependencies = [
"rustls-pki-types",
]
@@ -35,6 +35,7 @@ import kotlin.math.max
import hbb.MessageOuterClass.KeyEvent
import hbb.MessageOuterClass.KeyboardMode
import hbb.KeyEventConverter
import ffi.FFI
// const val BUTTON_UP = 2
// const val BUTTON_BACK = 0x08
@@ -79,6 +80,8 @@ class InputService : AccessibilityService() {
}
private fun notifyInputState() {
// The Flutter UI may not be running to forward this, e.g. when enabled from system settings.
FFI.setInputServiceOpen(isOpen)
val inputState = isOpen.toString()
Handler(Looper.getMainLooper()).post {
MainActivity.flutterMethodChannel?.invokeMethod(
@@ -254,6 +254,7 @@ class MainService : Service() {
val homePath = applicationContext.getExternalFilesDir(null)?.absolutePath
?: applicationContext.filesDir.absolutePath
FFI.startServer(configPath, homePath, "")
FFI.setInputServiceOpen(InputService.isOpen)
createForegroundNotification()
}
@@ -29,4 +29,5 @@ object FFI {
external fun onClipboardUpdate(clips: ByteBuffer)
external fun isServiceClipboardEnabled(): Boolean
external fun setDocumentLogsEnabled(enabled: Boolean)
external fun setInputServiceOpen(open: Boolean)
}
+1 -1
View File
@@ -212,7 +212,7 @@ class _TerminalPageState extends State<TerminalPage>
focusNode: _terminalFocusNode,
// Note: autofocus is not used here because focus is managed manually
// via _onTabStateChanged() to handle tab switching properly.
backgroundOpacity: 0.7,
backgroundOpacity: 1.0,
padding: _calculatePadding(heightPx),
onSecondaryTapDown: (details, offset) async {
final selection = _terminalModel.terminalController.selection;
+1 -1
View File
@@ -20,7 +20,7 @@ import 'package:xterm/xterm.dart';
import '../../desktop/pages/terminal_connection_manager.dart';
import '../../consts.dart';
const _terminalBackgroundOpacity = 0.7;
const _terminalBackgroundOpacity = 1.0;
Widget _buildTerminalViewForPlatform({
required bool reportMouseInput,
+2 -2
View File
@@ -191,8 +191,8 @@ class ServerModel with ChangeNotifier {
});
}
// Initial keyboard status is off on mobile
if (isMobile) {
// Initial keyboard status is off on iOS; Android syncs it from InputService natively.
if (isIOS) {
bind.mainSetOption(key: kOptionEnableKeyboard, value: 'N');
}
}
+9
View File
@@ -120,7 +120,16 @@ impl Drop for SimpleCallOnReturn {
}
}
/// `sodium_init()` chooses libsodium's implementations, so it runs before anything else uses the
/// library: a later call swaps Poly1305 under a computation another thread is in the middle of.
pub fn init_sodium() {
if hbb_common::sodiumoxide::init().is_err() {
log::error!("Failed to initialize libsodium");
}
}
pub fn global_init() -> bool {
init_sodium();
#[cfg(all(target_os = "linux", feature = "drm"))]
crate::platform::linux::dispatch_wayland_display_probe();
#[cfg(target_os = "linux")]
+22
View File
@@ -41,6 +41,8 @@ lazy_static::lazy_static! {
}
fn initialize(app_dir: &str, custom_client_config: &str) {
// On mobile `global_init` below comes after the custom client's signature is verified.
crate::common::init_sodium();
flutter::async_tasks::start_flutter_async_runner();
// `APP_DIR` is set in `main_get_data_dir_ios()` on iOS.
#[cfg(not(target_os = "ios"))]
@@ -3087,6 +3089,8 @@ pub mod server_side {
custom_client_config: JString,
) {
log::debug!("startServer from jvm");
// Started at boot, the service runs without the Flutter side and its `initialize`.
crate::common::init_sodium();
let mut env = env;
if let Ok(app_dir) = env.get_string(&app_dir) {
*config::APP_DIR.write().unwrap() = app_dir.into();
@@ -3186,4 +3190,22 @@ pub mod server_side {
) -> jboolean {
jboolean::from(crate::server::is_clipboard_service_ok())
}
/// Keeps `enable-keyboard` in step with InputService when the Flutter UI is not running.
#[no_mangle]
pub unsafe extern "system" fn Java_ffi_FFI_setInputServiceOpen(
_env: JNIEnv,
_class: JClass,
open: jboolean,
) {
// Config must not load before startServer sets APP_DIR; MainService syncs again after it.
if config::APP_DIR.read().unwrap().is_empty() {
return;
}
let key = super::keys::OPTION_ENABLE_KEYBOARD;
let value = if open == 0 { "N" } else { "Y" };
if let Err(e) = super::main_set_option(key.to_owned(), value.to_owned()) {
log::error!("Failed to sync input service state: {}", e);
}
}
}
+56 -1
View File
@@ -4432,7 +4432,7 @@ pub fn try_set_window_foreground(window: HWND) {
}
pub mod reg_display_settings {
use hbb_common::ResultType;
use hbb_common::{bail, ResultType};
use serde_derive::{Deserialize, Serialize};
use std::collections::HashMap;
use winreg::{enums::*, RegValue};
@@ -4496,6 +4496,7 @@ pub mod reg_display_settings {
}
pub fn restore_reg_connectivity(reg_recovery: RegRecovery, force: bool) -> ResultType<()> {
connectivity_subkey(&reg_recovery)?;
let hklm = winreg::RegKey::predef(HKEY_LOCAL_MACHINE);
let reg_item = hklm.open_subkey_with_flags(&reg_recovery.path, KEY_READ | KEY_WRITE)?;
if !force {
@@ -4537,6 +4538,60 @@ pub mod reg_display_settings {
_ => RegType::REG_NONE,
}
}
fn connectivity_subkey(recovery: &RegRecovery) -> ResultType<&str> {
let prefix = format!("{}\\{}\\", REG_GRAPHICS_DRIVERS_PATH, REG_CONNECTIVITY_PATH);
let Some(subkey) = recovery.path.strip_prefix(&prefix) else {
bail!("Invalid display connectivity recovery target");
};
if recovery.key != "Recent"
|| subkey.is_empty()
|| matches!(subkey, "." | "..")
|| subkey.chars().any(|c| matches!(c, '\\' | '/' | '\0'))
{
bail!("Invalid display connectivity recovery target");
}
Ok(subkey)
}
#[cfg(test)]
mod tests {
use super::*;
use winreg::types::ToRegValue;
#[test]
fn registry_recovery_rejects_external_targets_before_access() {
for force in [false, true] {
let recovery = RegRecovery {
path: format!("SOFTWARE\\RustDesk\\{}", uuid::Uuid::new_v4()),
key: "Recent".to_owned(),
old: (vec![0x22; 4], RegType::REG_DWORD as isize),
new: (vec![0x11; 4], RegType::REG_DWORD as isize),
};
let error = restore_reg_connectivity(recovery, force).unwrap_err();
assert_eq!(
error.to_string(),
"Invalid display connectivity recovery target"
);
}
}
#[test]
fn registry_recovery_accepts_display_changes() {
let connectivity = |value: &str| {
HashMap::from([(
"monitor".to_owned(),
HashMap::from([("Recent".to_owned(), value.to_reg_value())]),
)])
};
let recovery = diff_recent_connectivity(
connectivity("before"),
connectivity("after-layout-change"),
)
.unwrap();
assert_eq!(connectivity_subkey(&recovery).unwrap(), "monitor");
}
}
}
pub fn get_printer_names() -> ResultType<Vec<String>> {
+21 -3
View File
@@ -802,10 +802,15 @@ impl Connection {
}
ipc::Data::SwitchPermission{name, enabled} => {
log::info!("Change permission {} -> {}", name, enabled);
// Android broadcasts these to every connection; only remote sessions use them.
if (&name == "keyboard" || &name == "clipboard") && !conn.is_remote() {
continue;
}
if &name == "keyboard" {
conn.keyboard = enabled;
conn.send_permission(Permission::Keyboard, enabled).await;
if let Some(s) = conn.server.upgrade() {
// Until authorized, only record the value; try_sub_monitor_services subscribes from it.
if let Some(s) = conn.server.upgrade().filter(|_| conn.authorized) {
s.write().unwrap().subscribe(
super::clipboard_service::NAME,
conn.inner.clone(), conn.can_sub_clipboard_service());
@@ -822,7 +827,7 @@ impl Connection {
} else if &name == "clipboard" {
conn.clipboard = enabled;
conn.send_permission(Permission::Clipboard, enabled).await;
if let Some(s) = conn.server.upgrade() {
if let Some(s) = conn.server.upgrade().filter(|_| conn.authorized) {
s.write().unwrap().subscribe(
super::clipboard_service::NAME,
conn.inner.clone(), conn.can_sub_clipboard_service());
@@ -853,7 +858,7 @@ impl Connection {
conn.try_empty_file_clipboard();
}
#[cfg(feature = "unix-file-copy-paste")]
if let Some(s) = conn.server.upgrade() {
if let Some(s) = conn.server.upgrade().filter(|_| conn.authorized) {
s.write().unwrap().subscribe(
super::clipboard_service::FILE_NAME,
conn.inner.clone(),
@@ -3198,6 +3203,11 @@ impl Connection {
if self.is_authed_view_camera_conn() {
return true;
}
#[cfg(target_os = "android")]
if !self.peer_keyboard_enabled() {
self.update_auto_disconnect_timer();
return true;
}
#[cfg(any(target_os = "android", target_os = "ios"))]
if let Err(e) = call_main_service_pointer_input("mouse", me.mask, me.x, me.y) {
log::debug!("call_main_service_pointer_input fail:{}", e);
@@ -3237,6 +3247,11 @@ impl Connection {
if self.is_authed_view_camera_conn() {
return true;
}
#[cfg(target_os = "android")]
if !self.peer_keyboard_enabled() {
self.update_auto_disconnect_timer();
return true;
}
#[cfg(any(target_os = "android", target_os = "ios"))]
if let Err(e) = match pde.union {
Some(pointer_device_event::Union::TouchEvent(touch)) => match touch.union {
@@ -3279,6 +3294,9 @@ impl Connection {
if self.is_authed_view_camera_conn() {
return true;
}
if !self.peer_keyboard_enabled() {
return true;
}
let key = match me.mode.enum_value() {
Ok(KeyboardMode::Map) => {
Some(crate::keyboard::keycode_to_rdev_key(me.chr()))