[GH-ISSUE #6874] [Bug]: TUIC inbound currently does not follow per-user routing rules #4567

Closed
opened 2026-10-31 20:40:34 +07:00 by bsakaguchi · 1 comment
Owner

Originally created by @DimkaTsv on GitHub (Oct 19, 2026).
Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/6874

Describe the bug

TUIC inbound traffic does not follow routing rules that are based on USER tag.

In other words, if i have this set of rules:

  1. USER TEST_1 -> OUTBOUND_1 (capture all inbounds from user_1)
  2. TUIC_INBOUND + USER TEST_1 -> OUTBOUND_2 (capture TUIC inbound specifically from user_1)
  3. TUIC_INBOUND -> OUTBOUND_3 (capture TUIC inbound globally)

then TUIC traffic will always follow rule 3, ignoring first two, as it does not see user tags.

For comparison, AmneziaWG traffic, while also comes from external module, does follow them properly, even if it does not show actual USER in access logs.

P.S. Also, is it possible to make user from such connection to be shown in access logs? Currently all connections come from 127.0.0.1 without user marking, making it harder to debug rules.

How to reproduce the problem

  1. Create TUIC inbound. You can also create AmneziaWG inbound for confirmation.
  2. Create user with link to inbounds above, USER_1
  3. Set routing rules like this:
    3.1 USER_1 -> outbound_1
    3.2 USER_1 + TUIC / AWG inbounds -> outbound_1
    3.3 TUIC / AWG inbounds -> outbound_2
  4. Export both links and try to use them.
  5. Observe that TUIC will be routed to outbound_2, while AWG will be routed to outbound_1

Expected behavior

TUIC should not be an exception from routing rules category.
USER based routing should apply to it as well.

Actual behavior

Currently TUIC ignores any rule that routes based on USER tag. Instead it mostly follows IP/Domain/Inbound rules.

Relevant logs

This is logic issue, no applicable logs can be provided.

Screenshots

No response

3x-ui version

3.10.2

Xray-core version

26.10.10

How did you install 3x-ui?

install.sh script

Operating system

Debian 13

Which parts of the panel are affected?

Backend (API endpoints, login, settings)

Browser (only if it is a UI bug)

No response

Is the panel behind a reverse proxy or CDN?

No — direct access

Before submitting

  • I searched existing issues and this bug has not been reported.
  • I am running the latest released version of 3x-ui (or have verified the bug still exists on it).
  • This bug report is written in English.
  • I have redacted any sensitive data (tokens, real domains, client UUIDs).
Originally created by @DimkaTsv on GitHub (Oct 19, 2026). Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/6874 ### Describe the bug TUIC inbound traffic does not follow routing rules that are based on USER tag. In other words, if i have this set of rules: 1. USER TEST_1 -> OUTBOUND_1 (capture all inbounds from user_1) 2. TUIC_INBOUND + USER TEST_1 -> OUTBOUND_2 (capture TUIC inbound specifically from user_1) 3. TUIC_INBOUND -> OUTBOUND_3 (capture TUIC inbound globally) then TUIC traffic will always follow rule 3, ignoring first two, as it does not see user tags. For comparison, AmneziaWG traffic, while also comes from external module, does follow them properly, even if it does not show actual USER in access logs. P.S. Also, is it possible to make user from such connection to be shown in access logs? Currently all connections come from 127.0.0.1 without user marking, making it harder to debug rules. ### How to reproduce the problem 1. Create TUIC inbound. You can also create AmneziaWG inbound for confirmation. 2. Create user with link to inbounds above, USER_1 3. Set routing rules like this: 3.1 USER_1 -> outbound_1 3.2 USER_1 + TUIC / AWG inbounds -> outbound_1 3.3 TUIC / AWG inbounds -> outbound_2 4. Export both links and try to use them. 5. Observe that TUIC will be routed to outbound_2, while AWG will be routed to outbound_1 ### Expected behavior TUIC should not be an exception from routing rules category. USER based routing should apply to it as well. ### Actual behavior Currently TUIC ignores any rule that routes based on USER tag. Instead it mostly follows IP/Domain/Inbound rules. ### Relevant logs ```shell This is logic issue, no applicable logs can be provided. ``` ### Screenshots _No response_ ### 3x-ui version 3.10.2 ### Xray-core version 26.10.10 ### How did you install 3x-ui? install.sh script ### Operating system Debian 13 ### Which parts of the panel are affected? Backend (API endpoints, login, settings) ### Browser (only if it is a UI bug) _No response_ ### Is the panel behind a reverse proxy or CDN? No — direct access ### Before submitting - [x] I searched [existing issues](../issues?q=is%3Aissue) and this bug has not been reported. - [x] I am running the latest released version of 3x-ui (or have verified the bug still exists on it). - [x] This bug report is written in English. - [x] I have redacted any sensitive data (tokens, real domains, client UUIDs).
bsakaguchi 2026-10-31 20:40:34 +07:00
  • closed this issue
  • added the
    bug
    label
Author
Owner

@github-actions[bot] commented on GitHub (Oct 19, 2026):

Confirmed. The source shows exactly what you describe: TUIC traffic reaches Xray through a loopback SOCKS5 inbound set to "auth":"noauth". Xray never authenticates a user on that connection, so user routing rules can't match TUIC traffic. Rules that match only the inbound tag, IP or domain still work. AmneziaWG works because its relay inbound uses password auth with one account per peer email.

How it happens

The TUIC server already passes each client's email as the SOCKS username, both for TCP (internal/tuic/server.go:593) and UDP (internal/tuic/udp_associations.go:93):

socksConn, err := s.relay.DialTCP(ctx, user.Email, target)

socks5Handshake (internal/tuic/socks_bridge.go:337) offers both "no auth" and "username/password", and accepts whichever one the server picks. The Xray inbound that panel generates for TUIC is noauth (internal/web/service/xray.go:816):

tuicEgressSocksSettings = `{"auth":"noauth","udp":true}`

Xray therefore picks "no auth" (case 0x00: // no auth → return nil). The email is never sent, and the session has no user attached.

AmneziaWG does this differently. injectAmneziawgnetSocks (internal/web/service/xray.go:787-797) collects peer emails and calls amneziawgnet.SocksInboundSettings(emails, amneziawgnet.SocksPassword()). The result is auth: password with accounts[].user = email, so Xray attaches the user and user rules match.

The TUIC package already has the matching helper, tuic.SocksInboundSettings (internal/tuic/socks_bridge.go:564, "one username/password account per email"), and the relay already holds SocksPassword() (internal/tuic/manager.go:108). Nothing calls that helper, though. injectTuicSocks never builds an account list. The per-user plumbing is half built rather than deliberately left out. The only thing pinning noauth is internal/web/service/inbound_tuic_test.go:76, which asserts the current value. No comment in the source explains why it would be intended.

There's no workaround inside the panel. Until this is fixed, route TUIC traffic with inbound-tag, IP or domain rules, or give the users that need special routing their own TUIC inbound.

Verdict:        Confirmed bug
Severity:       Medium
Confidence:     High
Root cause:     internal/web/service/xray.go:816 / injectTuicSocks (:822-847) - the TUIC relay
                SOCKS inbound is generated as {"auth":"noauth","udp":true}, so Xray picks method 0x00
                and never receives the client email the TUIC server sends as SOCKS username.
                Introduced in 0054e671 "feat(tuic): implement native in-process Go TUIC v5 server (#6577)".
Same class:     The TCP (internal/tuic/server.go:593) and UDP (internal/tuic/udp_associations.go:93)
                paths both reach this same inbound and both lose identity. The MTProto egress bridge
                (xray.go:685) is also noauth, but mtg-multi sends no per-client identity at all, so
                that is a different cause, not this bug.
Already fixed:  Still present on the default branch (a8d0700b).
Duplicate of:   None
Evidence:       xray.go:816 tuicEgressSocksSettings = `{"auth":"noauth","udp":true}`;
                xray.go:797 amneziawgnet.SocksInboundSettings(emails, amneziawgnet.SocksPassword());
                tuic/socks_bridge.go:564 SocksInboundSettings (defined, never called);
                tuic/socks_bridge.go:348 `case 0x00: // no auth` → return nil;
                inbound_tuic_test.go:76 pins auth=noauth.
Not determined: None for the routing defect. Not run here; a reproduction is to check that
                Xray's access log shows no `email:` on TUIC connections.

Suggested fix: In injectTuicSocks, generate the inbound the way injectAmneziawgnetSocks does: call tuic.SocksInboundSettings(emails, tuic.SocksPassword()) with the emails of the inbound's enabled clients (the same set DesiredTuicInstances keeps). Update inbound_tuic_test.go to match. One side effect to account for: inboundUsesSocksAccounts (internal/xray/hot_diff.go:408) forces a full Xray restart when an account-carrying SOCKS inbound changes. With this fix, TUIC client edits would restart Xray just as AmneziaWG edits do. The SOCKS account list must also stay in sync with the TUIC registry, or a newly added client would fail the relay handshake.

This reply was generated automatically; a maintainer may follow up.

<!-- gh-comment-id:6267096707 --> @github-actions[bot] commented on GitHub (Oct 19, 2026): Confirmed. The source shows exactly what you describe: TUIC traffic reaches Xray through a loopback SOCKS5 inbound set to `"auth":"noauth"`. Xray never authenticates a user on that connection, so `user` routing rules can't match TUIC traffic. Rules that match only the inbound tag, IP or domain still work. AmneziaWG works because its relay inbound uses password auth with one account per peer email. **How it happens** The TUIC server already passes each client's email as the SOCKS username, both for TCP (`internal/tuic/server.go:593`) and UDP (`internal/tuic/udp_associations.go:93`): ```go socksConn, err := s.relay.DialTCP(ctx, user.Email, target) ``` `socks5Handshake` (`internal/tuic/socks_bridge.go:337`) offers both "no auth" and "username/password", and accepts whichever one the server picks. The Xray inbound that panel generates for TUIC is noauth (`internal/web/service/xray.go:816`): ```go tuicEgressSocksSettings = `{"auth":"noauth","udp":true}` ``` Xray therefore picks "no auth" (`case 0x00: // no auth` → `return nil`). The email is never sent, and the session has no user attached. AmneziaWG does this differently. `injectAmneziawgnetSocks` (`internal/web/service/xray.go:787-797`) collects peer emails and calls `amneziawgnet.SocksInboundSettings(emails, amneziawgnet.SocksPassword())`. The result is `auth: password` with `accounts[].user = email`, so Xray attaches the user and `user` rules match. The TUIC package already has the matching helper, `tuic.SocksInboundSettings` (`internal/tuic/socks_bridge.go:564`, "one username/password account per email"), and the relay already holds `SocksPassword()` (`internal/tuic/manager.go:108`). Nothing calls that helper, though. `injectTuicSocks` never builds an account list. The per-user plumbing is half built rather than deliberately left out. The only thing pinning `noauth` is `internal/web/service/inbound_tuic_test.go:76`, which asserts the current value. No comment in the source explains why it would be intended. There's no workaround inside the panel. Until this is fixed, route TUIC traffic with inbound-tag, IP or domain rules, or give the users that need special routing their own TUIC inbound. ``` Verdict: Confirmed bug Severity: Medium Confidence: High Root cause: internal/web/service/xray.go:816 / injectTuicSocks (:822-847) - the TUIC relay SOCKS inbound is generated as {"auth":"noauth","udp":true}, so Xray picks method 0x00 and never receives the client email the TUIC server sends as SOCKS username. Introduced in 0054e671 "feat(tuic): implement native in-process Go TUIC v5 server (#6577)". Same class: The TCP (internal/tuic/server.go:593) and UDP (internal/tuic/udp_associations.go:93) paths both reach this same inbound and both lose identity. The MTProto egress bridge (xray.go:685) is also noauth, but mtg-multi sends no per-client identity at all, so that is a different cause, not this bug. Already fixed: Still present on the default branch (a8d0700b). Duplicate of: None Evidence: xray.go:816 tuicEgressSocksSettings = `{"auth":"noauth","udp":true}`; xray.go:797 amneziawgnet.SocksInboundSettings(emails, amneziawgnet.SocksPassword()); tuic/socks_bridge.go:564 SocksInboundSettings (defined, never called); tuic/socks_bridge.go:348 `case 0x00: // no auth` → return nil; inbound_tuic_test.go:76 pins auth=noauth. Not determined: None for the routing defect. Not run here; a reproduction is to check that Xray's access log shows no `email:` on TUIC connections. ``` **Suggested fix:** In `injectTuicSocks`, generate the inbound the way `injectAmneziawgnetSocks` does: call `tuic.SocksInboundSettings(emails, tuic.SocksPassword())` with the emails of the inbound's enabled clients (the same set `DesiredTuicInstances` keeps). Update `inbound_tuic_test.go` to match. One side effect to account for: `inboundUsesSocksAccounts` (`internal/xray/hot_diff.go:408`) forces a full Xray restart when an account-carrying SOCKS inbound changes. With this fix, TUIC client edits would restart Xray just as AmneziaWG edits do. The SOCKS account list must also stay in sync with the TUIC registry, or a newly added client would fail the relay handshake. *This reply was generated automatically; a maintainer may follow up.* <!-- claude-issue:analyst -->
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
MHSanaei/3x-ui#4567
No description provided.