[GH-ISSUE #6062] [Bug]: INCY receives HAPP's Routing header instead of its own routing configuration #4197

Closed
opened 2026-10-31 20:37:53 +07:00 by bsakaguchi · 11 comments
Owner

Originally created by @aishlai on GitHub (Jul 20, 2026).
Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/6062

Describe the bug

Versions

  • 3X-UI: 3.5.0
  • HAPP iOS: 5.1.0
  • INCY iOS: 2.4.5

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

  1. HAPP itself is not affected and works as expected.
  2. If the HAPP routing configuration on the server is empty, INCY is able to receive and apply its own routing configuration correctly.

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

  1. In the 3X-UI subscription settings, configure the routing rules for HAPP and INCY, ensuring that each client has its own routing configuration.
  2. Open the INCY client on iOS and update the subscription.
  3. Check the routing configuration received by the INCY client.

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

  • 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 @aishlai on GitHub (Jul 20, 2026). Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/6062 ### Describe the bug ## Versions * 3X-UI: 3.5.0 * HAPP iOS: 5.1.0 * INCY iOS: 2.4.5 ## 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 1. HAPP itself is not affected and works as expected. 2. If the HAPP routing configuration on the server is empty, INCY is able to receive and apply its own routing configuration correctly. ## 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 1. In the **3X-UI** subscription settings, configure the routing rules for **HAPP** and **INCY**, ensuring that each client has its own routing configuration. 2. Open the **INCY** client on iOS and update the subscription. 3. Check the routing configuration received by the INCY client. ## 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 ```shell ``` ### 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 - [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:37:53 +07:00
  • closed this issue
  • added the
    bug
    label
Author
Owner

@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 the Routing-Enable / Routing HTTP headers from the Happ tab's settings (subEnableRouting / subRoutingRules) on every subscription response whenever Happ routing is enabled, regardless of which client is asking.
  • The subs handler (lines 374-377) separately appends the Incy tab's subIncyRoutingRules (an incy://routing/onadd/... line) into the subscription body, gated only by subIncyEnableRouting — 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 in internal/sub/. So with both enabled, every client, Happ or Incy, gets both the Routing header and the body-injected incy:// line in the same response.

In #5708 the maintainer's conclusion was that Incy giving the Routing header precedence over its own body-embedded incy:// 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-Enable headers when the request's User-Agent identifies 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 / jsonAutoDetect with clashUserAgent / jsonUserAgent regexes (internal/sub/controller.go:261-264, default pattern (?i)(clash|mihomo) in internal/web/service/setting.go:37), checked in shouldAutoServeFormat (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.

<!-- gh-comment-id:5025185966 --> @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 the `Routing-Enable` / `Routing` HTTP headers from the Happ tab's settings (`subEnableRouting` / `subRoutingRules`) on every subscription response whenever Happ routing is enabled, regardless of which client is asking. - The `subs` handler (lines 374-377) separately appends the Incy tab's `subIncyRoutingRules` (an `incy://routing/onadd/...` line) into the subscription body, gated only by `subIncyEnableRouting` — 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 in `internal/sub/`. So with both enabled, every client, Happ or Incy, gets both the `Routing` header and the body-injected `incy://` line in the same response. In #5708 the maintainer's conclusion was that Incy giving the `Routing` header precedence over its own body-embedded `incy://` 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-Enable` headers when the request's `User-Agent` identifies 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` / `jsonAutoDetect` with `clashUserAgent` / `jsonUserAgent` regexes (`internal/sub/controller.go:261-264`, default pattern `(?i)(clash|mihomo)` in `internal/web/service/setting.go:37`), checked in `shouldAutoServeFormat` (`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.*
Author
Owner

@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:

$ sqlite3 /etc/x-ui/x-ui.db "SELECT key, value FROM settings WHERE key LIKE '%Incy%';"
subIncyEnableRouting|true
subIncyRoutingRules|<2209 chars, valid incy://routing/onadd/... link>

$ curl -I https://<host>:<port>/<subPath>/<subId>
...
Routing: happ://routing/add/eyJOYW1lIjoi...
Routing-Enable: true

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:

common/geodata: failed to check code CATEGORY-MEDICINE-RU from geosite.dat > EOF

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.

<!-- gh-comment-id:5267031125 --> @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: ``` $ sqlite3 /etc/x-ui/x-ui.db "SELECT key, value FROM settings WHERE key LIKE '%Incy%';" subIncyEnableRouting|true subIncyRoutingRules|<2209 chars, valid incy://routing/onadd/... link> $ curl -I https://<host>:<port>/<subPath>/<subId> ... Routing: happ://routing/add/eyJOYW1lIjoi... Routing-Enable: true ``` 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: ``` common/geodata: failed to check code CATEGORY-MEDICINE-RU from geosite.dat > EOF ``` 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.
Author
Owner

@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}/ and incy://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:

  1. the minimal separation — a dedicated INCY setting and the body line, without the validation layer. Small, addresses this issue directly, easy to review.
  2. the whole thing, validation included, split into reviewable commits.

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 main and open the PR with the tests included.

<!-- gh-comment-id:5309792504 --> @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}/` and `incy://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:** 1. the minimal separation — a dedicated INCY setting and the body line, without the validation layer. Small, addresses this issue directly, easy to review. 2. the whole thing, validation included, split into reviewable commits. 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 `main` and open the PR with the tests included.
Author
Owner

@Artepin commented on GitHub (Aug 20, 2026):

Confirming this independently on 3.6.0-line source (built from a recent main checkout, Go module path github.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): ApplyCommonHeaders unconditionally sets the Routing header 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 Routing header when the request identifies as Incy (Happ is untouched, since the User-Agent check is always false for Happ clients):

 		if a.subIncyEnableRouting && a.subIncyRoutingRules != "" {
 			incyRules, _, err := resolveIncyRoutingSource(a.subIncyRoutingRules)
 			if err == nil && strings.TrimSpace(incyRules) != "" {
 				result.WriteString(incyRules)
 				result.WriteString("\n")
+
+				// Incy clients read the "Routing" HTTP header with higher
+				// priority than a routing string embedded in the body
+				// (documented client behavior: headers override body).
+				// ApplyCommonHeaders above unconditionally sets that header
+				// from the Happ routing rules, so Incy clients were always
+				// receiving Happ's profile regardless of this field.
+				// Override it here for requests that identify as Incy.
+				if strings.Contains(strings.ToUpper(userAgent), "INCY") {
+					c.Writer.Header().Set("Routing", incyRules)
+				}
 			}
 		}

This follows the same "detect by User-Agent" shape suggested in the automated comment above (mirroring the existing subClashAutoDetect/jsonAutoDetect pattern), 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.)

<!-- gh-comment-id:5355882913 --> @Artepin commented on GitHub (Aug 20, 2026): Confirming this independently on **3.6.0-line source** (built from a recent `main` checkout, Go module path `github.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`): `ApplyCommonHeaders` unconditionally sets the `Routing` header 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 `Routing` header when the request identifies as Incy (Happ is untouched, since the User-Agent check is always false for Happ clients): ```diff if a.subIncyEnableRouting && a.subIncyRoutingRules != "" { incyRules, _, err := resolveIncyRoutingSource(a.subIncyRoutingRules) if err == nil && strings.TrimSpace(incyRules) != "" { result.WriteString(incyRules) result.WriteString("\n") + + // Incy clients read the "Routing" HTTP header with higher + // priority than a routing string embedded in the body + // (documented client behavior: headers override body). + // ApplyCommonHeaders above unconditionally sets that header + // from the Happ routing rules, so Incy clients were always + // receiving Happ's profile regardless of this field. + // Override it here for requests that identify as Incy. + if strings.Contains(strings.ToUpper(userAgent), "INCY") { + c.Writer.Header().Set("Routing", incyRules) + } } } ``` This follows the same "detect by User-Agent" shape suggested in the automated comment above (mirroring the existing `subClashAutoDetect`/`jsonAutoDetect` pattern), 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.)
Author
Owner

@n0ctal commented on GitHub (Sep 1, 2026):

I checked this against current main before 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. ApplyCommonHeaders sets the Routing header from profileRoutingRules (internal/sub/controller.go:848), and all three call sites pass a.subRoutingRules — the Happ tab's value: subs at :429, serveJsonBody at :752, serveClashBody at :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 / subIncyRoutingRules exist and are honoured at internal/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:

// Advanced (Happ). Routing stays independent of the enable flag; ...
rules, remote, routingErr := resolveRoutingSource(remoteRoutingHapp, profileRoutingRules)
if profileEnableRouting {
    c.Writer.Header().Set("Routing-Enable", "true")
}
if (routingErr == nil || !remote) && strings.TrimSpace(rules) != "" {
    c.Writer.Header().Set("Routing", rules)
}

profileEnableRouting gates only Routing-Enable. The Routing header 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.

<!-- gh-comment-id:5490453095 --> @n0ctal commented on GitHub (Sep 1, 2026): I checked this against current `main` before 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.** `ApplyCommonHeaders` sets the `Routing` header from `profileRoutingRules` (`internal/sub/controller.go:848`), and all three call sites pass `a.subRoutingRules` — the Happ tab's value: `subs` at `:429`, `serveJsonBody` at `:752`, `serveClashBody` at `: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` / `subIncyRoutingRules` exist and are honoured at `internal/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: ```go // Advanced (Happ). Routing stays independent of the enable flag; ... rules, remote, routingErr := resolveRoutingSource(remoteRoutingHapp, profileRoutingRules) if profileEnableRouting { c.Writer.Header().Set("Routing-Enable", "true") } if (routingErr == nil || !remote) && strings.TrimSpace(rules) != "" { c.Writer.Header().Set("Routing", rules) } ``` `profileEnableRouting` gates only `Routing-Enable`. The `Routing` header 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.
Author
Owner

@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. ApplyCommonHeaders emits Routing from the Happ tab's rules at internal/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 vpnDns rather 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.

<!-- gh-comment-id:5490823037 --> @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. `ApplyCommonHeaders` emits `Routing` from the Happ tab's rules at `internal/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 `vpnDns` rather 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.
Author
Owner

@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 — ApplyCommonHeaders sets the Routing header from profileRoutingRules, and all three call sites pass a.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 by subIncyEnableRouting.

One detail I do not think has been named yet: the body append is not User-Agent gated either. Turning subIncyEnableRouting on adds the incy://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:

map $http_user_agent $incy_routing {
    default  "";
    "~*incy" "incy://routing/onadd/<base64 profile>";
}
map $incy_routing $routing_out {
    default  $incy_routing;
    ""       $upstream_http_routing;
}

# in the subscription location:
proxy_hide_header Routing;
add_header Routing $routing_out always;

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 subIncyRoutingRules setting, 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.

<!-- gh-comment-id:6129424365 --> @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` — `ApplyCommonHeaders` sets the `Routing` header from `profileRoutingRules`, and all three call sites pass `a.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 by `subIncyEnableRouting`. One detail I do not think has been named yet: **the body append is not User-Agent gated either.** Turning `subIncyEnableRouting` on adds the `incy://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: ```nginx map $http_user_agent $incy_routing { default ""; "~*incy" "incy://routing/onadd/<base64 profile>"; } map $incy_routing $routing_out { default $incy_routing; "" $upstream_http_routing; } # in the subscription location: proxy_hide_header Routing; add_header Routing $routing_out always; ``` 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 `subIncyRoutingRules` setting, 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.
Author
Owner

@MHSanaei commented on GitHub (Oct 12, 2026):

@claude analyze

<!-- gh-comment-id:6129936011 --> @MHSanaei commented on GitHub (Oct 12, 2026): @claude analyze
Author
Owner

@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 Routing header to every client, Incy included. It also adds the Incy tab's incy:// 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

ApplyCommonHeaders sets the routing headers without checking which client is asking (internal/sub/controller.go:960-976):

rules, remote, routingErr := resolveRoutingSource(remoteRoutingHapp, profileRoutingRules)
if strings.TrimSpace(profileRoutingRules) == "" {
    rules, remote, routingErr = jsonRoutingHeaderSource(a.subJsonRoutingRules), false, nil
}
...
if (routingErr == nil || !remote) && strings.TrimSpace(rules) != "" {
    c.Writer.Header().Set("Routing", rules)
}

The User-Agent is only checked further down, and only for the app-management headers (controller.go:968 and :984). The Incy routing line is appended by subs() with no client check (controller.go:507-513):

