windows: share-link and subscription parsing, admin-only edits
ps-core::links ports upstream's proxy_url_parsers.py and proxy_parsing.py: every scheme, each backend's refusals, XRay rendering, subscription decoding, tags and the server checks. Upstream's build-outbound tests are ported case for case, and tools/parity/links.py runs ~750 links through both implementations: no differences. config::privileged_changes names the edits only an administrator may make: anything that runs a program, passes arguments through, or names a local file, since the service runs as LocalSystem. Names that become paths or service names are validated. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
c837db1c18
commit
77d4cefe0e
12 files changed
+2821
-3
No files matched your search
@@ -48,6 +48,15 @@ fn tag_pattern_ok(tag: &str) -> bool {
|
||||
&& chars.all(|c| c.is_ascii_alphanumeric() || matches!(c, '.' | '_' | '-'))
|
||||
}
|
||||
|
||||
/// A name that becomes part of a file path, a Windows service name or an adapter name:
|
||||
/// letters, digits, `.`, `_` and `-`, not starting with a dot, at most 64 characters.
|
||||
pub(crate) fn path_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())
|
||||
@@ -172,6 +181,9 @@ fn proxy(cfg: &Config, v: &mut Issues) {
|
||||
}
|
||||
for (name, group) in &p.groups {
|
||||
let path = format!("proxy.groups.{name}");
|
||||
if !path_name_ok(name) {
|
||||
v.error(&path, format!("group name '{name}' takes letters, digits, '.', '_' and '-', and no leading dot"));
|
||||
}
|
||||
if BUILTIN_TAGS.contains(&name.as_str()) || p.outbounds.iter().any(|o| &o.tag == name) {
|
||||
v.error(&path, format!("group '{name}' takes a tag an outbound or builtin already has"));
|
||||
}
|
||||
@@ -257,6 +269,11 @@ fn tunnels(cfg: &Config, v: &mut Issues) {
|
||||
if w.config_file.is_some() && w.config.is_some() {
|
||||
v.error("warp.config", "set configFile or config, not both");
|
||||
}
|
||||
for name in w.devices.keys() {
|
||||
if !path_name_ok(name) {
|
||||
v.error(format!("warp.devices.{name}"), "a device name takes letters, digits, '.', '_' and '-', and no leading dot");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let a = &cfg.amnezia_wg;
|
||||
@@ -275,10 +292,14 @@ fn tunnels(cfg: &Config, v: &mut Issues) {
|
||||
v.warn(format!("{path}.autostart"), "an outbound always runs: autostart only applies to a global profile");
|
||||
}
|
||||
v.requires(p.as_outbound.is_some(), proxy_on, &format!("{path}.asOutbound"), &format!("amneziaWg.profiles.{name}.asOutbound"), "proxy.enable = true");
|
||||
if !path_name_ok(name) {
|
||||
v.error(&path, format!("profile name '{name}' takes letters, digits, '.', '_' and '-', and no leading dot"));
|
||||
}
|
||||
if let Some(iface) = &p.interface_name
|
||||
&& (iface.is_empty() || iface.len() > 32 || !iface.chars().all(|c| c.is_ascii_alphanumeric() || matches!(c, '_' | '-' | '.'))) {
|
||||
v.error(format!("{path}.interfaceName"), "a tunnel name takes letters, digits, '_', '-' and '.' (at most 32)");
|
||||
}
|
||||
&& (!path_name_ok(iface) || iface.len() > 32)
|
||||
{
|
||||
v.error(format!("{path}.interfaceName"), "a tunnel name takes letters, digits, '.', '_' and '-' (at most 32, no leading dot)");
|
||||
}
|
||||
if let Some(settings) = &p.settings {
|
||||
if settings.peers.is_empty() {
|
||||
v.error(format!("{path}.settings.peers"), "a profile needs a peer");
|
||||
@@ -349,6 +370,11 @@ fn tunnels(cfg: &Config, v: &mut Issues) {
|
||||
let wl = &cfg.whitelist_bypass;
|
||||
if wl.enable {
|
||||
v.requires(!wl.joiners.is_empty(), proxy_on, "whitelistBypass.joiners", "whitelistBypass.joiners", "proxy.enable = true");
|
||||
for name in wl.joiners.keys().chain(wl.creators.keys()) {
|
||||
if !path_name_ok(name) {
|
||||
v.error(format!("whitelistBypass.{name}"), "a creator or joiner name takes letters, digits, '.', '_' and '-', and no leading dot");
|
||||
}
|
||||
}
|
||||
for (name, j) in &wl.joiners {
|
||||
if j.platform == crate::config::WlPlatform::Vk {
|
||||
v.error(format!("whitelistBypass.joiners.{name}.platform"), "VK has no joiner here");
|
||||
@@ -447,6 +473,9 @@ fn inbounds(cfg: &Config, v: &mut Issues) {
|
||||
let mut ports: BTreeMap<(u16, bool), &str> = BTreeMap::new();
|
||||
for (tag, l) in &ib.listeners {
|
||||
let path = format!("inbounds.listeners.{tag}");
|
||||
if !path_name_ok(tag) {
|
||||
v.error(&path, format!("listener tag '{tag}' takes letters, digits, '.', '_' and '-', and no leading dot"));
|
||||
}
|
||||
let sources = [l.kind.is_some(), l.xray_json.is_some(), l.json_file.is_some()];
|
||||
if count_some(&sources) != 1 {
|
||||
v.error(&path, format!("listener '{tag}' needs exactly one of type, xrayJson and jsonFile"));
|
||||
@@ -498,6 +527,9 @@ fn inbounds(cfg: &Config, v: &mut Issues) {
|
||||
|
||||
let mut orders = BTreeMap::new();
|
||||
for (name, user) in &ib.users {
|
||||
if !path_name_ok(name) {
|
||||
v.error(format!("inbounds.users.{name}"), format!("user name '{name}' takes letters, digits, '.', '_' and '-', and no leading dot"));
|
||||
}
|
||||
if let Some(order) = user.order
|
||||
&& let Some(other) = orders.insert(order, name) {
|
||||
v.error(format!("inbounds.users.{name}.order"), format!("users '{other}' and '{name}' share order {order}"));
|
||||
@@ -641,6 +673,17 @@ mod tests {
|
||||
assert!(errors(&cfg).iter().any(|e| e.contains("port 1080")));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn names_that_become_paths_are_checked() {
|
||||
let mut cfg = Config::default();
|
||||
cfg.amnezia_wg.enable = true;
|
||||
cfg.amnezia_wg.profiles.insert(
|
||||
"..\\evil".into(),
|
||||
crate::config::AwgProfile { config: Some("[Interface]".into()), ..Default::default() },
|
||||
);
|
||||
assert!(errors(&cfg).iter().any(|e| e.contains("profile name")), "{:?}", errors(&cfg));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn groups_need_sing_box() {
|
||||
let mut cfg = Config::default();
|
||||
|
||||
Reference in new issue
Block a user