Compare commits

..
Author SHA1 Message Date
rustdesk 3970601f71 fix(flutter): keep SIGPIPE setup in the native FFI entry
Sciter already receives SIGPIPE initialization from the Rust runtime. Scope the missing startup initialization to native Flutter runners on Linux and macOS.
2026-09-23 13:50:08 +08:00
rustdesk c7e611b510 fix: share SIGPIPE initialization with Sciter startup
Initialize SIGPIPE before global_init in core_main, shared by Flutter and Sciter on Linux and macOS.
2026-09-23 13:39:55 +08:00
rustdesk ea13df359c fix(flutter): initialize SIGPIPE in the Rust native entry
Share SIGPIPE initialization between the Linux and macOS native runners before core startup. Remove the Linux C++ initialization.
2026-09-23 13:30:48 +08:00
rustdesk b44786913e test(linux): remove SIGPIPE runner test 2026-09-23 11:02:53 +08:00
rustdesk 500982854f fix(linux): ignore SIGPIPE in Flutter runner
Initialize SIGPIPE before entering the Rust core so writes to closed IPC peers return EPIPE instead of terminating the server. Add a native-entry regression test for the failure reported in #16297.
2026-09-23 10:44:17 +08:00
rustdesk 6a0eb9a1fd fix(terminal): preserve trackpad scrolling in alternate screen
Prevent the inner terminal scrollable from accepting user scrolling in the alternate buffer, so xterm's existing outer handler receives trackpad gestures after main-screen history.

