Skip to content

Lightweight native Discord client for Windows, Linux and macOS, written in Rust. No Electron, no browser engine.

Fix Go Live voice endpoints with stream IDs (#2)

AlexMeridaPozo72ba850d8bef
diff --git a/crates/voice/src/transport.rs b/crates/voice/src/transport.rs
index c975cc3..e77c171 100644
--- a/crates/voice/src/transport.rs
+++ b/crates/voice/src/transport.rs
@@ -151,8 +151,9 @@ pub(crate) fn negotiation_timeout(
/// Turn the `endpoint` of VOICE_SERVER_UPDATE into the voice WebSocket URL.
///
/// Discord sends `host:port` (e.g. `c-ams05-1a2b3c4d.discord.media:443`), sometimes without
-/// the port; a `wss://` scheme and a trailing slash are tolerated. Only Discord media hosts
-/// are accepted so the voice token is never sent elsewhere.
+/// the port; stream servers append a numeric stream ID to the host. A `wss://` scheme and
+/// a trailing slash are tolerated. Only Discord media hosts are accepted so the voice token
+/// is never sent elsewhere.
pub(crate) fn endpoint(raw: &str) -> Result<String, &'static str> {
let raw = raw.trim();
let raw = raw.strip_prefix("wss://").unwrap_or(raw);
@@ -161,19 +162,24 @@ pub(crate) fn endpoint(raw: &str) -> Result<String, &'static str> {
return Err("Missing Discord voice endpoint");
}
if raw.len() > 256
- || raw.contains('/')
|| raw.contains('@')
|| raw.contains('?')
|| raw.contains('#')
{
return Err("Invalid Discord voice endpoint");
}
- let url = url::Url::parse(&format!("wss://{raw}/?v=8"))
+ if let Some((_, path)) = raw.split_once('/') {
+ if path.is_empty() || path.len() > 24 || !path.bytes().all(|c| c.is_ascii_digit()) {
+ return Err("Invalid Discord voice endpoint");
+ }
+ }
+ let mut url = url::Url::parse(&format!("wss://{raw}"))
.map_err(|_| "Invalid Discord voice endpoint")?;
let host = url.host_str().ok_or("Missing Discord voice host")?;
if !host.ends_with(".discord.media") || url.username() != "" || url.password().is_some() {
return Err("Voice endpoint is outside Discord media");
}
+ url.set_query(Some("v=8"));
Ok(url.into())
}
pub(crate) fn public_ip(ip: IpAddr) -> bool {
@@ -1542,6 +1548,10 @@ mod tests {
"voice-1.discord.media:443/",
"wss://voice-1.discord.media/?v=8",
),
+ (
+ "snam.discord.media:443/1234567890123456789",
+ "wss://snam.discord.media/1234567890123456789?v=8",
+ ),
(
" voice-1.discord.media:2096 ",
"wss://voice-1.discord.media:2096/?v=8",
@@ -1555,6 +1565,9 @@ mod tests {
"127.0.0.1:9",
"voice.discord.media.evil.test",
"voice.discord.media/path",
+ "voice.discord.media/123/456",
+ "voice.discord.media/123?token=x",
+ "voice.discord.media.evil.test/123",
"voice.discord.media?token=x",
"http://voice.discord.media",