[GH-ISSUE #6961] [Bug]: 后台修改基础路径后,更新版本,路径会被重置。 #4600

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

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

Describe the bug

后台修改基础路径后,更新版本,路径会被重置成新的基础路径。
版本:3.10.2

How to reproduce the problem

后台修改基础路径后,更新版本,路径会被重置成新的基础路径。
版本:3.10.2

Expected behavior

No response

Actual behavior

No response

Relevant logs


Screenshots

No response

3x-ui version

3.10.2

Xray-core version

No response

How did you install 3x-ui?

Other (please describe in the bug body)

Operating system

ubuntu 24.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 response

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 @igsood on GitHub (Oct 26, 2026). Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/6961 ### Describe the bug 后台修改基础路径后,更新版本,路径会被重置成新的基础路径。 版本:3.10.2 ### How to reproduce the problem 后台修改基础路径后,更新版本,路径会被重置成新的基础路径。 版本:3.10.2 ### Expected behavior _No response_ ### Actual behavior _No response_ ### Relevant logs ```shell ``` ### Screenshots _No response_ ### 3x-ui version 3.10.2 ### Xray-core version _No response_ ### How did you install 3x-ui? Other (please describe in the bug body) ### Operating system ubuntu 24.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 response_ ### 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).
Author
Owner

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

结论:如果您设置的基础路径(去掉开头的 / 之后)不足 4 个字符,例如 /、/a/、/ab/,那么更新脚本会把它当作"缺失或过短",静默替换成一个随机的 18 位新路径——这正是您看到的现象,并且在最新的 v3.11.0 中依然存在。如果您的路径长度 ≥ 4 个字符,则不是这个原因,请按文末回复两个信息。

原因

面板内"更新"按钮和 x-ui 菜单里的"更新"都会执行同一个 update.sh(internal/web/service/panel/panel.go:44、x-ui.sh:151)。脚本先读出当前路径,去掉开头的 /:

# update.sh:177
local existing_webBasePath=$(${xui_folder}/x-ui setting -show true | grep -Eo 'webBasePath: .+' | awk '{print $2}' | sed 's#^/##')

然后只按长度判断:

# update.sh:206-209
if [[ ${#existing_webBasePath} -lt 4 ]]; then
    echo -e "${yellow}WebBasePath is missing or too short. Generating a new one...${plain}"
    local config_webBasePath=$(gen_random_string 18)
    ${xui_folder}/x-ui setting -webBasePath "${config_webBasePath}"

SetBasePath 存储时总会加上首尾 /(internal/web/service/setting.go:822-829),所以面板里存为 /ab/ 的路径,在这里会变成 ab/,长度为 3,于是被覆盖。而后台设置页对长度没有任何限制,只校验开头必须是 /(frontend/src/schemas/setting.ts:5),因此用户可以保存一个后台认为合法、但每次更新都会被替换的路径。

您现在可以做的

  1. 把基础路径改成至少 3 个字符的段(例如 /mypanel/),之后更新就不会再被替换。
  2. 如果更新后进不去面板,在服务器上查看当前路径:
    x-ui settings
    
    或直接改回自己的路径:
    /usr/local/x-ui/x-ui setting -webBasePath mypanel
    x-ui restart
    
  3. 更新日志里如果出现 WebBasePath is missing or too short. Generating a new one...,就说明是这个原因。

需要您补充

  1. 被重置之前,您设置的基础路径大约有几个字符(不必给出真实路径)?——用来确认是否就是上面这个长度判断。
  2. 安装方式选了"Other",具体是什么方式(Docker、面板内更新按钮、x-ui 菜单更新,还是重新运行 install.sh)?——如果是 Docker 且数据库没有挂载到持久卷,所有设置都会在重建容器时丢失,那是另一个原因。

Verdict:        Confirmed bug
Severity:       Medium
Confidence:     Medium
Root cause:     update.sh:206 — any webBasePath shorter than 4 chars after stripping the
                leading "/" (stored "/", "/x/", "/ab/") is overwritten with a random 18-char
                path on every update. The UI accepts such paths (schemas/setting.ts:5 only
                requires a leading "/"). Introduced in 69ccdba7 "Self-signed SSL (#3611)".
Same class:     install.sh:1123 / install.sh:1350-1352 — re-running install.sh over an
                existing install with non-default credentials makes the same overwrite.
Already fixed:  Still present on the default branch (v3.11.0).
Duplicate of:   None
Evidence:       update.sh:177 strips the leading "/" only; update.sh:206-209 length check
                and overwrite; setting.go:822-829 always stores "/<path>/"; panel.go:44
                and x-ui.sh:151 both run update.sh.
Not determined: Whether the reporter's path was actually under 4 characters, and the
                install method ("Other"). Their answers to the two questions above settle it.

Suggested fix: 在 update.sh 中只在路径确实为空或仍是默认 / 时才生成新路径,因为更新时需要替换的只有未设置的默认值;用户自己保存的短路径应当保留,最多打印一条警告。install.sh:1350 的已安装分支也需要同样的修改。如果更希望强制最小长度,就应在后台设置页保存时校验,而不是在更新时静默覆盖。

此回复由自动分析生成,维护者可能会进一步跟进。

<!-- gh-comment-id:6419664307 --> @github-actions[bot] commented on GitHub (Oct 26, 2026): 结论:如果您设置的基础路径(去掉开头的 `/` 之后)**不足 4 个字符**,例如 `/`、`/a/`、`/ab/`,那么更新脚本会把它当作"缺失或过短",**静默替换成一个随机的 18 位新路径**——这正是您看到的现象,并且在最新的 v3.11.0 中依然存在。如果您的路径长度 ≥ 4 个字符,则不是这个原因,请按文末回复两个信息。 ### 原因 面板内"更新"按钮和 `x-ui` 菜单里的"更新"都会执行同一个 `update.sh`(`internal/web/service/panel/panel.go:44`、`x-ui.sh:151`)。脚本先读出当前路径,去掉开头的 `/`: ```bash # update.sh:177 local existing_webBasePath=$(${xui_folder}/x-ui setting -show true | grep -Eo 'webBasePath: .+' | awk '{print $2}' | sed 's#^/##') ``` 然后只按长度判断: ```bash # update.sh:206-209 if [[ ${#existing_webBasePath} -lt 4 ]]; then echo -e "${yellow}WebBasePath is missing or too short. Generating a new one...${plain}" local config_webBasePath=$(gen_random_string 18) ${xui_folder}/x-ui setting -webBasePath "${config_webBasePath}" ``` `SetBasePath` 存储时总会加上首尾 `/`(`internal/web/service/setting.go:822-829`),所以面板里存为 `/ab/` 的路径,在这里会变成 `ab/`,长度为 3,于是被覆盖。而后台设置页对长度没有任何限制,只校验开头必须是 `/`(`frontend/src/schemas/setting.ts:5`),因此用户可以保存一个后台认为合法、但每次更新都会被替换的路径。 ### 您现在可以做的 1. 把基础路径改成至少 3 个字符的段(例如 `/mypanel/`),之后更新就不会再被替换。 2. 如果更新后进不去面板,在服务器上查看当前路径: ```bash x-ui settings ``` 或直接改回自己的路径: ```bash /usr/local/x-ui/x-ui setting -webBasePath mypanel x-ui restart ``` 3. 更新日志里如果出现 `WebBasePath is missing or too short. Generating a new one...`,就说明是这个原因。 ### 需要您补充 1. 被重置之前,您设置的基础路径大约有几个字符(不必给出真实路径)?——用来确认是否就是上面这个长度判断。 2. 安装方式选了"Other",具体是什么方式(Docker、面板内更新按钮、`x-ui` 菜单更新,还是重新运行 `install.sh`)?——如果是 Docker 且数据库没有挂载到持久卷,所有设置都会在重建容器时丢失,那是另一个原因。 --- ``` Verdict: Confirmed bug Severity: Medium Confidence: Medium Root cause: update.sh:206 — any webBasePath shorter than 4 chars after stripping the leading "/" (stored "/", "/x/", "/ab/") is overwritten with a random 18-char path on every update. The UI accepts such paths (schemas/setting.ts:5 only requires a leading "/"). Introduced in 69ccdba7 "Self-signed SSL (#3611)". Same class: install.sh:1123 / install.sh:1350-1352 — re-running install.sh over an existing install with non-default credentials makes the same overwrite. Already fixed: Still present on the default branch (v3.11.0). Duplicate of: None Evidence: update.sh:177 strips the leading "/" only; update.sh:206-209 length check and overwrite; setting.go:822-829 always stores "/<path>/"; panel.go:44 and x-ui.sh:151 both run update.sh. Not determined: Whether the reporter's path was actually under 4 characters, and the install method ("Other"). Their answers to the two questions above settle it. ``` Suggested fix: 在 `update.sh` 中只在路径确实为空或仍是默认 `/` 时才生成新路径,因为更新时需要替换的只有未设置的默认值;用户自己保存的短路径应当保留,最多打印一条警告。`install.sh:1350` 的已安装分支也需要同样的修改。如果更希望强制最小长度,就应在后台设置页保存时校验,而不是在更新时静默覆盖。 *此回复由自动分析生成,维护者可能会进一步跟进。* <!-- claude-issue:analyst -->
Author
Owner

@HamedSanaei commented on GitHub (Oct 26, 2026):

Root cause confirmed and fix submitted.

The installation/update scripts use a path-length check to detect an uninitialized webBasePath. Unfortunately, this also matches valid short custom paths such as /a/ and /ab/, causing them to be replaced with a newly generated random path.

A similar problem was previously reported in #5179. Commit f88f53c fixed the restart/desynchronization behavior, but the underlying path-overwrite condition remained.

I've submitted a focused fix that preserves valid custom paths, retains secure initialization for missing/default paths, and adds regression coverage for the affected scenarios.

PR: https://github.com/MHSanaei/3x-ui/pull/6964

<!-- gh-comment-id:6426590735 --> @HamedSanaei commented on GitHub (Oct 26, 2026): **Root cause confirmed and fix submitted.** The installation/update scripts use a path-length check to detect an uninitialized `webBasePath`. Unfortunately, this also matches valid short custom paths such as `/a/` and `/ab/`, causing them to be replaced with a newly generated random path. A similar problem was previously reported in #5179. Commit `f88f53c` fixed the restart/desynchronization behavior, but the underlying path-overwrite condition remained. I've submitted a focused fix that preserves valid custom paths, retains secure initialization for missing/default paths, and adds regression coverage for the affected scenarios. PR: https://github.com/MHSanaei/3x-ui/pull/6964
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#4600
No description provided.