Keep wheel encoding and drag reporting unchanged. Cover trackpad forwarding, subsequent drag coordinates, arrow fallback, and return to local scrollback.
2026-09-22 11:45:05 +08:00
rustdeskandClaude Fable 5.1 763d4eeb05 bump hbb_common: tungstenite 0.29 forks, read buffer grown as bytes arrive
hbb_common 7dc56d6..d9895ff, one commit: tokio-tungstenite and tungstenite
up from 0.26 to rustdesk-org's rustdesk-patches-0.29 branches. The
tungstenite fork grows the read buffer a read_buffer_size chunk at a time
as bytes arrive, where upstream reserved the whole length a frame header
declared. It is pinned here at the workspace root, the one place cargo
reads [patch], so hbb_common's copy and tokio-tungstenite's resolve to
the same one. The lockfile moves only those two crates and drops utf-8,
which 0.29 no longer pulls.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EZ49AbZJYfm8NTp5yDPMab
2026-09-21 17:58:35 +08:00
fufesou a5d4ef97e8 fix(ws): reject text frames after encryption is enabled (#16295)
Signed-off-by: fufesou <linlong1266@gmail.com>
2026-09-20 18:21:15 +08:00
RustDeskandClaude Fable 5.1 dd9b21cf86 server: hold an unauthenticated connection to a small message (#16254)
* server: hold an unauthenticated connection to a small message

Until a peer authorizes it sends only a public key, a login request, a test delay
and a close reason, none of them large. Nothing said so: a frame header could
declare up to whatever the transport allowed, 1 GiB on TCP and WebRTC, and a
connection holds its place for up to LOGIN_GRACE before it has to authorize. With
MAX_UNAUTHORIZED_CONNS places to fill, that is 64 GiB of header-declared payload
one peer could make us hold - or, on WebSocket, 1 GiB bought outright with a few
hundred bytes of frame headers, because tungstenite reserves a frame's declared
payload as soon as it passes max_frame_size.

The cap goes on in create_tcp_connection, before the identity handshake, so that
read is bounded too, and comes off once the login is settled. It comes off before
connect_port_forward_if_needed rather than beside the rest of authorization: a
multiplexed tunnel narrows the same knob again for its own framing and has to have
the last word.

128 KiB is several times the largest login request anyone sends - a long hostname,
an os_login, an avatar URL, a file-transfer path - and is also the read buffer
tungstenite allocates per WebSocket connection whatever we do, so on that transport
the bound costs nothing beyond a floor already paid. A server hands that avatar
out as a URL; only a custom client that inlines an image into the avatar option
instead can reach the bound at all. Together with
MAX_UNAUTHORIZED_CONNS it holds every unauthorized connection to 8 MiB. Redis
answered this same shape in CVE-2021-32675 with 16 KiB, tighter because a
per-message bound is the only one it has; here the connection count is the other.

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

* server: test that the unauthenticated cap is on before the handshake reads

hbb_common covers each transport's cap; nothing covered where the connection
layer puts it. A header one byte over MAX_UNAUTHORIZED_MESSAGE, written to a
connection stalled in the identity handshake, has to end the handshake on the
header alone and release the connection's place: the test fails with the cap
moved past the handshake or dropped.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EZ49AbZJYfm8NTp5yDPMab

* client: hold the clipboard until this round's login is accepted

The clipboard listener is one per process, started by the first session to
log in, and its broadcast went to every session - one whose login was still
waiting on a password, 2FA or the peer's consent included. What the user
copied meanwhile went to a machine that had not admitted them; the peer
drops it unread before authorization, but it is in that peer's hands.

The check goes on the round, not the session: a session-level one reads a
state and later a sender that a reconnect can have swapped in between, so a
broadcast that passed for the round before could still queue on the next.
Remote is the round - its queue, and is_connected set once its own PeerInfo
is in - so a Clipboard or MultiClipboards that reaches handle_msg_from_ui
before then is dropped there, on the line before it would go out. What the
login itself sends through the same queue, Auth2FA among it, goes as before.

The unauthenticated cap on the other side is how this came up: a clipboard
over 128 KiB ended such a login with "Reset by the peer". The small case had
always gone through quietly.

A test drives a round's Remote over a loopback pair before any login: a
clipboard does not reach the far end, a 2FA code does, and once the round is
connected the clipboard does too.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EZ49AbZJYfm8NTp5yDPMab

---------

Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
2026-09-20 14:26:42 +08:00
7 changed files with 188 additions and 14 deletions
Generated
+4 -12
View File
@@ -8609,8 +8609,8 @@ dependencies = [
[[package]]
name = "tokio-tungstenite"
version = "0.26.2"
source = "git+https://github.com/rustdesk-org/tokio-tungstenite?rev=9c320de8e7c546cb654b017b7f4cbb4a5cc09cd9#9c320de8e7c546cb654b017b7f4cbb4a5cc09cd9"
version = "0.29.0"
source = "git+https://github.com/rustdesk-org/tokio-tungstenite?rev=c241b11b03de4881faf1ecd2fe6e867c92f3013b#c241b11b03de4881faf1ecd2fe6e867c92f3013b"
dependencies = [
"futures-util",
"log",
@@ -8893,9 +8893,8 @@ dependencies = [
[[package]]
name = "tungstenite"
version = "0.26.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4793cb5e56680ecbb1d843515b23b6de9a75eb04b66643e256a396d43be33c13"
version = "0.29.0"
source = "git+https://github.com/rustdesk-org/tungstenite-rs?rev=efce47e5364f00a63302cf07ab1fb13ded478914#efce47e5364f00a63302cf07ab1fb13ded478914"
dependencies = [
"bytes",
"data-encoding",
@@ -8909,7 +8908,6 @@ dependencies = [
"rustls-pki-types",
"sha1",
"thiserror 2.0.17",
"utf-8",
"webpki-roots 0.26.11",
]
@@ -9139,12 +9137,6 @@ dependencies = [
"log",
]
[[package]]
name = "utf-8"
version = "0.7.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9"
[[package]]
name = "utf16string"
version = "0.2.0"
+5
View File
@@ -218,6 +218,11 @@ exclude = ["vdi/host"]
# This allows building and running on systems without libxdo installed (e.g., Wayland-only)
[patch.crates-io]
libxdo-sys = { path = "libs/libxdo-sys-stub" }
# Upstream reserves a frame's whole declared length as soon as its header is in, so a header alone
# buys an allocation the size it names, bounded only by max_frame_size. This fork grows the read
# buffer one read_buffer_size chunk at a time as the bytes actually arrive. Patched rather than
# depended on directly, so tokio-tungstenite's own tungstenite resolves to the same copy.
tungstenite = { git = "https://github.com/rustdesk-org/tungstenite-rs", rev = "efce47e5364f00a63302cf07ab1fb13ded478914" }
# One branch off upstream v0.13.0, the tag whose crate versions match this stack.
# webrtc-util: reads the Windows adapter list's IPv6 addresses as host-order u16 groups, so every
# one comes out byte-swapped, fails to bind, and ICE gathers no IPv6 host candidate on Windows;
@@ -9,6 +9,7 @@ import 'platform_model.dart';
import 'rustdesk_terminal.dart';
import 'terminal_copy_shortcut.dart';
import 'terminal_mouse_drag_reporter.dart';
import 'terminal_scroll_controller.dart';
part 'terminal_mouse_handler_input.dart';
part 'terminal_web_clipboard_gesture.dart';
@@ -55,7 +56,7 @@ class _TerminalMouseInteractionState extends State<TerminalMouseInteraction> {
static const _scrollDown = 1;
final _terminalViewKey = GlobalKey<TerminalViewState>();
final _scrollController = ScrollController();
late final _scrollController = TerminalScrollController(() => widget.terminal);
final _mouseDrag = TerminalMouseDragReporter();
late final WheelButtonFixMouseHandler _mouseHandler;
TerminalMouseHandler? _previousMouseHandler;
@@ -0,0 +1,36 @@
import 'package:flutter/widgets.dart';
import 'package:xterm/xterm.dart';
class TerminalScrollController extends ScrollController {
TerminalScrollController(this.terminal);
final Terminal Function() terminal;
@override
ScrollPosition createScrollPosition(ScrollPhysics physics,
ScrollContext context, ScrollPosition? oldPosition) {
return super.createScrollPosition(
_TerminalScrollPhysics(terminal, parent: physics),
context,
oldPosition,
);
}
}
class _TerminalScrollPhysics extends ScrollPhysics {
const _TerminalScrollPhysics(this.terminal, {super.parent});
final Terminal Function() terminal;
@override
_TerminalScrollPhysics applyTo(ScrollPhysics? ancestor) =>
_TerminalScrollPhysics(terminal, parent: buildParent(ancestor));
@override
bool shouldAcceptUserOffset(ScrollMetrics position) {
// A retained main-screen offset can make this inner scrollable win the
// trackpad gesture, starving xterm's outer alternate-screen scroll handler.
if (terminal().isUsingAltBuffer) return false;
return super.shouldAcceptUserOffset(position);
}
}
@@ -0,0 +1,130 @@
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter_hbb/models/terminal_mouse_handler.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:xterm/xterm.dart';
const _captureMouse = '\x1b[?1007l\x1b[?1000h\x1b[?1002h\x1b[?1006h\x1b[?1003h';
void main() {
late Terminal terminal;
late TerminalController controller;
late List<String> output;
setUp(() {
output = [];
terminal = Terminal()..onOutput = output.add;
controller = TerminalController();
});
Future<TerminalViewState> mount(WidgetTester tester) async {
await tester.pumpWidget(MaterialApp(
home: Align(
alignment: Alignment.topLeft,
child: Padding(
padding: const EdgeInsets.only(left: 30, top: 50),
child: SizedBox(
width: 400,
height: 120,
child: TerminalMouseInteraction(terminal, controller: controller),
),
),
),
));
terminal.write(List.generate(80, (i) => 'line $i\r\n').join());
await tester.pump();
final view = tester.state<TerminalViewState>(find.byType(TerminalView));
expect(view.widget.scrollController!.offset, greaterThan(0));
return view;
}
Future<void> scrollTrackpad(
WidgetTester tester, Offset point, double distance) async {
final pointer = TestPointer(2, PointerDeviceKind.trackpad);
await tester.sendEventToBinding(pointer.panZoomStart(point));
await tester.sendEventToBinding(
pointer.panZoomUpdate(point, pan: Offset(0, distance)));
await tester.sendEventToBinding(
pointer.panZoomUpdate(point, pan: Offset(0, distance * 2)));
await tester.sendEventToBinding(pointer.panZoomEnd());
await tester.pump();
}
for (final trackpad in [false, true]) {
final device = trackpad ? 'trackpad' : 'wheel';
testWidgets('alternate screen reports $device after main-screen history',
(tester) async {
final view = await mount(tester);
terminal.write('\x1b[?1049h$_captureMouse');
await tester.pump();
final render = view.renderTerminal;
final point = render.localToGlobal(
Offset(render.cellSize.width * 2.5, render.lineHeight * 1.5));
if (trackpad) {
await scrollTrackpad(tester, point, render.lineHeight * 3);
} else {
await tester.sendEventToBinding(PointerScrollEvent(
position: point,
scrollDelta: Offset(0, -render.lineHeight * 3),
));
await tester.pump();
}
expect(output, isNotEmpty);
expect(output, everyElement('\x1b[<64;3;2M'));
expect(view.widget.scrollController!.offset, 0);
expect(controller.selection, isNull);
}, variant: TargetPlatformVariant.only(TargetPlatform.macOS));
}
testWidgets('trackpad scrolling keeps subsequent drag coordinates aligned',
(tester) async {
final view = await mount(tester);
terminal.write('\x1b[?1049h$_captureMouse');
await tester.pump();
final render = view.renderTerminal;
final start = render.localToGlobal(
Offset(render.cellSize.width * 2.5, render.lineHeight * 1.5));
final end = render.localToGlobal(
Offset(render.cellSize.width * 6.5, render.lineHeight * 2.5));
await scrollTrackpad(tester, start, render.lineHeight * 3);
output.clear();
final mouse = await tester.createGesture(kind: PointerDeviceKind.mouse);
await mouse.down(start);
await mouse.moveTo(end);
await mouse.up();
await tester.pump(kDoubleTapTimeout);
expect(output, ['\x1b[<0;3;2M', '\x1b[<32;7;3M', '\x1b[<0;7;3m']);
expect(controller.selection, isNull);
expect(controller.suspendedPointerInputs, isFalse);
}, variant: TargetPlatformVariant.only(TargetPlatform.macOS));
testWidgets('leaving alternate screen restores local trackpad scrollback',
(tester) async {
final view = await mount(tester);
terminal.write('\x1b[?1049h$_captureMouse');
await tester.pump();
terminal.write('\x1b[?1003l\x1b[?1002l\x1b[?1000l\x1b[?1006l\x1b[?1049l');
await tester.pump();
final before = view.widget.scrollController!.offset;
await scrollTrackpad(
tester, view.renderTerminal.localToGlobal(const Offset(40, 40)), 48);
expect(output, isEmpty);
expect(view.widget.scrollController!.offset, lessThan(before));
}, variant: TargetPlatformVariant.only(TargetPlatform.macOS));
testWidgets('alternate screen without mouse capture still simulates arrows',
(tester) async {
final view = await mount(tester);
terminal.write('\x1b[?1049h');
await tester.pump();
await scrollTrackpad(
tester, view.renderTerminal.localToGlobal(const Offset(40, 40)), -48);
expect(output, isNotEmpty);
expect(output, everyElement('\x1b[B'));
expect(view.widget.scrollController!.offset, 0);
}, variant: TargetPlatformVariant.only(TargetPlatform.macOS));
}
+10
View File
@@ -105,6 +105,16 @@ fn load_plugin_in_app_path(dll_name: &str) -> Result<Library, LibError> {
#[cfg(not(windows))]
#[no_mangle]
pub extern "C" fn rustdesk_core_main() -> bool {
#[cfg(any(target_os = "linux", target_os = "macos"))]
{
use hbb_common::libc;
// Native runners bypass Rust's startup, which normally ignores SIGPIPE.
if unsafe { libc::signal(libc::SIGPIPE, libc::SIG_IGN) } == libc::SIG_ERR {
eprintln!("Failed to ignore SIGPIPE: {}", std::io::Error::last_os_error());
std::process::exit(1);
}
}
#[cfg(not(any(target_os = "android", target_os = "ios")))]
if crate::core_main::core_main().is_some() {
return true;