Commit Graph
13 Commits
Author SHA1 Message Date
eric 7899cadebc feat(failover): let the deployer choose where health checks go
Every failover health check connected to www.google.com:443 and asked
1.1.1.1:53 about www.google.com, through every actor, direct ones
included, on a timer. That is a fixed pattern an observer can match,
direct DNS in the clear, and where Google is blocked a direct actor was
always marked down. The TLS check also sent "GET / HTTP/1.1" with no Host
header, which no browser does.

healthCheckTcpDestination (host:port) and healthCheckUdpDestination
(ip:port), health-check-tcp-destination and health-check-udp-destination
in .conf, now set them; the defaults are unchanged. The DNS check asks
for the TCP destination's name, or the root zone when that is an
address, and the HTTP request carries a Host header, with the port when
it is not 443. An IPv6 address must be in brackets. A malformed value
fails at startup.

A test runs real checks through a direct actor against local listeners.
2026-12-04 09:55:40 +08:00
eric 4135f4fe64 fix(config): pass a failover's last resort on to the outbound
The failover outbound has always supported a last resort, used when the
last health check found every actor down, but neither config format
passed it on: JSON had no key for it and .conf parsed last-resort and
dropped it. The previous commit took that for a missing feature and only
warned. JSON now takes lastResort, and .conf's last-resort is passed on.

The outbound manager also took a last-resort tag it had not loaded yet
for none at all. It now waits for that tag as it does for actors. A tag
that names no outbound is a configuration error, rather than something
to wait for until the group quietly fails to load. And any outbound
still not loaded at the end -- one it uses is missing, or the build
leaves its protocol out -- is now named in a warning instead of
vanishing.

The docs say what a direct last resort means: everything goes direct
whenever the proxy is found down.
2026-12-04 09:55:40 +08:00
eric cfa1aeb5b7 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.
2026-12-04 09:55:40 +08:00
eric cedceea53e fix(conf): keep = in values, and let quotes hold commas
The .conf parser split every key=value at each =, and dropped the
parameter when that gave more than two parts, so a base64 password or
key vanished without a word. The same applied to [Env], [General] and
[Host] lines. A comma could not be written at all, and a positional value
containing = was skipped while still counting as a position, which
shifted the ones after it.

A key=value is now split at its first =. In [Proxy] and [Proxy Group]
lines a value in double quotes is taken whole, commas included, and
positional values are counted among themselves. A quote opens a value
only at its start or right after key=, so one inside a value, as in
password=ab"cd, stays an ordinary character, and a quote that never
closes quotes nothing rather than taking the rest of the line.
2026-12-04 09:55:40 +08:00
eric 64f5a7b294 fix(config): accept camelCase for the amux connection limits
Every two-word JSON key is camelCase with a snake_case alias, except
amux's max_recv_bytes and max_lifetime, which took snake_case only.
maxRecvBytes and maxLifetime were ignored without a word, so a limit
meant to retire connections never applied. Both spellings now work.
2026-12-04 09:55:40 +08:00
eric 3e2c66d539 fix(config): refuse a client key on tls and quic outbounds
Both outbounds accepted certificateKey and rawCertificateKey and never
used them: neither presents a client certificate. Someone who set one
believed the server could tell this client apart, and it could not.

Setting either is now a configuration error naming the outbound. The
dead branches that chose between identical no-client-auth builders are
gone.
2026-12-04 09:55:40 +08:00
eric 857d3393f5 fix(config): give vmess security a default, and refuse an unknown one
A JSON vmess outbound with no security, or one leaf does not implement,
was accepted, and every connection through it then failed with
"unsupported cipher". The .conf format already defaulted to
chacha20-ietf-poly1305; JSON now does the same, and any other value is a
configuration error at startup. The value is accepted in any case and
stored lowercase, which is the only spelling the cipher table knows.
2026-12-04 09:55:40 +08:00
eric 99258453cf fix(socks): authenticate UDP and SOCKS4 when a password is required
A socks inbound with a username checked it on SOCKS5 TCP and nowhere
else. SOCKS4 has no password, and was accepted anyway, so any client
could skip the check by speaking the older protocol. The UDP relay
answered datagrams from any address. And a username with no password
panicked on the right username, which a release build turns into an
abort.

