[PR #6964] [MERGED] fix(scripts): preserve custom webBasePath during updates #6546

Closed
opened 2026-11-02 04:09:33 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/MHSanaei/3x-ui/pull/6964
Author: @HamedSanaei
Created: 10/26/2026
Status: ✅ Merged
Merged: 11/2/2026
Merged by: @MHSanaei

Base: main ← Head: fix/preserve-custom-web-base-path


📝 Commits (1)

  • a99be10 fix(scripts): preserve custom webBasePath during updates

📊 Changes

3 files changed (+315 additions, -10 deletions)

View changed files

📝 install.sh (+19 -5)
➕ scripts_base_path_test.go (+277 -0)
📝 update.sh (+19 -5)

📄 Description

Summary

Preserve configured panel paths during updates and reinstallations, including /a/ and /ab/. Only initialize a missing/default root path, and skip configuration changes if the CLI settings read fails or is malformed.

Why

Fixes #6961.

Problem: Valid short custom panel paths are silently replaced during updates or reinstallations.

Root cause: Both scripts strip the leading slash and use a minimum-length check to decide whether webBasePath is uninitialized. The CLI and frontend accept these short custom paths. The existing pipelines also discard CLI failures, which can turn an unsuccessful settings read into an apparent empty path.

Solution: Validate one settings snapshot before changing configuration, distinguish an explicitly empty value from a missing/malformed record, and replace the length check with an empty/root check. Retain the installer's separate default-credential initialization branch, so a short custom path does not prevent insecure default credentials from being replaced. Custom credentials, configured certificates, database selection, and existing service workflows remain unchanged. Configuration-read failures do not prevent the surrounding installer from completing service setup or the updater from completing its existing post-configuration steps. Path handling requests an update restart only when a new path is initialized.

Historical context: #5179 reported the same overwrite alongside a login desynchronization. Commit f88f53cd7b8a6fc0c5eb6a12170f7630f395ee8e added the restart after regeneration, addressing the desynchronization symptom while leaving the path-length condition in place. This PR addresses that remaining overwrite condition.

Type of change

  • Bug fix
  • New feature
  • Refactoring (no behavior change)
  • Documentation
  • Tests only
  • Build / CI / tooling
  • Other

Areas affected

  • Frontend (UI / panel pages)
  • Backend (API endpoints, login, settings)
  • Xray config generation
  • Subscription (share links / Clash / JSON)
  • Statistics / traffic counters
  • Database / migrations
  • Install / upgrade script
  • Docker image
  • Multi-node (sub-nodes)
  • Telegram bot

How was this tested?

The new Go regression tests execute the actual Bash configuration functions and random generator extracted from each script. The CLI, network requests, service restarts, SSL setup, and installation-result writer use temporary fixtures; the installers themselves are never sourced or executed against the host. These tests run automatically in the existing Go CI jobs; native Windows skips them with instructions to use WSL.

Red → green: the original path overwrite and failed-read mutations were reproduced before implementation (24 failures in the initial 44-case suite). The final 46-case suite also checks that read failures leave the existing service-setup flow intact. All cases pass, covering:

  • / and missing stored paths initialize once with an 18-character random path. The CLI fixture normalizes a missing stored value to /, matching the real GetBasePath behavior.
  • /a/, /ab/, /abc/, /mypanel/, and paths containing spaces remain unchanged.
  • Custom credentials survive two consecutive updates/reinstallations.
  • Default credentials are securely initialized on install even with an existing short path, without changing that path or port.
  • Failed CLI reads, empty output, absent path records, relative paths, duplicate records, and reported getter errors cannot change settings or request a restart.
  • Repeated runs do not rewrite initialized paths or trigger additional path-related restarts; configured TLS is preserved.
  • The actual post-configuration continuations still install/start the service and reach Fail2ban setup after a failed settings read. Filesystem and service operations are isolated with temporary fixtures and mocks.

Commands run under Linux/amd64 in WSL:

  • bash -n update.sh
  • bash -n install.sh
  • go test -run '^TestScriptConfig' -count=1 -v .
  • go test -race -run '^TestScriptConfig' -count=1 .
  • shellcheck --severity=error install.sh update.sh (ShellCheck 0.9.0; matches repository CI policy)
  • GOFLAGS=-p=2 make verify

All 11 CI checks passed on final commit a99be10d499b09278075bd0f2cbf2f3e8fe8163c, including shell lint, Go tests/lint, race, frontend, code generation, parser fuzzing, vulnerability checks, PostgreSQL checks, and node end-to-end tests.

Breaking changes

None for valid existing configurations. A failed or malformed settings read now skips configuration changes and logs an error instead of guessing that the path is unset. Existing service setup continues. Missing/default paths retain secure initialization. No API, database schema, frontend validation, or TLS policy changes. No production installation or deployment was performed.

Checklist

  • I tested the change locally and confirmed the described behavior.
  • I added or updated tests for the new behavior (when applicable).
  • go build ./... and the test suite pass locally.
  • For frontend changes: npm run lint, npm run typecheck, and npm run build pass. (No frontend changes.)
  • I updated the Wiki / README / API docs if user-facing behavior changed. (No documented API or configuration contract changes.)
  • My commits follow the project's existing message style.
  • I have no unrelated changes mixed into this PR.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/MHSanaei/3x-ui/pull/6964 **Author:** [@HamedSanaei](https://github.com/HamedSanaei) **Created:** 10/26/2026 **Status:** ✅ Merged **Merged:** 11/2/2026 **Merged by:** [@MHSanaei](https://github.com/MHSanaei) **Base:** `main` ← **Head:** `fix/preserve-custom-web-base-path` --- ### 📝 Commits (1) - [`a99be10`](https://github.com/MHSanaei/3x-ui/commit/a99be10d499b09278075bd0f2cbf2f3e8fe8163c) fix(scripts): preserve custom webBasePath during updates ### 📊 Changes **3 files changed** (+315 additions, -10 deletions) <details> <summary>View changed files</summary> 📝 `install.sh` (+19 -5) ➕ `scripts_base_path_test.go` (+277 -0) 📝 `update.sh` (+19 -5) </details> ### 📄 Description ## Summary Preserve configured panel paths during updates and reinstallations, including `/a/` and `/ab/`. Only initialize a missing/default root path, and skip configuration changes if the CLI settings read fails or is malformed. ## Why Fixes #6961. **Problem:** Valid short custom panel paths are silently replaced during updates or reinstallations. **Root cause:** Both scripts strip the leading slash and use a minimum-length check to decide whether `webBasePath` is uninitialized. The CLI and frontend accept these short custom paths. The existing pipelines also discard CLI failures, which can turn an unsuccessful settings read into an apparent empty path. **Solution:** Validate one settings snapshot before changing configuration, distinguish an explicitly empty value from a missing/malformed record, and replace the length check with an empty/root check. Retain the installer's separate default-credential initialization branch, so a short custom path does not prevent insecure default credentials from being replaced. Custom credentials, configured certificates, database selection, and existing service workflows remain unchanged. Configuration-read failures do not prevent the surrounding installer from completing service setup or the updater from completing its existing post-configuration steps. Path handling requests an update restart only when a new path is initialized. **Historical context:** #5179 reported the same overwrite alongside a login desynchronization. Commit `f88f53cd7b8a6fc0c5eb6a12170f7630f395ee8e` added the restart after regeneration, addressing the desynchronization symptom while leaving the path-length condition in place. This PR addresses that remaining overwrite condition. ## Type of change - [x] Bug fix - [ ] New feature - [ ] Refactoring (no behavior change) - [ ] Documentation - [ ] Tests only - [ ] Build / CI / tooling - [ ] Other ## Areas affected - [ ] Frontend (UI / panel pages) - [ ] Backend (API endpoints, login, settings) - [ ] Xray config generation - [ ] Subscription (share links / Clash / JSON) - [ ] Statistics / traffic counters - [ ] Database / migrations - [x] Install / upgrade script - [ ] Docker image - [ ] Multi-node (sub-nodes) - [ ] Telegram bot ## How was this tested? The new Go regression tests execute the actual Bash configuration functions and random generator extracted from each script. The CLI, network requests, service restarts, SSL setup, and installation-result writer use temporary fixtures; the installers themselves are never sourced or executed against the host. These tests run automatically in the existing Go CI jobs; native Windows skips them with instructions to use WSL. Red → green: the original path overwrite and failed-read mutations were reproduced before implementation (24 failures in the initial 44-case suite). The final 46-case suite also checks that read failures leave the existing service-setup flow intact. All cases pass, covering: - `/` and missing stored paths initialize once with an 18-character random path. The CLI fixture normalizes a missing stored value to `/`, matching the real `GetBasePath` behavior. - `/a/`, `/ab/`, `/abc/`, `/mypanel/`, and paths containing spaces remain unchanged. - Custom credentials survive two consecutive updates/reinstallations. - Default credentials are securely initialized on install even with an existing short path, without changing that path or port. - Failed CLI reads, empty output, absent path records, relative paths, duplicate records, and reported getter errors cannot change settings or request a restart. - Repeated runs do not rewrite initialized paths or trigger additional path-related restarts; configured TLS is preserved. - The actual post-configuration continuations still install/start the service and reach Fail2ban setup after a failed settings read. Filesystem and service operations are isolated with temporary fixtures and mocks. Commands run under Linux/amd64 in WSL: - `bash -n update.sh` - `bash -n install.sh` - `go test -run '^TestScriptConfig' -count=1 -v .` - `go test -race -run '^TestScriptConfig' -count=1 .` - `shellcheck --severity=error install.sh update.sh` (ShellCheck 0.9.0; matches repository CI policy) - `GOFLAGS=-p=2 make verify` All 11 CI checks passed on final commit `a99be10d499b09278075bd0f2cbf2f3e8fe8163c`, including shell lint, Go tests/lint, race, frontend, code generation, parser fuzzing, vulnerability checks, PostgreSQL checks, and node end-to-end tests. ## Breaking changes None for valid existing configurations. A failed or malformed settings read now skips configuration changes and logs an error instead of guessing that the path is unset. Existing service setup continues. Missing/default paths retain secure initialization. No API, database schema, frontend validation, or TLS policy changes. No production installation or deployment was performed. ## Checklist - [x] I tested the change locally and confirmed the described behavior. - [x] I added or updated tests for the new behavior (when applicable). - [x] `go build ./...` and the test suite pass locally. - [ ] For frontend changes: `npm run lint`, `npm run typecheck`, and `npm run build` pass. (No frontend changes.) - [ ] I updated the Wiki / README / API docs if user-facing behavior changed. (No documented API or configuration contract changes.) - [x] My commits follow the project's existing message style. - [x] I have no unrelated changes mixed into this PR. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi changed title from [PR #6964] fix(scripts): preserve custom webBasePath during updates to [PR #6964] [MERGED] fix(scripts): preserve custom webBasePath during updates 2026-11-07 14:33:54 +07:00
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#6546
No description provided.