mirror of
https://github.com/rustdesk/rustdesk-server.git
synced 2026-11-27 00:04:24 +00:00
Match IPv4 clients against the relay lists in their IPv4 form
hbbr listens dual-stack by default, so a direct IPv4 client reaches relay() as ::ffff:a.b.c.d. relay() checked BLACKLIST and BLOCKLIST with that form, while the lists hold the plain IPv4 that `ba` and `Ba` are given. A blacklisted IPv4 client was therefore never throttled, and adding it to the blocklist did not end its session. handle_connection already normalizes with try_into_v4 for its accept-time check; relay() now does the same. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01JAxkkiaGp2k8okvs4MpCUq
This commit is contained in:
1 parent
0415b0e057
commit
f3d43ff192
1 file changed
+30
-1
+30
-1
@@ -544,7 +544,9 @@ async fn relay(
|
||||
total_limiter: Limiter,
|
||||
id: String,
|
||||
) -> ResultType<()> {
|
||||
let ip = addr.ip().to_string();
|
||||
// The dual-stack listener reports an IPv4 client as ::ffff:a.b.c.d, while the lists hold the
|
||||
// IPv4 form that `ba` and `Ba` are given.
|
||||
let ip = hbb_common::try_into_v4(addr).ip().to_string();
|
||||
let mut tm = std::time::Instant::now();
|
||||
let mut elapsed = 0;
|
||||
let mut total = 0;
|
||||
@@ -693,6 +695,33 @@ mod tests {
|
||||
async fn blocked_writes_in_both_directions_time_out() {
|
||||
tokio::join!(check_blocked_send(false), check_blocked_send(true));
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn a_blocklisted_ipv4_client_on_the_dual_stack_listener_is_cut_off() {
|
||||
let ip = "192.0.2.55";
|
||||
BLOCKLIST.write().await.insert(ip.to_owned());
|
||||
let mut stream = TestStream {
|
||||
data: None,
|
||||
blocked: false,
|
||||
};
|
||||
let mut peer: Box<dyn StreamTrait> = Box::new(TestStream {
|
||||
data: None,
|
||||
blocked: false,
|
||||
});
|
||||
let result = timeout(
|
||||
10_000,
|
||||
relay(
|
||||
format!("[::ffff:{ip}]:1").parse().unwrap(),
|
||||
&mut stream,
|
||||
&mut peer,
|
||||
Limiter::new(1_000_000.),
|
||||
"blocklist-test".to_owned(),
|
||||
),
|
||||
)
|
||||
.await;
|
||||
BLOCKLIST.write().await.remove(ip);
|
||||
assert!(result.expect("the relay kept a blocklisted client").is_ok());
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns the configured relay key or resolves a signing key to its public value.
|
||||
|
||||
Reference in new issue
Block a user