[GH-ISSUE #6386] [Bug]: subscription language #4332

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

Originally created by @ArtinTomcat on GitHub (Sep 1, 2026).
Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/6386

Describe the bug

when users change their subscription language , the language on xray panel also changes too

How to reproduce the problem

.

Expected behavior

No response

Actual behavior

No response

Relevant logs


Screenshots

No response

3x-ui version

3.7.0

Xray-core version

No response

How did you install 3x-ui?

install.sh script

Operating system

Ubuntu 24

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?

None

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 @ArtinTomcat on GitHub (Sep 1, 2026). Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/6386 ### Describe the bug when users change their subscription language , the language on xray panel also changes too ### How to reproduce the problem . ### Expected behavior _No response_ ### Actual behavior _No response_ ### Relevant logs ```shell ``` ### Screenshots _No response_ ### 3x-ui version 3.7.0 ### Xray-core version _No response_ ### How did you install 3x-ui? install.sh script ### Operating system Ubuntu 24 ### 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? None ### 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:38:53 +07:00
  • closed this issue
  • added the
    bug
    label
Author
Owner

@github-actions[bot] commented on GitHub (Sep 1, 2026):

Confirmed — the subscription page and the panel share one single browser cookie for the UI language, so changing it on one changes it on the other. This is a real defect, but it only travels inside one browser: a client changing the language on their own subscription page cannot change the language you see in your panel.

Why it happens

The panel language is not stored server-side at all. There is no webLang setting — the only language key in the database is tgLang for the Telegram bot (internal/web/service/setting.go:83). Both the panel and the subscription page read the language from the same cookie:

frontend/src/utils/index.ts:791
document.cookie = cname + '=' + encodeURIComponent(cvalue) + ';' + expires + 'path=/';

LanguageManager.setLanguage() (frontend/src/utils/index.ts:940-946) writes that cookie, and it is called from both places with no distinction:

  • Subscription page — frontend/src/pages/sub/SubPage.tsx:98-101
  • Panel settings — frontend/src/pages/settings/GeneralTab.tsx:153-156

Both bundles then read it back through the same LanguageManager.getLanguage() (frontend/src/utils/index.ts:900) at i18n startup (frontend/src/i18n/react.ts:18).

The cookie is written with path=/ and no Domain attribute, and cookies are scoped by host, not by port. By default the subscription server listens on a different port but the same hostname — "subPort": "2096" and "subDomain": "" (internal/web/service/setting.go:103-105), and an empty subDomain falls back to the panel's own hostname (internal/web/service/setting.go:1416-1417). So https://example.com:2096/sub/... and https://example.com:2053/panel/ share the exact same lang cookie.

Workarounds today

  1. Set the panel language back in Settings → Panel Settings → Language (frontend/src/pages/settings/GeneralTab.tsx:319). It is the same cookie, so it wins whichever page wrote it last.
  2. Open the subscription page in a private window or a separate browser profile when you want to check it.
  3. Give the subscription server its own hostname via the subDomain setting (internal/web/service/setting.go:826, read at internal/sub/sub.go:58). Different host = different cookie jar, so the two stop interfering.

A separate, genuinely cross-user coupling (for the maintainer)

While tracing this I found a second one that does cross users, though it does not affect the UI language. LocalizerMiddleware assigns a package-level global from the current request's cookie:

// internal/web/locale/locale.go:142
LocalizerWeb = i18n.NewLocalizer(i18nBundle, lang)

That middleware is installed on the public subscription server too (internal/sub/sub.go:219), and both servers run in one process (main.go:120-122). I18nWeb resolves through that same global (internal/web/controller/base.go:41 → internal/web/locale/locale.go:83), and it backs ~280 API response messages across internal/web/controller/. So an anonymous subscriber's lang cookie can flip the language of an admin's API messages mid-flight, and the unsynchronised write to a shared global is a data race. This is a distinct defect from the one reported above and would rate higher than it.

Verdict: Confirmed bug
Severity: Low
Confidence: Medium
Root cause: CookieManager.setCookie writes the lang cookie with path=/ and no Domain (frontend/src/utils/index.ts:791); LanguageManager.setLanguage (frontend/src/utils/index.ts:940-946) is called unchanged from both SubPage.tsx:100 and GeneralTab.tsx:155, and both bundles read it back via frontend/src/i18n/react.ts:18. Triggers whenever the subscription page and the panel are reached on the same hostname (the default: subDomain is "" and falls back to the panel host, internal/web/service/setting.go:1416-1417), in the same browser. The subscription-page language selector arrived with the frontend rewrite in edf0f369 ("Frontend rewrite: React + TypeScript with AntD v6 (#4498)"), which is the only commit touching onLangChange in SubPage.tsx.
Already fixed: Still present on the default branch (f727d04f, v3.7.0 — the latest release per gh release list).
Duplicate of: None. Related: #3807, the request that added a language selector to the subscription page.
Evidence: frontend/src/utils/index.ts:791 document.cookie = cname + '=' + encodeURIComponent(cvalue) + ';' + expires + 'path=/';; frontend/src/utils/index.ts:944 CookieManager.setCookie('lang', language, 365);; frontend/src/utils/index.ts:900 let lang = CookieManager.getCookie('lang');; frontend/src/i18n/react.ts:18 let active: string = LanguageManager.getLanguage();; internal/web/service/setting.go:103-105 "subPort": "2096", "subPath": "/sub/", "subDomain": ""; internal/web/locale/locale.go:142 LocalizerWeb = i18n.NewLocalizer(i18nBundle, lang); internal/sub/sub.go:219 engine.Use(locale.LocalizerMiddleware()). No test in the repo pins the shared-cookie behaviour as intended, and no comment defends it.
Not determined: Whether you observed this in one browser (fully explained above) or believe a client's change reached your panel. The single check that settles it: open the panel in a private window while a client is using the subscription page — if the panel is still in your language there, it was the shared cookie in your own browser. I could not run the panel or read any screenshot here, so please paste text rather than images if you follow up.

Suggested fix: Give the subscription page its own persisted language key instead of routing through the shared path=/ lang cookie that LanguageManager owns (frontend/src/utils/index.ts:791), so SubPage.tsx:100 and GeneralTab.tsx:155 no longer write the same slot. The LocalizerWeb global is a separate change: make the localizer request-scoped (it is already placed in the gin context at internal/web/locale/locale.go:144) rather than assigned to a package variable.

A clearer title for searchability would be "changing the language on the subscription page also changes the panel language".

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

<!-- gh-comment-id:5500905433 --> @github-actions[bot] commented on GitHub (Sep 1, 2026): Confirmed — the subscription page and the panel share one single browser cookie for the UI language, so changing it on one changes it on the other. This is a real defect, but it only travels **inside one browser**: a client changing the language on their own subscription page cannot change the language you see in your panel. ### Why it happens The panel language is not stored server-side at all. There is no `webLang` setting — the only language key in the database is `tgLang` for the Telegram bot (`internal/web/service/setting.go:83`). Both the panel and the subscription page read the language from the same cookie: ``` frontend/src/utils/index.ts:791 document.cookie = cname + '=' + encodeURIComponent(cvalue) + ';' + expires + 'path=/'; ``` `LanguageManager.setLanguage()` (`frontend/src/utils/index.ts:940-946`) writes that cookie, and it is called from both places with no distinction: - Subscription page — `frontend/src/pages/sub/SubPage.tsx:98-101` - Panel settings — `frontend/src/pages/settings/GeneralTab.tsx:153-156` Both bundles then read it back through the same `LanguageManager.getLanguage()` (`frontend/src/utils/index.ts:900`) at i18n startup (`frontend/src/i18n/react.ts:18`). The cookie is written with `path=/` and no `Domain` attribute, and cookies are scoped by host, **not by port**. By default the subscription server listens on a different port but the same hostname — `"subPort": "2096"` and `"subDomain": ""` (`internal/web/service/setting.go:103-105`), and an empty `subDomain` falls back to the panel's own hostname (`internal/web/service/setting.go:1416-1417`). So `https://example.com:2096/sub/...` and `https://example.com:2053/panel/` share the exact same `lang` cookie. ### Workarounds today 1. Set the panel language back in **Settings → Panel Settings → Language** (`frontend/src/pages/settings/GeneralTab.tsx:319`). It is the same cookie, so it wins whichever page wrote it last. 2. Open the subscription page in a private window or a separate browser profile when you want to check it. 3. Give the subscription server its own hostname via the `subDomain` setting (`internal/web/service/setting.go:826`, read at `internal/sub/sub.go:58`). Different host = different cookie jar, so the two stop interfering. ### A separate, genuinely cross-user coupling (for the maintainer) While tracing this I found a second one that *does* cross users, though it does not affect the UI language. `LocalizerMiddleware` assigns a **package-level global** from the current request's cookie: ```go // internal/web/locale/locale.go:142 LocalizerWeb = i18n.NewLocalizer(i18nBundle, lang) ``` That middleware is installed on the public subscription server too (`internal/sub/sub.go:219`), and both servers run in one process (`main.go:120-122`). `I18nWeb` resolves through that same global (`internal/web/controller/base.go:41` → `internal/web/locale/locale.go:83`), and it backs ~280 API response messages across `internal/web/controller/`. So an anonymous subscriber's `lang` cookie can flip the language of an admin's API messages mid-flight, and the unsynchronised write to a shared global is a data race. This is a distinct defect from the one reported above and would rate higher than it. Verdict: Confirmed bug Severity: Low Confidence: Medium Root cause: `CookieManager.setCookie` writes the `lang` cookie with `path=/` and no `Domain` (`frontend/src/utils/index.ts:791`); `LanguageManager.setLanguage` (`frontend/src/utils/index.ts:940-946`) is called unchanged from both `SubPage.tsx:100` and `GeneralTab.tsx:155`, and both bundles read it back via `frontend/src/i18n/react.ts:18`. Triggers whenever the subscription page and the panel are reached on the same hostname (the default: `subDomain` is `""` and falls back to the panel host, `internal/web/service/setting.go:1416-1417`), in the same browser. The subscription-page language selector arrived with the frontend rewrite in edf0f369 ("Frontend rewrite: React + TypeScript with AntD v6 (#4498)"), which is the only commit touching `onLangChange` in `SubPage.tsx`. Already fixed: Still present on the default branch (f727d04f, v3.7.0 — the latest release per `gh release list`). Duplicate of: None. Related: #3807, the request that added a language selector to the subscription page. Evidence: `frontend/src/utils/index.ts:791` `document.cookie = cname + '=' + encodeURIComponent(cvalue) + ';' + expires + 'path=/';`; `frontend/src/utils/index.ts:944` `CookieManager.setCookie('lang', language, 365);`; `frontend/src/utils/index.ts:900` `let lang = CookieManager.getCookie('lang');`; `frontend/src/i18n/react.ts:18` `let active: string = LanguageManager.getLanguage();`; `internal/web/service/setting.go:103-105` `"subPort": "2096"`, `"subPath": "/sub/"`, `"subDomain": ""`; `internal/web/locale/locale.go:142` `LocalizerWeb = i18n.NewLocalizer(i18nBundle, lang)`; `internal/sub/sub.go:219` `engine.Use(locale.LocalizerMiddleware())`. No test in the repo pins the shared-cookie behaviour as intended, and no comment defends it. Not determined: Whether you observed this in one browser (fully explained above) or believe a *client's* change reached your panel. The single check that settles it: open the panel in a private window while a client is using the subscription page — if the panel is still in your language there, it was the shared cookie in your own browser. I could not run the panel or read any screenshot here, so please paste text rather than images if you follow up. Suggested fix: Give the subscription page its own persisted language key instead of routing through the shared `path=/` `lang` cookie that `LanguageManager` owns (`frontend/src/utils/index.ts:791`), so `SubPage.tsx:100` and `GeneralTab.tsx:155` no longer write the same slot. The `LocalizerWeb` global is a separate change: make the localizer request-scoped (it is already placed in the gin context at `internal/web/locale/locale.go:144`) rather than assigned to a package variable. A clearer title for searchability would be "changing the language on the subscription page also changes the panel language". *This reply was generated automatically; a maintainer may follow up.* <!-- claude-issue:analyst -->
Author
Owner

@dawNotPoi commented on GitHub (Sep 3, 2026):

I'd like to work on this. I'll keep the panel and login on the existing lang cookie, give the subscription SPA an independent language scope with a one-time migration from a valid existing selection, and add focused regression coverage for initialization and date formatting. I won't change the backend localizer as part of this fix.

<!-- gh-comment-id:5519192062 --> @dawNotPoi commented on GitHub (Sep 3, 2026): I'd like to work on this. I'll keep the panel and login on the existing `lang` cookie, give the subscription SPA an independent language scope with a one-time migration from a valid existing selection, and add focused regression coverage for initialization and date formatting. I won't change the backend localizer as part of this fix.
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#4332
No description provided.