Skip to content

TUN inbound's autoSystemWfpBlockLeak: Support "tcp/port" and "udp/port"; "dns" covers "tcp/853" and "udp/853" as well - #7288

Merged
RPRX merged 2 commits into
mainfrom
windows-tun-wfp-ports
Oct 31, 2026
Merged

RPRX merged 2 commits into
mainfrom
windows-tun-wfp-ports

Conversation

@patterniha

Copy link
Copy Markdown
Collaborator

#6853 (comment)

"dns" in autoSystemWfpBlockLeak only blocked port 53 outside the TUN, plus the DNS Client service on Windows 11 and Server 2022 and later, so other programs' DNS over TLS (TCP 853) and DNS over QUIC (UDP 853) could still leave outside the TUN.

autoSystemWfpBlockLeak now takes:

  • "tcp/", "udp/": connections to that port may only go through the TUN (or come from Xray itself).
  • "windnsclient": Windows' DNS Client service may only connect through the TUN, except for mDNS and LLMNR. As before, this only applies from Windows 11 and Server 2022 on, where the service may use DoH or DoT to any port; earlier versions only query port 53.
  • "dns": stands for "udp/53", "tcp/53", "windnsclient", "tcp/853" and "udp/853".
  • "misconfigtun": unchanged.

Values are case-insensitive, deduplicated, and anything else, such as "tcp/0" or "icmp/1", is rejected. Keeping the system's DNS inside the TUN, with "udp/53", "tcp/53" or "windnsclient", needs dns to be set, as "dns" did; ports like 853 alone do not. Each port gets its own permit-through-TUN and block filters with a protocol condition, where port 53 used to have one for both protocols, and the log lists what is blocked, e.g. "[tun] blocked outside the TUN: udp/53, tcp/53, tcp/853, udp/853, windnsclient".

Tested on Windows 11 with a Wintun adapter as the outside interface: with "tcp/853", "udp/853", "tcp/7215" and "udp/7216", those are blocked outside the TUN over IPv4 and IPv6, while tcp/7216, udp/7215 and 443 are not, port 853 works through the TUN, Xray's own connections to port 853 still leave outside it, and nothing is blocked after Xray stops.

