Skip to content

Commit eed64ca

Browse files
committed
v0.3.1: IP-literal destinations -> plain TCP passthrough (always)
User reported log spam on Windows with many 'relay failed: خطای SSL' errors for IP-literal targets like 172.105.237.214:443. Root cause: xray/VLESS, torrent, SSH, and other app-level clients use raw IPs in CONNECT/SOCKS5 targets. Our previous logic would MITM these, see 'POST /' inside the xhttp wrapping, forward to Apps Script, which would then fail SSL-verifying the app's self-signed backend. New heuristic: if the CONNECT target is an IP literal, skip MITM entirely and do plain TCP passthrough. Reasoning: browsers never use raw IPs in CONNECT -- they always have a domain. Any client using an IP literal is using a custom protocol that we have no business MITMing. Effect: xray/VLESS tunnels now work through mhrv-rs SOCKS5 (the app's own TLS wrap passes through untouched). Browser HTTPS still MITM'd + relayed as before (domain CONNECTs). Also downgraded 'relay failed' logs from error to warn so they don't spam the ERROR channel on misrouted traffic.
1 parent a2d0cec commit eed64ca

4 files changed

Lines changed: 25 additions & 5 deletions

File tree

‎Cargo.lock‎

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎Cargo.toml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "mhrv-rs"
3-
version = "0.3.0"
3+
version = "0.3.1"
44
edition = "2021"
55
description = "Rust port of MasterHttpRelayVPN -- DPI bypass via Google Apps Script relay with domain fronting"
66
license = "MIT"

‎src/domain_fronter.rs‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -318,12 +318,15 @@ impl DomainFronter {
318318
Ok(Ok(bytes)) => bytes,
319319
Ok(Err(e)) => {
320320
self.relay_failures.fetch_add(1, Ordering::Relaxed);
321-
tracing::error!("Relay failed: {}", e);
321+
// Most upstream errors (self-signed certs, unreachable hosts,
322+
// non-HTTP endpoints) are normal for misrouted traffic. Log
323+
// at warn so they don't spam error channels.
324+
tracing::warn!("relay failed: {}", e);
322325
return error_response(502, &format!("Relay error: {}", e));
323326
}
324327
Err(_) => {
325328
self.relay_failures.fetch_add(1, Ordering::Relaxed);
326-
tracing::error!("Relay timeout");
329+
tracing::warn!("relay timeout");
327330
return error_response(504, "Relay timeout");
328331
}
329332
};

‎src/proxy_server.rs‎

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,17 @@ async fn dispatch_tunnel(
308308
return do_sni_rewrite_tunnel_from_tcp(sock, &host, port, mitm, rewrite_ctx).await;
309309
}
310310

311-
// 2. Peek at the first byte to detect TLS vs plain. Time-bounded — if the
311+
// 2. IP-literal destinations are almost always app-level custom protocols
312+
// (xray/VLESS, torrent, SSH, VPN, raw TCP). Browsers never use raw IPs
313+
// in CONNECT. MITMing these would break the app's own TLS/auth, and
314+
// trying to relay opaque bytes through Apps Script always fails.
315+
// Always plain TCP passthrough for IP literals.
316+
if is_ip_literal(&host) {
317+
plain_tcp_passthrough(sock, &host, port).await;
318+
return Ok(());
319+
}
320+
321+
// 3. Peek at the first byte to detect TLS vs plain. Time-bounded — if the
312322
// client doesn't send anything within 300ms, assume server-first
313323
// protocol (SMTP, POP3, FTP banner) and jump straight to plain TCP.
314324
let mut peek_buf = [0u8; 8];
@@ -345,6 +355,13 @@ async fn dispatch_tunnel(
345355
Ok(())
346356
}
347357

358+
// ---------- IP literal detection ----------
359+
360+
fn is_ip_literal(host: &str) -> bool {
361+
let h = host.trim_start_matches('[').trim_end_matches(']');
362+
h.parse::<std::net::IpAddr>().is_ok()
363+
}
364+
348365
// ---------- Plain TCP passthrough ----------
349366

350367
async fn plain_tcp_passthrough(mut sock: TcpStream, host: &str, port: u16) {

0 commit comments

Comments
 (0)