if a.subIncyEnableRouting && a.subIncyRoutingRules != "" {
    incyRules, _, err := resolveIncyRoutingSource(a.subIncyRoutingRules)
    if err == nil && strings.TrimSpace(incyRules) != "" {
        result.WriteString(incyRules)

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's subJsonRoutingRules (controller.go:961-965). An install with JSON routing rules set therefore still sends Incy a Happ-shaped Routing header. If you want to keep Incy clean without a proxy, both fields have to be empty. The nginx map override @Snegovik posted above handles it at the proxy layer and leaves the panel unchanged.

Two thread points the source settles

  • Unticking Happ "enable routing" still sends the Routing header. That is intended, not a second bug. internal/sub/remote_routing_test.go:413-414 asserts that with profileEnableRouting=false the Routing header is still a happ://routing/onadd/ value, and only Routing-Enable is dropped.
  • Incy giving the header priority over the body line is client behaviour. The source can't show it. Three people in this thread report it, and @Artepin tested it on iOS 2.5.1 and Windows 3.4.2.

Verdict: Confirmed bug
Severity: Medium
Confidence: Medium
Root cause: internal/sub/controller.go, ApplyCommonHeaders, lines 960-976: the Routing header is built from the Happ rules (or, when those are empty, the JSON-tab rules) and set for every requester; the Incy body line at subs() lines 507-513 is likewise unconditional. Neither path uses IsIncyClient (internal/sub/incy.go:62) or IsHappClient (internal/sub/happ.go:41), which both exist.
Same class: ApplyCommonHeaders is 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 (from 2dd903ea, #6402) is a second source of Happ-shaped Routing reaching 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:12 regexp.MustCompile(`(?i)\bincy\b`); test remote_routing_test.go:413-414 pins the header-without-enable behaviour
Not determined: Whether Incy accepts an incy:// value in the Routing header, 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. When IsIncyClient matches and Incy routing is enabled, send the Incy rules (or no Routing header) instead of the Happ/JSON value. Gate the subs() body line on the same check so Happ and plain clients stop getting the incy:// line. A patch only in subs(), 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 enhancement to bug.

This reply was generated automatically. A maintainer may follow up.

<!-- gh-comment-id:6129965505 --> @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 `Routing` header to every client, Incy included. It also adds the Incy tab's `incy://` 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** `ApplyCommonHeaders` sets the routing headers without checking which client is asking (`internal/sub/controller.go:960-976`): ```go rules, remote, routingErr := resolveRoutingSource(remoteRoutingHapp, profileRoutingRules) if strings.TrimSpace(profileRoutingRules) == "" { rules, remote, routingErr = jsonRoutingHeaderSource(a.subJsonRoutingRules), false, nil } ... if (routingErr == nil || !remote) && strings.TrimSpace(rules) != "" { c.Writer.Header().Set("Routing", rules) } ``` The User-Agent is only checked further down, and only for the app-management headers (`controller.go:968` and `:984`). The Incy routing line is appended by `subs()` with no client check (`controller.go:507-513`): ```go if a.subIncyEnableRouting && a.subIncyRoutingRules != "" { incyRules, _, err := resolveIncyRoutingSource(a.subIncyRoutingRules) if err == nil && strings.TrimSpace(incyRules) != "" { result.WriteString(incyRules) ``` 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's `subJsonRoutingRules` (`controller.go:961-965`). An install with JSON routing rules set therefore still sends Incy a Happ-shaped `Routing` header. If you want to keep Incy clean without a proxy, both fields have to be empty. The nginx `map` override @Snegovik posted above handles it at the proxy layer and leaves the panel unchanged. **Two thread points the source settles** - **Unticking Happ "enable routing" still sends the `Routing` header.** That is intended, not a second bug. `internal/sub/remote_routing_test.go:413-414` asserts that with `profileEnableRouting=false` the `Routing` header is still a `happ://routing/onadd/` value, and only `Routing-Enable` is dropped. - **Incy giving the header priority over the body line is client behaviour.** The source can't show it. Three people in this thread report it, and @Artepin tested it on iOS 2.5.1 and Windows 3.4.2. Verdict: Confirmed bug Severity: Medium Confidence: Medium Root cause: `internal/sub/controller.go`, `ApplyCommonHeaders`, lines 960-976: the `Routing` header is built from the Happ rules (or, when those are empty, the JSON-tab rules) and set for every requester; the Incy body line at `subs()` lines 507-513 is likewise unconditional. Neither path uses `IsIncyClient` (`internal/sub/incy.go:62`) or `IsHappClient` (`internal/sub/happ.go:41`), which both exist. Same class: `ApplyCommonHeaders` is 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` (from `2dd903ea`, #6402) is a second source of Happ-shaped `Routing` reaching 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:12` `` regexp.MustCompile(`(?i)\bincy\b`) ``; test `remote_routing_test.go:413-414` pins the header-without-enable behaviour Not determined: Whether Incy accepts an `incy://` value in the `Routing` header, 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. When `IsIncyClient` matches and Incy routing is enabled, send the Incy rules (or no `Routing` header) instead of the Happ/JSON value. Gate the `subs()` body line on the same check so Happ and plain clients stop getting the `incy://` line. A patch only in `subs()`, 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 `enhancement` to `bug`. *This reply was generated automatically. A maintainer may follow up.* <!-- claude-issue:analyst -->
Author
Owner

@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

<!-- gh-comment-id:6141225455 --> @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
Author
Owner

@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 the Routing header. 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 Routing header 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.

<!-- gh-comment-id:6149927134 --> @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 the `Routing` header.** 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 `Routing` header 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.
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#4197
No description provided.