…Leak` on Windows; "dns" covers DoT and DoQ as well

"dns" in autoSystemWfpBlockLeak only blocked port 53 outside the TUN, plus
the DNS Client service on Windows 11 and Server 2022 and later, so other
programs' DNS over TLS (TCP 853) and DNS over QUIC (UDP 853) could still
leave outside the TUN.

autoSystemWfpBlockLeak now takes:

- "tcp/<port>", "udp/<port>": connections to that port may only go through
  the TUN (or come from Xray itself).
- "windnsclient": Windows' DNS Client service may only connect through the
  TUN, except for mDNS and LLMNR. As before, this only applies from Windows
  11 and Server 2022 on, where the service may use DoH or DoT to any port;
  earlier versions only query port 53.
- "dns": stands for "udp/53", "tcp/53", "windnsclient", "tcp/853" and
  "udp/853".
- "misconfigtun": unchanged.

Values are case-insensitive, deduplicated, and anything else, such as
"tcp/0" or "icmp/1", is rejected. Keeping the system's DNS inside the TUN,
with "udp/53", "tcp/53" or "windnsclient", needs dns to be set, as "dns"
did; ports like 853 alone do not. Each port gets its own permit-through-TUN
and block filters with a protocol condition, where port 53 used to have one
for both protocols, and the log lists what is blocked, e.g. "[tun] blocked
outside the TUN: udp/53, tcp/53, tcp/853, udp/853, windnsclient".

Tested on Windows 11 with a Wintun adapter as the outside interface: with
"tcp/853", "udp/853", "tcp/7215" and "udp/7216", those are blocked outside
the TUN over IPv4 and IPv6, while tcp/7216, udp/7215 and 443 are not, port
853 works through the TUN, Xray's own connections to port 853 still leave
outside it, and nothing is blocked after Xray stops.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@RPRX

RPRX commented Oct 29, 2026

Copy link
Copy Markdown
Member

TUN 的 README.md 也带上那些 PR #6853 (comment) 的内容,以及近期其它与 TUN 相关的改动

…nt changes in README

Covers #7173 (a connection that cannot be bound fails
instead of leaving unbound), #7214 (IPv4-only and IPv6-only outbound
interfaces on Windows), #7230 (IPV6_BOUND_IF on macOS), and also #7130
(built-in TCP/IP stack), #6874 (IPv6 disabled system-wide on Windows),
#6811 (an existing Wintun adapter is reused) and #6883 (the iOS fd is
duplicated). #7092 and autoSystemWfpBlockLeak were already covered.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@patterniha

Copy link
Copy Markdown
Collaborator Author

TUN 的 README.md 也带上那些 PR #6853 (comment) 的内容,以及近期其它与 TUN 相关的改动

Done, the TUN README now covers #7173, #7214, #7230, and also #7130, #6874, #6811 and #6883 (#7092 and autoSystemWfpBlockLeak were already there).

@RPRX

RPRX commented Oct 30, 2026

Copy link
Copy Markdown
Member

@patterniha 新加的这些是不是不好做双向 block(因为得排除掉 Xray 接收 DNS 响应的情况)?虽然“只 block 发送”也够用了

@patterniha

Copy link
Copy Markdown
Collaborator Author

@patterniha 新加的这些是不是不好做双向 block(因为得排除掉 Xray 接收 DNS 响应的情况)?虽然“只 block 发送”也够用了

No, they're already blocked in both directions, the same as port 53 before, and Xray is excluded.

The filters sit in WFP's ALE (Application Layer Enforcement) layers, which are stateful. ALE connect judges a program's outgoing connection, and for UDP its first packet to each remote IP:port. ALE recv-accept judges incoming connections, and for UDP the first packet from a remote IP:port the socket never sent to. Once a flow is allowed, the rest of it, replies included, is not checked again. Each port gets its filters on both layers, for IPv4 and IPv6, and "permit Xray" (by its app ID) is on all of them with the highest weight.

So:

  • Xray queries a DNS server outside the TUN: allowed at connect, and the replies belong to that flow, so they are never checked.
  • Another program queries port 53/853 outside the TUN: blocked at connect, so no reply comes back either.
  • Another program queries through the TUN: allowed.
  • A packet from port 53/853 arrives outside the TUN without a flow (unsolicited, or a reply from another address than the one queried): blocked at recv-accept, unless it is for Xray.
  • The same packet arriving through the TUN: allowed.
  • Queries to a local DNS server on port 53 (e.g. one serving the LAN): not matched, as the filters match the remote port, not the local one.

Only "windnsclient" is outbound-only, since the DNS Client service only opens connections. In the test, Xray's own queries to port 53 and 853 outside the TUN got their replies while other programs were blocked.

@RPRX RPRX changed the title TUN inbound: Support "tcp/port" and "udp/port" in autoSystemWfpBlockLeak on Windows; "dns" covers DoT and DoQ as well TUN inbound's autoSystemWfpBlockLeak: Support "tcp/port" and "udp/port"; "dns" covers "tcp/853" and "udp/853" as well Oct 31, 2026
@RPRX
RPRX merged commit 6cdd323 into main Oct 31, 2026
46 checks passed
@RPRX

RPRX commented Oct 31, 2026

Copy link
Copy Markdown
Member

@Fangliding XTLS/Xray-docs-next#903 XTLS/Xray-docs-next#906 这俩文档 PR 尽快合并,你可以改

@RPRX

RPRX commented Nov 1, 2026

Copy link
Copy Markdown
Member

@patterniha 是否有必要加一个 "all",即除了 Xray 外的几乎所有流量

@patterniha

Copy link
Copy Markdown
Collaborator Author

是否有必要加一个 "all",即除了 Xray 外的几乎所有流量

Windows' own LAN route is more specific than the TUN's, so LAN traffic leaves outside the TUN and never reaches Xray's bypass rules; "all" would block it, along with incoming connections to other programs (RDP, SMB), mDNS/LLMNR, other VPNs and some VM NATs.

Anyway, we can add it as an opt-in for users who want a strict mode, where nothing but Xray can leave outside the TUN.

RadUnderSun pushed a commit to RadUnderSun/ultimaVLESS that referenced this pull request Nov 1, 2026
- VLESS/Trojan без TLS, REALITY и VLESS Encryption Xray теперь пускает
  только на 10/8, 172.16/12, 192.168/16, loopback, link-local и fc00::/7
  (XTLS/Xray-core#7249). Клиентская копия проверки сужена так же, иначе
  ссылка на 100.64.0.0/10 (CGNAT, Tailscale) или 198.18.0.0/15 проходила
  проверку клиента, а Xray не запускался.
- «Блокировать утечки DNS» (`autoSystemWfpBlockLeak: ["dns"]`) теперь
  закрывает и DNS over TLS/QUIC на порту 853 (XTLS/Xray-core#7288):
  подсказка и комментарий обновлены.

Конфиги клиента (19 ссылок × proxy, TUN auto-route с WFP, TUN split,
режимы «сайты» и «приложения») проверены `xray run -test` v26.10.31.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@RPRX

RPRX commented Nov 2, 2026

Copy link
Copy Markdown
Member

@patterniha 我觉得 "all" 除了 DHCP 这种系统必要的,其它的都可以拦截掉,你测测,以及是否依赖 TUN 其它选项要理清楚

另外补上 "tcp"、“udp”、"icmp",/0 这种写法可以接纳,就按没声明端口即拦截所有来处理,既如此也可以支持范围 /10-20

@RPRX

RPRX commented Nov 2, 2026

Copy link
Copy Markdown
Member

演进方向是即使不需要 TUN 或只需要代理少部分流量,Xray-core 也可以弄一个 GUI 可配置的 Windows 防火墙,现在算是雏形

RPRX pushed a commit that referenced this pull request Nov 2, 2026
…rt alone, port range, "tcp"/"udp" alone or with port range, "icmp", and a CIDR in front of any value; Always allow loopback, DHCP and IPv6 neighbor discovery (#7315)

#7288 (comment)
#7315 (comment)
#7315 (comment)

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
@RPRX
RPRX deleted the windows-tun-wfp-ports branch November 19, 2026 12:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants