windows: refuse loopback through the proxy; Clash API always has a secret

Per-app rules naming an outbound that is not running are left out with a
warning instead of failing the start, and failover renders as sing-box's
own urltest until the service drives it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
faumarayandClaude Opus 5.5 committed 2026-10-26 22:57:06 +03:00
1 parent 3665f7f5a0
commit 130c020151
3 files changed
+24 -14

No files matched your search

+18 -9
View File
@@ -139,15 +139,21 @@ pub(super) fn direct_match(input: &Input) -> RouteMatch {
/// The rules that pick an outbound by program, and the loopback hops' guard: kept in every
/// route mode, ahead of everything that picks by destination, as upstream's pin rules are.
fn always_rules(input: &Input) -> Vec<Value> {
fn always_rules(input: &Input, known: &dyn Fn(&str) -> bool, warnings: &mut Vec<String>) -> Vec<Value> {
let cfg = input.cfg;
let mut rules = Vec::new();
if !input.env.direct_processes.is_empty() {
rules.push(json!({ "process_path": input.env.direct_processes, "outbound": "direct" }));
}
if cfg.per_app_routing.enable {
for (i, prof) in cfg.per_app_routing.profiles.iter().enumerate() {
let _ = i;
for prof in &cfg.per_app_routing.profiles {
if !derived::BUILTIN_TAGS.contains(&prof.outbound.as_str()) && !known(&prof.outbound) {
warnings.push(format!(
"per-app profile '{}': no outbound or group named '{}' is running; its programs follow the routing",
prof.name, prof.outbound
));
continue;
}
let inbound = per_app_inbound(&prof.name);
rules.push(target(json!({ "inbound": [inbound] }), &prof.outbound));
if !prof.process_names.is_empty() {
@@ -187,12 +193,15 @@ pub(super) fn route(input: &Input, hop_ports: &[u16], known: &dyn Fn(&str) -> bo
if onion {
common.push(json!({ "domain_suffix": ["onion"], "outbound": derived::TOR_OUTBOUND_TAG }));
}
// A client asking for a loopback hop would have sing-box dial the helpers' listeners
// for it, past the routing.
if !hop_ports.is_empty() {
common.push(json!({ "ip_cidr": LOOPBACK, "port": hop_ports, "action": "reject" }));
}
common.extend(always_rules(input));
// Nothing reaches this host's loopback through the proxy: the helpers' listeners, the
// Clash API and whatever else listens there would be a client's for the asking, a LAN
// client's too when the listener is exposed. Upstream guards only the hops (its firewall
// keeps the rest from other users); Windows has no such firewall here, so every port. A
// name that resolves to loopback on its own is not caught: keep the listener on loopback.
let _ = hop_ports;
common.push(json!({ "ip_cidr": LOOPBACK, "action": "reject" }));
common.push(json!({ "domain": ["localhost"], "domain_suffix": [".localhost"], "action": "reject" }));
common.extend(always_rules(input, known, warnings));
// The custom rules: each outbound's own routing, then routing.rules, at their priority.
let mut sections = Vec::new();