windows: protect the state directory, names that become files, logs

The state directory gets a protected DACL (SYSTEM and Administrators)
at every start; on Windows programs run only from its bin\, never from
PATH; rule-set and geodata names are validated before they become file
names, and checked again where they do; logs need the secrets scope.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
faumarayandClaude Opus 5.5 committed 2026-10-26 23:16:40 +03:00
1 parent 41c8ed4406
commit d678976c2d
6 files changed
+96 -3

No files matched your search

@@ -57,6 +57,15 @@ pub(crate) fn path_name_ok(name: &str) -> bool {
&& name.chars().all(|c| c.is_ascii_alphanumeric() || matches!(c, '.' | '_' | '-'))
}
/// A geosite or geoip name: "geolocation-!cn" and "google@cn" among them, never a path
/// (upstream's routing-render.jq `geo`).
pub(crate) fn geo_name_ok(name: &str) -> bool {
!name.is_empty()
&& name.len() <= 64
&& !name.starts_with('.')
&& name.chars().all(|c| c.is_ascii_alphanumeric() || matches!(c, '!' | '@' | '.' | '_' | '-'))
}
fn profile_name_ok(name: &str) -> bool {
let mut chars = name.chars();
matches!(chars.next(), Some(c) if c.is_ascii_lowercase() || c.is_ascii_digit())
@@ -167,6 +176,25 @@ fn proxy(cfg: &Config, v: &mut Issues) {
}
}
}
let mut geo_lists: Vec<(String, &crate::config::RouteMatch)> = vec![
("proxy.routing.proxy".into(), &p.routing.proxy),
("proxy.routing.direct".into(), &p.routing.direct),
("proxy.routing.block".into(), &p.routing.block),
];
geo_lists.extend(p.routing.rules.iter().enumerate().map(|(i, r)| (format!("proxy.routing.rules.{i}"), &r.matches)));
geo_lists.extend(p.outbounds.iter().enumerate().map(|(i, o)| (format!("proxy.outbounds.{i}.routing"), &o.routing)));
for (path, m) in geo_lists {
for name in m.geosites.iter().chain(&m.geoips) {
if !geo_name_ok(name) {
v.error(&path, format!("'{name}' is not a geosite or geoip name: letters, digits, '!', '@', '.', '_' and '-'"));
}
}
}
for name in p.routing.rule_sets.keys() {
if !path_name_ok(name) {
v.error(format!("proxy.routing.ruleSets.{name}"), "a rule set name takes letters, digits, '.', '_' and '-', and no leading dot");
}
}
if !p.routing.rule_sets.is_empty() && !sing_box {
v.error("proxy.routing.ruleSets", "rule sets need the sing-box or hybrid backend");
}