With a username set, SOCKS4 is now refused, and the relay drops datagrams
from any IP address without an open, authenticated UDP ASSOCIATE
connection, as RFC 1928 asks; the association ends with that connection.
It is open before the reply goes out, since a client may send its first
datagram the moment it reads the reply. A username without a password
means an empty password, and a password without a username is a
configuration error instead of silently turning authentication off.

The UDP check is by IP address, since a client's sending port is not
known in advance; the docs say what that leaves open.
2026-12-04 09:55:40 +08:00
eric 01e755e35b fix(router): match geoip codes as alternatives, fail closed on missing lists
Every condition's values are alternatives except geoip's: each country
code was its own condition, ANDed with the rest, so a rule naming two
countries matched nothing.

A rule source that could not be loaded was worse. A missing geo.mmdb, or an
external site list that failed to load or held nothing for its tag, simply
left its condition out, and the rest of the rule matched on its own: a rule
for one country's TCP traffic took all TCP traffic.

A country whose database cannot be opened, and an external list that
cannot be loaded, now match nothing. When that leaves the rule with no
condition of that kind, the whole rule is dropped with a warning, so its
traffic falls through to the rules below it. The tests build a small
MaxMind database of their own; on the old router they fail.
2026-12-04 09:55:40 +08:00
eric 752d34ddfd fix(dispatcher): bound an outbound's handshake
The dial to an outbound was bounded by OUTBOUND_DIAL_TIMEOUT, and nothing
after it was. A server that accepted and then never answered -- a TLS
ClientHello with no ServerHello, a WebSocket upgrade with no reply -- held
the session, and every plugin instance in its chain, for as long as the
server stayed up. The client could not end it: leaf does not read from
the client until the handshake is done, so it never saw the client leave.

OUTBOUND_HANDSHAKE_TIMEOUT, thirty seconds by default and 0 for none, now
bounds the protocol handshake of stream and datagram outbounds.

A failover is the exception. It already gives each actor its own
failTimeout, and one limit around all of them would cut it off before
its later actors and its last resort. The dispatcher leaves it unbounded
as a whole, and the failover puts the limit around its last resort,
which had none. A select passes on whether its chosen actor is one.
2026-12-04 09:55:40 +08:00
eric f67087f2f5 fix(socks): offer only the password in leaf's own SOCKS5 outbound
leaf's SOCKS5 outbound had the same fault as the C and Zig plugins: with
credentials configured it offered "no authentication" as well, and
carried on if the server picked it.

It used async-socks5, which always offers both, so the handshake is now
leaf's own and the dependency is gone. With credentials set,
username/password is the only method offered, and a server that picks
anything else is refused before the request goes out. A password set
without a username, which would quietly turn authentication off, is a
configuration error, as it is on the inbound.

That also fixes three things in its UDP path: a reply that could not be
parsed ended the association instead of being dropped; a relay given as
0.0.0.0 sent datagrams to this host rather than to the server; and the
UDP ASSOCIATE request named the server as DST.ADDR, where RFC 1928 wants
the client's sending address or zeros, so a server that enforced it
dropped every datagram. It now sends zeros.
2026-12-04 09:55:40 +08:00
eric c2f48d337a fix(fakedns): match filters as domains, not substrings
fakeDnsInclude and fakeDnsExclude (always-fake-ip and always-real-ip in
.conf) matched an entry anywhere in the name. One written for example.com
also covered notexample.com and example.com.evil.net, so a name the
deployer never listed could be given a fake address, or a real lookup,
on the strength of a few letters it contained.

An entry now covers that domain and the names under it, label by label
and ignoring case; * still covers everything. A keyword entry that relied
on the old behaviour now matches only a domain of that name, which the
docs say.
2026-12-04 09:55:40 +08:00
eric 730e8a6dae docs: a configuration reference, and what each choice exposes
docs/configuration.md lists every JSON option, environment variable and
command-line flag: what it does, what it accepts, and what happens when it
is left out, with the .conf keys mapped onto them. Options that decide
whether traffic stays behind the proxy are marked.

docs/security.md explains those choices together: names looked up outside
the proxy, where unmatched traffic goes, direct fallback, IPv6 under TUN,
certificate checks, logs, and how the protocols fare on filtered networks,
without presenting any as safe from a censor. It ends with a configuration
to start from, which has been run.

examples/README.md says what each example is for and what to change before
deploying one. The README links all three and no longer names the TUN
stacks that were replaced.
2026-12-04 09:55:40 +08:00