From cfa1aeb5b7e2f71306a496e7ce10072fdd31f03c Mon Sep 17 00:00:00 2001 From: eric Date: Fri, 4 Dec 2026 01:33:59 +0800 Subject: [PATCH] fix(conf): refuse interface keys that were never acted on dns-interface in [General] and interface= on a [Proxy] line were parsed and then dropped, so traffic meant for a chosen interface left through the default route while the config said otherwise. Both are now errors that point to OUTBOUND_INTERFACE, which binds every socket leaf opens. last-resort on a failover group was dropped the same way. Ignoring it fails closed -- with every actor down, connections fail rather than go elsewhere -- so it stays accepted, with a warning that says so. --- docs/configuration.md | 8 ++++---- leaf/src/config/conf/config.rs | 34 +++++++++++++++++++++++++++------- 2 files changed, 31 insertions(+), 11 deletions(-) diff --git a/docs/configuration.md b/docs/configuration.md index 61d86bd..6412161 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -882,7 +882,7 @@ quotes nothing. There is no way to write a `"` inside a quoted value. |---|---| | `loglevel`, `logoutput`, `logformat` | `log.level`, `log.output`, `log.format` | | `dns-server = a, b` | `dns.servers` | -| `dns-interface` | Read and ignored | +| `dns-interface` | Refused: it was never acted on. `OUTBOUND_INTERFACE` in `[Env]` binds every socket leaf opens, DNS included | | `interface`, `port` (or `http-interface`, `http-port`) | An `http` inbound, tag `http`, when both are set | | `socks-interface`, `socks-port` | A `socks` inbound, tag `socks`, no authentication, when both are set | | `tun = auto` | A `tun` inbound with `auto` | @@ -926,7 +926,7 @@ used across a network that is watched. The keys: | `quic=true` | A `quic` transport instead of TLS, ALPN `http/1.1` | | `uuid`, `username` | The VMess or VLESS id | | `reality-public-key`, `reality-short-id` | `reality` settings | -| `interface` | Read and ignored | +| `interface` | Refused, as `dns-interface` | ### `[Proxy Group]` @@ -943,8 +943,8 @@ The `failover` keys are the JSON settings in kebab-case: `fail-timeout`, `health-check-active`, `health-check-prefers`, `health-check-on-start`, `health-check-wait`, `health-check-attempts`, `health-check-success-percentage`, `fallback-cache`, `cache-size`, -`cache-timeout`. `last-resort` names an outbound to use when every actor is -down; it is read but not yet passed on. +`cache-timeout`. `last-resort` is not implemented: leaf prints a warning and +ignores it, so when every actor is down connections fail. ### `[Rule]` diff --git a/leaf/src/config/conf/config.rs b/leaf/src/config/conf/config.rs index 269cac1..83745ba 100644 --- a/leaf/src/config/conf/config.rs +++ b/leaf/src/config/conf/config.rs @@ -591,7 +591,11 @@ pub fn from_lines(lines: Vec>) -> Result { general.dns_server = get_char_sep_slice(parts[1], ','); } "dns-interface" => { - general.dns_interface = get_string(parts[1]); + // Never acted on: queries left through the default route, + // not the interface the deployer named. + return Err(anyhow::anyhow!( + "dns-interface is not supported; set OUTBOUND_INTERFACE in [Env], which binds every socket leaf opens" + )); } "always-real-ip" => { general.always_real_ip = get_char_sep_slice(parts[1], ','); @@ -741,7 +745,11 @@ pub fn from_lines(lines: Vec>) -> Result { proxy.reality_short_id = Some(v.to_string()); } "interface" => { - proxy.interface = v.to_string(); + // Never acted on, as dns-interface. + return Err(anyhow::anyhow!( + "[{}] interface is not supported; set OUTBOUND_INTERFACE in [Env], which binds every socket leaf opens", + proxy.tag + )); } _ => {} } @@ -884,11 +892,13 @@ pub fn from_lines(lines: Vec>) -> Result { group.cache_timeout = i; } "last-resort" => { - group.last_resort = if !v.is_empty() { - Some(v.to_owned()) - } else { - None - }; + // Not implemented. Ignoring it fails closed: with + // every actor down the connection fails rather + // than going elsewhere. + println!( + "[{}] last-resort is not supported and is ignored: when every actor is down, connections fail", + group.tag + ); } "health-check-timeout" => { let i = v.parse().ok(); @@ -2075,4 +2085,14 @@ mod value_tests { assert_eq!(p[0].encrypt_method.as_deref(), Some("aes-128-gcm")); assert_eq!(p[0].password.as_deref(), Some("secret")); } + + #[test] + fn keys_that_were_never_acted_on_are_refused() { + let parse = |conf: &str| from_lines(conf.lines().map(|s| Ok(s.to_string())).collect()); + assert!(parse("[General]\ndns-interface = en0\n").is_err()); + assert!(parse("[Proxy]\nT = trojan, 1.2.3.4, 443, pw, interface=en0\n").is_err()); + assert!( + parse("[Proxy]\nA = direct\n[Proxy Group]\nG = failover, A, last-resort=A\n").is_ok() + ); + } }