mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-03 21:18:19 +07:00
[GH-ISSUE #6062] [Bug]: INCY receives HAPP's Routing header instead of its own routing configuration #4197
Labels
No labels
backlog
bug
clarification needed
documentation
duplicate
enhancement
github_actions
good first issue
invalid
javascript
New Feature
PR welcomed
pull-request
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
MHSanaei/3x-ui#4197
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @aishlai on GitHub (Jul 20, 2026).
Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/6062
Describe the bug
Versions
Description
When both HAPP and INCY routing rules are configured in 3X-UI, the INCY client does not apply its own routing configuration. Instead, it receives and uses the routing configuration intended for HAPP.
In addition, the HAPP routing configuration is not fully compatible with INCY. In particular, GeoIP and GeoSite rules cause problems because iOS limits the memory usage of VPN applications to approximately 50 MB. As a result, INCY must use the Lite versions of the GeoIP and GeoSite databases.
Expected Behavior
When an INCY subscription is requested, the server should return and apply the routing configuration specifically configured for INCY, instead of the HAPP routing configuration.
Additional Information
Suggested Solution
Detect the client type based on the User-Agent of the subscription request and return the corresponding configuration for that client (e.g., HAPP or INCY).
How to reproduce the problem
Steps to Reproduce
Actual Result
The INCY client does not receive its own routing configuration. Instead, it receives the routing configuration intended for HAPP.
Expected behavior
No response
Actual behavior
No response
Relevant logs
Screenshots
No response
3x-ui version
3.5.0
Xray-core version
26.7.11
How did you install 3x-ui?
install.sh script
Operating system
Ubuntu25.04
Which parts of the panel are affected?
No response
Browser (only if it is a UI bug)
No response
Is the panel behind a reverse proxy or CDN?
No — direct access
Before submitting
@github-actions[bot] commented on GitHub (Jul 20, 2026):
This is closely related to #5708 and #5999, which covered the same Happ/Incy conflict. Re-verified against the current source (v3.5.0) rather than assuming those closures fully cover this report, since the fix suggested here is different.
Confirmed in source —
internal/sub/controller.go:ApplyCommonHeaders(lines 696-699) unconditionally sets theRouting-Enable/RoutingHTTP headers from the Happ tab's settings (subEnableRouting/subRoutingRules) on every subscription response whenever Happ routing is enabled, regardless of which client is asking.subshandler (lines 374-377) separately appends the Incy tab'ssubIncyRoutingRules(anincy://routing/onadd/...line) into the subscription body, gated only bysubIncyEnableRouting— again with no check on the requester.Both settings pairs are documented as client-specific in the panel copy itself (
internal/web/translation/en-US.json:subEnableRoutingDesc— "Global setting to enable routing in the VPN client. (Only for Happ)";subIncyEnableRoutingDesc— "Inject a routing profile into the subscription body for the Incy client. (Only for Incy)"), but neither is actually gated by who is asking — there is no User-Agent or other client-identity check anywhere ininternal/sub/. So with both enabled, every client, Happ or Incy, gets both theRoutingheader and the body-injectedincy://line in the same response.In #5708 the maintainer's conclusion was that Incy giving the
Routingheader precedence over its own body-embeddedincy://line is the Incy client's own import behavior, not something 3x-ui's output controls, and suggested reporting that precedence to the Incy developers. That still holds — 3x-ui cannot change how Incy resolves a conflict once both are present in the same response.What's different in this report is the suggested solution: suppress the Happ
Routing/Routing-Enableheaders when the request'sUser-Agentidentifies an Incy client, so Incy only ever sees its own body-embedded line. That needs no cooperation from Incy's developers, and the codebase already has the same pattern for format selection:subClashAutoDetect/jsonAutoDetectwithclashUserAgent/jsonUserAgentregexes (internal/sub/controller.go:261-264, default pattern(?i)(clash|mihomo)ininternal/web/service/setting.go:37), checked inshouldAutoServeFormat(internal/sub/controller.go:395-400). Extending that mechanism with an Incy User-Agent regex to gate the routing headers/body-line would follow existing design, and matches the reporter's own confirmed workaround (point 2 under "Additional Information": clearing the Happ routing config lets Incy apply its own routing correctly).Relabeling this as an enhancement and retitling it: the current behavior matches the code as written — both settings fire unconditionally, by design — so the gap is a missing per-client User-Agent gate (a new capability), not broken existing logic. The GeoIP/GeoSite "Lite" database point is useful context for why the two configs need to diverge, but isn't something 3x-ui manages directly — the Happ/Incy routing fields are opaque deep-link strings the admin supplies, not database files the panel builds.
@MHSanaei for a decision on whether to add Incy User-Agent detection to gate the Happ routing headers / Incy body-line, following the existing Clash/JSON auto-detect pattern.
This reply was generated automatically. A maintainer may follow up.
@Snegovik commented on GitHub (Aug 12, 2026):
Confirming this is still present on v3.6.0 (xray-core v26.7.28, Debian).
The issue is visible server-side, not just in the client. With both toggles enabled and both rule sets stored, the subscription response contains only the generic
Routing:header carrying the HAPP profile — no INCY header is returned at all:Tested with a default curl User-Agent and with
-A "Incy/1.0"— identical output in both cases, so nothing is being selected by User-Agent yet.The two formats are not interchangeable, which makes the fallback actively harmful rather than merely useless: HAPP uses camelCase keys with native booleans (
FakeDns: false,GeositeUrl,RemoteDNSIp), INCY uses different casing and string booleans (FakeDNS: "false",Geositeurl,RemoteDNSIP).The GeoIP/GeoSite memory point in the original report matches what I saw in practice. Feeding INCY a HAPP profile pointing at the full runetfreedom
geosite.dat(~74 MB) fails with:The category name in the error varies — it just fails on whichever entry it reaches when the truncated file runs out. Trimming the rule list one category at a time does not help; the file size is the actual limit. Separate INCY rules would let operators point INCY at the Lite databases while HAPP keeps the full ones, which is exactly what this request is asking for.
@n0ctal commented on GitHub (Aug 16, 2026):
@MHSanaei — we run a fork with this implemented, and it has been in production for a while. Rather than open a large PR unannounced, I would rather describe it and let you decide whether you want it, and in what shape.
What the fork does. Happ's routing stays where it is, in the response headers. INCY gets its own setting and its rules are emitted as a separate
incy://routing/...line in the subscription body. The two never substitute for each other, which is the substance of this report: nothing has to guess the client, because each one reads from the place it already reads from.What sits under it. A decoder for
happ://routing/{add,onadd}/andincy://routing/{add,onadd}/links that validates rather than trusts: base64 alphabet and length (unpadded accepted, then canonicalised), schema of the decoded object, DNS forms, UTF-8 validity, and a versioning field so a newer profile is not silently downgraded. Unknown fields are rejected by default and can be accepted explicitly, which is audit-logged. 17 tests cover the decode paths.That validation exists because a malformed profile pasted into settings used to reach clients unchanged; making it strict was the fix, and canonicalising it was what stopped a semantically identical profile from looking like a change on every save.
Honest sizing. It is roughly 600 lines plus tests, spread over
internal/web/service/routing_profile.go, the settings layer, the sub controller and a small frontend validator. That is a feature contribution, not a bug fix, which is why I am asking first.Two shapes, either works for us:
Say which you prefer, or that you would rather not carry it, and I will act accordingly. If you want it, I will rebase onto current
mainand open the PR with the tests included.@Artepin commented on GitHub (Aug 20, 2026):
Confirming this independently on 3.6.0-line source (built from a recent
maincheckout, Go module pathgithub.com/mhsanaei/3x-ui/v3), xray-core 26.7.28 — same versions @Snegovik reported above.Wanted to share a minimal, targeted patch as a lighter-weight alternative to sit alongside @n0ctal's larger validation-layer proposal, in case a smaller fix is useful while that gets decided.
Root cause (matches the automated analysis above,
internal/sub/controller.go):ApplyCommonHeadersunconditionally sets theRoutingheader from the Happ-tab settings on every subscription response. The Incy tab's rules are only ever appended to the response body (incy://routing/onadd/...), with no corresponding header override. Per Incy's own subscription-format docs, header values take precedence over body values — so Incy always resolves to Happ's profile regardless of what's configured for it, exactly as reported here.Patch — after the block that writes the Incy rules into the body, override the
Routingheader when the request identifies as Incy (Happ is untouched, since the User-Agent check is always false for Happ clients):This follows the same "detect by User-Agent" shape suggested in the automated comment above (mirroring the existing
subClashAutoDetect/jsonAutoDetectpattern), scoped to just the header conflict rather than a full profile-format validation layer.Verified in production against real Incy clients (iOS 2.5.1 and Windows 3.4.2) — both now receive the Incy-configured routing profile instead of Happ's. Happy to open a PR with this if it's useful as a stopgap, or defer entirely to whichever shape of @n0ctal's proposal @MHSanaei decides to take — just didn't want the minimal option to go unmentioned.
(Also opened #6273 independently before finding this thread — closing it now as a duplicate of this one.)
@n0ctal commented on GitHub (Sep 1, 2026):
I checked this against current
mainbefore commenting, because the mechanism turns out to be different from what the report assumes, and there is a second problem hiding underneath it.Confirmed: every client gets Happ's routing.
ApplyCommonHeaderssets theRoutingheader fromprofileRoutingRules(internal/sub/controller.go:848), and all three call sites passa.subRoutingRules— the Happ tab's value:subsat:429,serveJsonBodyat:752,serveClashBodyat:800. There is no branch on the requesting client anywhere in that path, so the report is correct on the symptom.But INCY is already supported, by a different transport.
subIncyEnableRouting/subIncyRoutingRulesexist and are honoured atinternal/sub/controller.go:431-437— except they are appended to the response body, not sent as a header. So an INCY subscription currently carries its own rules in the body and Happ's rules in the header at the same time. This is not "the panel forgot about INCY"; it is two incompatible delivery schemes in one response, which is worth naming precisely because it changes what a fix has to do.The separate bug: the enable flag does not disable anything. Lines 841-848:
profileEnableRoutinggates onlyRouting-Enable. TheRoutingheader itself is emitted whenever the rules string is non-empty, deliberately, as the comment says. The practical consequence is that Happ routing cannot be switched off: unticking the box still ships the rules to every subscriber, and the only way to stop it is to empty the rules field. That is a defect in its own right, independent of INCY, and I am happy to open it separately if a maintainer would prefer it tracked on its own.On the stated cause. The iOS ~50 MB extension limit does not account for what I am seeing in the field: INCY fails without surfacing an error at all, while Happ is the one that reports exceeding a limit. A conflict between two simultaneous sources of routing rules explains both of those; a memory ceiling explains neither. I cannot prove that from the code alone — it needs INCY logs — but it is at least a testable hypothesis, which "the extension ran out of memory" is not.
@Artepin's patch above addresses the header selection directly, which is the part the code confirms. I would rather see that one land than propose a competing change; if it does, the enable-flag behaviour and the header/body split are still worth resolving afterwards.
@n0ctal commented on GitHub (Sep 1, 2026):
Field result on desktop, which sharpens the symptom I described earlier and matches what the code does.
Setup. macOS on Intel, INCY 3.7.2 desktop, TUN mode. Control: Happ on the same machine, same network, same subscription, back to back.
With routing enabled, INCY has no connectivity at all. Not degraded, not partial — nothing resolves and nothing loads. Turning routing off restores it. Happ on the identical profile is unaffected. Earlier in this thread I described INCY as failing without surfacing an error; the accurate statement is stronger than that, and easier for anyone else to reproduce: enabling routing takes the tunnel down completely.
That is the behaviour the header path predicts.
ApplyCommonHeadersemitsRoutingfrom the Happ tab's rules atinternal/sub/controller.go:848, from all three call sites, while INCY's own rules arrive separately in the response body at:431-437. A client that reads the header therefore applies a rule set written for a different client, on top of its own. A total loss of connectivity is exactly what a conflicting or unparseable routing set produces, and it explains why the failure is silent: nothing errored, the rules simply sent everything nowhere.Second observation, on DNS, which I want to record as a measurement rather than a conclusion. With the tunnel up, the egress address and the resolvers do not agree: the tunnel exits in one country, while 28 of 29 DNS queries were answered by Cloudflare resolvers in a second country and one by Google in a third. No ISP resolver appeared, so this is not the earlier system-DNS leak — that one is gone here. What remains is that name resolution and traffic leave by different paths.
Two consequences worth naming. Geolocated answers arrive for the wrong country, so sites can behave oddly while everything appears to be working. And an observer sees one exit for DNS and another for traffic, which is a correlation the user did not ask for.
I am deliberately not claiming a cause for that second part. It does not follow from the panel code, which is what I verified; it is client-side behaviour, and proving it needs INCY's own logs. It is consistent with the client resolving through its configured
vpnDnsrather than anything the subscription offers, but consistent is not the same as demonstrated.The connectivity failure, by contrast, does follow from the code above, and I would treat it as the primary defect in this issue.
@Snegovik commented on GitHub (Oct 12, 2026):
Still reproducible on v3.10.0 (xray-core v26.10.10), with the line numbers for current
main, since the ones earlier in this thread have moved:internal/sub/controller.go:975—ApplyCommonHeaderssets theRoutingheader fromprofileRoutingRules, and all three call sites passa.subRoutingRules, i.e. the Happ tab:subs()at:505,serveJsonBody()at:846,serveClashBody()at:914. There is still no branch on the requesting client anywhere in that path.internal/sub/controller.go:507-514— the Incy tab's rules are appended to the response body, gated only bysubIncyEnableRouting.One detail I do not think has been named yet: the body append is not User-Agent gated either. Turning
subIncyEnableRoutingon adds theincy://routing/onadd/...line to every subscription response, including those fetched by Happ and by plain v2ray-style clients. So on a mixed install the setting cannot be enabled cleanly today: either Incy gets Happ's profile in the header, or everyone gets Incy's line in the body — in practice both at once.A workaround that has been in production here since 2026-08-27, in case it is useful to others while this stays open. It is Artepin's patch from this thread, implemented one layer up in the reverse proxy, so no fork is needed:
Incy clients get their own profile, every other client passes the panel's header through untouched. Seven weeks, 11 clients, no regressions. The value is generated from the panel's own
subIncyRoutingRulessetting, so the panel stays the single source of truth.@MHSanaei — the thread now holds two concrete proposals: the minimal User-Agent-gated header override, and n0ctal's validated decoder. Would either be accepted? I am happy to open a PR for the minimal variant if that is the direction you prefer.
@MHSanaei commented on GitHub (Oct 12, 2026):
@claude analyze
@github-actions[bot] commented on GitHub (Oct 12, 2026):
This is still present on the default branch (v3.10.0). The panel sends the Happ tab's
Routingheader to every client, Incy included. It also adds the Incy tab'sincy://line to every response body, Happ included. It does this even though it now recognises Incy by User-Agent (IsIncyClient, added in v3.9.0) and the setting text calls each routing setting client-specific. I'm reclassifying this from feature request to bug. My earlier analysis called it a missing capability. That no longer holds: the Incy detection exists, and the routing path just doesn't use it.What the code does
ApplyCommonHeaderssets the routing headers without checking which client is asking (internal/sub/controller.go:960-976):The User-Agent is only checked further down, and only for the app-management headers (
controller.go:968and:984). The Incy routing line is appended bysubs()with no client check (controller.go:507-513):The setting text says the opposite (
internal/web/translation/en-US.json):subEnableRoutingDesc(line 1411): "Global setting to enable routing in the VPN client. (Only for Happ)"subIncyEnableRoutingDesc(line 1417): "Inject a routing profile into the subscription body for the Incy client. (Only for Incy)"The "leave Happ routing empty" workaround no longer works on its own. Since
2dd903ea(v3.8.0), an empty Happ field makes the header fall back to the JSON tab'ssubJsonRoutingRules(controller.go:961-965). An install with JSON routing rules set therefore still sends Incy a Happ-shapedRoutingheader. If you want to keep Incy clean without a proxy, both fields have to be empty. The nginxmapoverride @Snegovik posted above handles it at the proxy layer and leaves the panel unchanged.Two thread points the source settles
Routingheader. That is intended, not a second bug.internal/sub/remote_routing_test.go:413-414asserts that withprofileEnableRouting=falsetheRoutingheader is still ahapp://routing/onadd/value, and onlyRouting-Enableis dropped.Verdict: Confirmed bug
Severity: Medium
Confidence: Medium
Root cause:
internal/sub/controller.go,ApplyCommonHeaders, lines 960-976: theRoutingheader is built from the Happ rules (or, when those are empty, the JSON-tab rules) and set for every requester; the Incy body line atsubs()lines 507-513 is likewise unconditional. Neither path usesIsIncyClient(internal/sub/incy.go:62) orIsHappClient(internal/sub/happ.go:41), which both exist.Same class:
ApplyCommonHeadersis called from all three formats with the same Happ rules:subs()controller.go:505,serveJsonBody():846,serveClashBody():914; the JSON-rules fallback at:961-965(from2dd903ea, #6402) is a second source of Happ-shapedRoutingreaching Incy.Already fixed: Still present on the default branch (
74c3cc38, after v3.10.0).71e38367(#6650, v3.9.0) added Incy User-Agent detection only for app-management headers, not routing.Duplicate of: Related: #5708, #5999 (same Happ/Incy conflict, closed earlier), #6273 (closed by its author as a duplicate of this one)
Evidence: quoted lines above;
incy.go:12regexp.MustCompile(`(?i)\bincy\b`); testremote_routing_test.go:413-414pins the header-without-enable behaviourNot determined: Whether Incy accepts an
incy://value in theRoutingheader, as @Artepin's patch assumes, or needs the header left out and the body line used instead. The Incy client docs or a header-only test against a current Incy build would settle it.Suggested fix: Make the routing choice per client inside
ApplyCommonHeaders, so all three formats get it at once. WhenIsIncyClientmatches and Incy routing is enabled, send the Incy rules (or noRoutingheader) instead of the Happ/JSON value. Gate thesubs()body line on the same check so Happ and plain clients stop getting theincy://line. A patch only insubs(), like the one above, would leave the JSON and Clash formats and the JSON-rules fallback still sending Happ routing to Incy.I retitled this from "[Feature]: Serve INCY-specific routing configuration instead of HAPP's, based on subscription User-Agent" and changed the label from
enhancementtobug.This reply was generated automatically. A maintainer may follow up.
@mvanhorn commented on GitHub (Oct 13, 2026):
ApplyCommonHeaders resolved the Happ routing source on every response and set Routing-Enable and Routing from it, and when the Happ rule string was empty it substituted the JSON routing header. The subs handler appended subIncyRoutingRules whenever Incy routing was enabled and the stored rules were non-empty.
The resolved Incy line is written to the body only when IsIncyClient matches the subscription User-Agent, Incy routing is enabled, and the resolved text is non-blank.
https://github.com/MHSanaei/3x-ui/pull/6810
@Snegovik commented on GitHub (Oct 13, 2026):
Thanks for the quick turnaround on #6810. One data point for the "Not determined" line in the analysis above, since the merged fix takes the other route and that distinction matters if the route ever regresses.
INCY does honour an
incy://link delivered in theRoutingheader. That is exactly what the nginx override above has been doing here since 2026-08-27: header only, no body line at all — the Incy tab's switch has been off on this install the whole time, so the panel never emitted one. Before the override, INCY applied the Happ profile and fell back to its default GitHub-hosted geo files, which are unreachable from where these clients are, so routing effectively stopped working. Since the override, the INCY clients here have been running on their own profile, with no recurrence.So both transports are known to work for the builds in use here: a
Routingheader outranks a body line (as reported earlier in this thread), and a header carrying the Incy-shaped link is accepted and applied. #6810 deletes the header and relies on the body line alone, which is fine as long as every INCY build reads it — and if one does not, setting the header instead is a known-good fallback rather than an open question.One upgrade note that may deserve a line in the release notes: after #6810, an INCY request with the Incy tab's routing switch off falls through to the JSON tab's rules (
controller.go:961-965). On installs where that switch was deliberately left off because a proxy was doing the work — this one, for instance — INCY will receive no routing profile at all after upgrading, until the switch is turned on. The fix itself is right; the part that is easy to miss is that the old workaround and the new behaviour do not overlap, so the switch has to be flipped as part of the upgrade.