`action: bypass` doesn't apply to forwarded traffic since the pre-match chains moved
Operating system
Linux
System version
debian13
Installation type
Original sing-box Command Line
If you are using a graphical client, please provide the version of the client.
No response
Version
sing-box version 1.14.0-rc.4
Environment: go1.26.7 linux/amd64
Tags: with_gvisor,with_quic,with_dhcp,with_wireguard,with_utls,with_acme,with_clash_api,with_tailscale,with_ccm,with_ocm,with_cloudflared,with_naive_outbound,with_usbip,with_openvpn,with_openconnect,badlinkname,tfogo_checklinkname0,with_musl
Revision: 193aba27f722028bc7cdc4e2b096522e11b12964
CGO: enabled
Description
With auto_redirect on a gateway, rules with action: bypass no longer take effect for TCP
and UDP from LAN clients: the traffic goes through sing-box and falls through to later rules.
Locally originated traffic is still bypassed correctly.
Affects sing-box >= 1.14.0-beta.13 (sing-tun >= 909ab10 / v0.9.0-beta.1). Tested on sing-box 1.14.0-rc.4, sing-tun v0.9.0-beta.3, kernel 7.1.8, nftables 1.1.6.
909ab10 ("Fix nfqueue pre-match chain priorities and missing exclude rules") moved
prerouting_prematch from NATDest - 1 to NATDest + 1, and, with NFQUEUE enabled,
the prerouting NAT chain from NATDest + 1 to NATDest + 2.
In practice the chains don't run in that order. DNAT still happens at dstnat (-100)
regardless of what the NAT chain declares — a filter chain at -101 still sees the original
destination, one at -99 doesn't. So prerouting_prematch now runs after the NAT chain and
returns before it reaches its queue rules:
- TCP has already been REDIRECTed, so it returns at
ip daddr @inet4_local_address_set - UDP and ICMP already carry
ct mark 0x2023set by the NAT chain, so they return there
Nothing forwarded reaches NFQUEUE. TCP then arrives as a redirect inbound and UDP as a tun
packet connection, so the rule is only reached in full routing, where a bypass with no
outbound is a no-op (route/route.go) and matching carries on to the next rule.
output_prematch is based on ChainPriorityMangle, so even at Mangle + 1 (-149) it is
still well ahead of -100 — that path is unaffected. main (v0.8.x, used by sing-box 1.13.x)
is still on NATDest - 1.
Reproduction
No remote server needed. config.json:
{ "log": { "level": "debug" }, "inbounds": [ { "type": "tun", "tag": "tun-in", "address": ["172.19.0.1/30"], "auto_route": true, "auto_redirect": true } ], "outbounds": [{ "type": "direct", "tag": "direct" }], "route": { "rules": [{ "ip_cidr": ["223.5.5.5/32"], "action": "bypass" }], "final": "direct", "auto_detect_interface": true } }
-
sing-box run -c config.json -
Put a client behind the box, so no second machine is needed:
ip netns add c ip link add vc type veth peer name vcg ip link set vc netns c ip addr add 10.97.0.1/24 dev vcg; ip link set vcg up ip -n c addr add 10.97.0.2/24 dev vc; ip -n c link set vc up ip -n c route add default via 10.97.0.1 sysctl -w net.ipv4.ip_forward=1 nft add table ip nat97 nft add chain ip nat97 post '{type nat hook postrouting priority 100; policy accept;}' nft add rule ip nat97 post ip saddr 10.97.0.0/24 masquerade
-
From the client, connect to the address the bypass rule covers:
ip netns exec c curl -sk -o /dev/null https://223.5.5.5/
-
nft list chain inet sing-box prerouting_prematch nft list chain inet sing-box prerouting
Expected: the SYN goes to NFQUEUE and is bypassed, so prerouting's redirect to :<port>
never counts it and sing-box logs nothing for the connection.
Actual: the queue flags bypass to <n> rules stay at 0 packets, ip daddr @inet4_local_address_set catches the SYN instead (it has already been redirected),
redirect to :<port> counts 1, and sing-box logs the connection and routes it to direct.
A UDP datagram from the client (printf hello | nc -u -w1 223.5.5.5 4444) behaves the same.
The same request from the box itself is bypassed correctly: output_prematch's TCP queue
rule counts 1, output's redirect rule stays at 0, and the log shows pre-match[0]
instead of match[0].
Cleanup: ip netns del c; ip link del vcg; nft delete table ip nat97
Logs
TCP from the client — pre-match never ran, so the rule is only reached in full routing,
where a `bypass` with no `outbound` does nothing:
INFO inbound/tun[tun-in]: inbound redirect connection from 10.97.0.2:57758
INFO inbound/tun[tun-in]: inbound connection to 223.5.5.5:443
DEBUG router: match[0] ip_cidr=223.5.5.5/32 => bypass()
INFO outbound/direct[direct]: outbound connection to 223.5.5.5:443
UDP from the client, same story:
INFO inbound/tun[tun-in]: inbound packet connection from 10.97.0.2:57107
INFO inbound/tun[tun-in]: inbound packet connection to 223.5.5.5:4444
DEBUG router: match[0] ip_cidr=223.5.5.5/32 => bypass()
INFO outbound/direct[direct]: outbound packet connection
The same TCP request from the box itself is the whole log for that connection:
DEBUG router: pre-match[0] ip_cidr=223.5.5.5/32 => bypass()
`nft monitor trace` for the forwarded SYN. The NAT chain (declared `dstnat + 2`) runs before
`prerouting_prematch` (declared `dstnat + 1`), which then only sees the redirected packet
(fields trimmed):
trace id 1752c914 inet sing-box prerouting packet: iif "vcg" ip saddr 10.97.0.2 ip daddr 223.5.5.5 ip protocol tcp tcp sport 57758 tcp dport 443 tcp flags == syn
trace id 1752c914 inet sing-box prerouting rule meta nfproto ipv4 meta l4proto tcp counter redirect to :39631 return (verdict accept)
trace id 1752c914 inet sing-box prerouting_prematch packet: iif "vcg" ip saddr 10.97.0.2 ip daddr 10.97.0.1 ip protocol tcp tcp sport 57758 tcp dport 39631 tcp flags == syn
trace id 1752c914 inet sing-box prerouting_prematch rule ip daddr @inet4_local_address_set counter return (verdict return)
Forwarded UDP returns one rule earlier, on the conntrack mark the NAT chain has just set:
trace id 7db48d8d inet sing-box prerouting rule meta mark set 0x00002023 ct mark set meta mark return (verdict return)
trace id 7db48d8d inet sing-box prerouting_prematch rule ct mark 0x00002023 return (verdict return)
Supporter
- [ ] I am a sponsor
Integrity requirements
- [x] I confirm that I have read the documentation, understand the meaning of all the configuration items I wrote, and did not pile up seemingly useful options or default values.
- [x] I confirm that I have provided the server and client configuration files and process that can be reproduced locally, instead of a complicated client configuration file that has been stripped of sensitive data.
- [x] I confirm that I have provided the simplest configuration that can be used to reproduce the error I reported, instead of depending on remote servers, TUN, graphical interface clients, or other closed-source software.
- [x] I confirm that I have provided the complete configuration files and logs, rather than just providing parts I think are useful out of confidence in my own intelligence.
I confirm the issue. Bypass still doesn't work in release version 1.14.0.
Since the bypass broken in 1.14.0-beta.13, it is hard for sing-box to coexist with Tailscale and other VPNs. Hope this can be solved soon.
For those who are interested, the developer just pushed a commit, which has fixed this bug: https://github.com/SagerNet/sing-box/commit/4bb61c77171a941ef690aa89926611cd5237f0b8
@nekohasekai Could you please release a fixed version?
Bypass has been fixed in 1.14.1.