fix(hbbs): cap peer id length at 253 bytes

RegisterPk accepted ids up to a whole UDP datagram, so 31 registered
peers with ~64 KB ids still let the bounded punch-request store reach
hundreds of MB. Reject longer ids in RegisterPk and RegisterPeer, the
same bound the Pro server uses.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PkpVy2ufxgEjKd3SjXPnJ8
This commit is contained in:
rustdesk
2026-10-07 22:23:03 +08:00
co-authored by Claude Opus 5.5
parent 5634686c5a
commit 9dfa0610e0
2 changed files with 5 additions and 2 deletions
+3
View File
@@ -22,6 +22,9 @@ pub const IP_CHANGE_DUR: u64 = 180;
pub const IP_CHANGE_DUR_X2: u64 = IP_CHANGE_DUR * 2;
pub const DAY_SECONDS: u64 = 3600 * 24;
pub const IP_BLOCK_DUR: u64 = 60;
// Same bound as the Pro server: a longer id is not a normal RustDesk id or hostname,
// and every peer entry and punch-request record keeps its own copy.
pub const MAX_PEER_ID_LEN: usize = 253;
#[derive(Debug, Default, Serialize, Deserialize, Clone)]
pub(crate) struct PeerInfo {
+2 -2
View File
@@ -373,7 +373,7 @@ impl RendezvousServer {
match msg_in.union {
Some(rendezvous_message::Union::RegisterPeer(rp)) => {
// B registered
if !rp.id.is_empty() {
if !rp.id.is_empty() && rp.id.len() <= MAX_PEER_ID_LEN {
log::trace!("New peer registered: {:?} {:?}", &rp.id, &addr);
self.update_addr(rp.id, addr, socket).await?;
if self.inner.serial > rp.serial {
@@ -393,7 +393,7 @@ impl RendezvousServer {
}
let id = rk.id;
let ip = addr.ip().to_string();
if id.len() < 6 {
if id.len() < 6 || id.len() > MAX_PEER_ID_LEN {
return send_rk_res(socket, addr, UUID_MISMATCH).await;
} else if !self.check_ip_blocker(&ip, &id).await {
return send_rk_res(socket, addr, TOO_FREQUENT).await;