windows: no unquoted value can add a directive to Tor's torrc

proxy.listener.address went into the torrc unquoted (Socks5Proxy, with
upstream = "proxy"): a newline in it, set by a user who may change the
configuration, would add a directive, ClientTransportPlugin among them,
which runs a program as SYSTEM (found by the commit security review).
The address is written from its parsed IpAddr now; a bridge line with a
control character in it is refused; and the validator holds every
listen address (the proxy's, the SSH tunnel's, tg-ws-proxy's) to an IP
address, which they all are.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
faumarayandClaude Opus 5.5 committed 2026-10-27 08:06:42 +03:00
1 parent ed2159f7b6
commit d9d52c49b6
2 files changed
+48 -6

No files matched your search

@@ -147,6 +147,17 @@ fn not_ported(cfg: &Config, v: &mut Issues) {
fn proxy(cfg: &Config, v: &mut Issues) {
let p = &cfg.proxy;
let sing_box = p.backend.runs_sing_box();
// Listen addresses reach other programs' configs and command lines (Tor's torrc, ssh's -D,
// tg-ws-proxy's --host): an IP address, nothing else.
for (path, address) in [
("proxy.listener.address", &p.listener.address),
("sshProxy.listener.address", &cfg.ssh_proxy.listener.address),
("tgWsProxy.listener.address", &cfg.tg_ws_proxy.listener.address),
] {
if address.parse::<std::net::IpAddr>().is_err() {
v.error(path, format!("'{address}' is not an IP address"));
}
}
let mut seen = BTreeSet::new();
for (i, ob) in p.outbounds.iter().enumerate() {
@@ -763,6 +774,17 @@ mod tests {
assert_eq!(errors(&Config::default()), Vec::<String>::new());
}
#[test]
fn listen_addresses_are_ip_addresses() {
let mut cfg = Config::default();
assert!(!errors(&cfg).iter().any(|e| e.contains("listener.address")));
cfg.proxy.listener.address = "127.0.0.1\nClientTransportPlugin x exec calc.exe".into();
cfg.tg_ws_proxy.listener.address = "::".into();
let errs = errors(&cfg);
assert!(errs.iter().any(|e| e.starts_with("proxy.listener.address:")), "{errs:?}");
assert!(!errs.iter().any(|e| e.starts_with("tgWsProxy.listener.address:")), "{errs:?}");
}
#[test]
fn ssh_host_and_user_cannot_be_options() {
let mut cfg = Config::default();