[GH-ISSUE #5481] [Bug]: x-ui setting -webCert/-webCertKey does not persist cert paths on a fresh install (panel stays HTTP-only) #3830

Closed
opened 2026-10-31 20:35:16 +07:00 by bsakaguchi · 1 comment
Owner

Originally created by @Taov-Russo on GitHub (Jun 22, 2026).
Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/5481

Describe the bug

On a fresh 3x-ui v3.3.1 install, running x-ui setting -webCert <fullchain> -webCertKey <privkey>
exits successfully (no error, exit code 0) but does NOT write webCertFile / webKeyFile to the
settings table. As a result the panel keeps serving plain HTTP, and setting -show still prints
Warning: Panel is not secure with SSL. Accessing the panel over HTTPS fails with
ERR_SSL_PROTOCOL_ERROR in the browser.

The cert files themselves are valid and readable - manually inserting the same paths into the
settings table makes the panel serve HTTPS correctly, which shows the issue is the CLI not
persisting the values, not the certificate.

How to reproduce the problem

Steps to reproduce the behavior:

  1. Fresh install of 3x-ui v3.3.1 (default install, untouched DB at /etc/x-ui/x-ui.db).
  2. Place a valid cert/key on disk, e.g. /etc/taoru/ssl/fullchain.pem (0644) and
    /etc/taoru/ssl/privkey.pem (0600).
  3. Run:
    x-ui setting -webCert /etc/taoru/ssl/fullchain.pem -webCertKey /etc/taoru/ssl/privkey.pem
    systemctl restart x-ui
    
    The command prints nothing and exits 0.
  4. Check settings:
    x-ui setting -show
    # -> Warning: Panel is not secure with SSL
    sqlite3 /etc/x-ui/x-ui.db "SELECT key,value FROM settings WHERE key LIKE 'web%';"
    # -> only webPort and webBasePath are present; webCertFile / webKeyFile are MISSING
    
  5. Verify over TLS:
    curl -vk https://127.0.0.1:33033/
    # -> OpenSSL ... error:0A00010B:SSL routines::wrong version number  (server answers plain HTTP)
    

Expected behavior

x-ui setting -webCert ... -webCertKey ... should persist webCertFile / webKeyFile into the
settings table (inserting the rows if they do not exist yet), so that after a restart the panel
serves HTTPS.

Actual behavior

Workaround

Inserting the rows directly works:

systemctl stop x-ui
sqlite3 /etc/x-ui/x-ui.db "INSERT INTO settings(key,value) VALUES('webCertFile','/etc/taoru/ssl/fullchain.pem');"
sqlite3 /etc/x-ui/x-ui.db "INSERT INTO settings(key,value) VALUES('webKeyFile','/etc/taoru/ssl/privkey.pem');"
systemctl start x-ui

curl -vk https://127.0.0.1:33033/   # -> TLSv1.3 handshake completes, panel serves HTTPS

Suspected root cause

On a fresh DB the webCertFile / webKeyFile rows do not exist in the settings table (only
webPort and webBasePath are seeded). The setting -webCert/-webCertKey path appears to update
existing rows only, so when the rows are absent nothing is written. After the rows are created
manually once, the CLI updates them fine - which is consistent with an UPDATE-only code path.

Relevant logs


Screenshots

No response

3x-ui version

v3.3.1

Xray-core version

No response

How did you install 3x-ui?

install.sh script

Operating system

Ubuntu 24.04 LTS (x86_64)

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 @Taov-Russo on GitHub (Jun 22, 2026). Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/5481 ### Describe the bug On a fresh 3x-ui v3.3.1 install, running `x-ui setting -webCert <fullchain> -webCertKey <privkey>` exits successfully (no error, exit code 0) but does NOT write `webCertFile` / `webKeyFile` to the `settings` table. As a result the panel keeps serving plain HTTP, and `setting -show` still prints `Warning: Panel is not secure with SSL`. Accessing the panel over HTTPS fails with `ERR_SSL_PROTOCOL_ERROR` in the browser. The cert files themselves are valid and readable - manually inserting the same paths into the `settings` table makes the panel serve HTTPS correctly, which shows the issue is the CLI not persisting the values, not the certificate. ### How to reproduce the problem Steps to reproduce the behavior: 1. Fresh install of 3x-ui v3.3.1 (default install, untouched DB at `/etc/x-ui/x-ui.db`). 2. Place a valid cert/key on disk, e.g. `/etc/taoru/ssl/fullchain.pem` (0644) and `/etc/taoru/ssl/privkey.pem` (0600). 3. Run: ``` x-ui setting -webCert /etc/taoru/ssl/fullchain.pem -webCertKey /etc/taoru/ssl/privkey.pem systemctl restart x-ui ``` The command prints nothing and exits 0. 4. Check settings: ``` x-ui setting -show # -> Warning: Panel is not secure with SSL sqlite3 /etc/x-ui/x-ui.db "SELECT key,value FROM settings WHERE key LIKE 'web%';" # -> only webPort and webBasePath are present; webCertFile / webKeyFile are MISSING ``` 5. Verify over TLS: ``` curl -vk https://127.0.0.1:33033/ # -> OpenSSL ... error:0A00010B:SSL routines::wrong version number (server answers plain HTTP) ``` ### Expected behavior `x-ui setting -webCert ... -webCertKey ...` should persist `webCertFile` / `webKeyFile` into the `settings` table (inserting the rows if they do not exist yet), so that after a restart the panel serves HTTPS. ### Actual behavior ## Workaround Inserting the rows directly works: ``` systemctl stop x-ui sqlite3 /etc/x-ui/x-ui.db "INSERT INTO settings(key,value) VALUES('webCertFile','/etc/taoru/ssl/fullchain.pem');" sqlite3 /etc/x-ui/x-ui.db "INSERT INTO settings(key,value) VALUES('webKeyFile','/etc/taoru/ssl/privkey.pem');" systemctl start x-ui curl -vk https://127.0.0.1:33033/ # -> TLSv1.3 handshake completes, panel serves HTTPS ``` ## Suspected root cause On a fresh DB the `webCertFile` / `webKeyFile` rows do not exist in the `settings` table (only `webPort` and `webBasePath` are seeded). The `setting -webCert/-webCertKey` path appears to update existing rows only, so when the rows are absent nothing is written. After the rows are created manually once, the CLI updates them fine - which is consistent with an UPDATE-only code path. ### Relevant logs ```shell ``` ### Screenshots _No response_ ### 3x-ui version v3.3.1 ### Xray-core version _No response_ ### How did you install 3x-ui? install.sh script ### Operating system Ubuntu 24.04 LTS (x86_64) ### 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).
bsakaguchi 2026-10-31 20:35:16 +07:00
  • closed this issue
  • added the
    bug
    label
Author
Owner

@github-actions[bot] commented on GitHub (Jun 22, 2026):

The root cause is confirmed by the source. The -webCert/-webCertKey flags are registered on settingCmd in main.go (lines 543–544), but the case "setting": handler never calls updateCert(). It only calls updateSetting(), which handles port, username, password, webBasePath, listenIP, and resetTwoFactor — cert paths are not wired in. updateCert() is invoked exclusively by the separate case "cert": branch (line 652 of main.go).

Workaround (use this instead):

x-ui cert -webCert /etc/taoru/ssl/fullchain.pem -webCertKey /etc/taoru/ssl/privkey.pem
systemctl restart x-ui

This is also the command used internally by x-ui.sh's SSL Certificate Management menu (option 19), at lines 1377, 1401, 1634, and 1853 of that script.

A secondary note on your suspected root cause: saveSetting() in internal/web/service/setting.go (lines 298–311) does a proper UPSERT — it inserts a new row when the key is absent and updates it otherwise. The "UPDATE-only" theory does not hold; once updateCert() is actually called, it works correctly on a fresh DB.

The bug is that x-ui setting -webCert/-webCertKey silently accepts the flags but discards them. The fix would be to add a updateCert(webCertFile, webKeyFile) call inside the case "setting": block of main.go when either flag is non-empty, mirroring the cert subcommand.

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

<!-- gh-comment-id:4766952889 --> @github-actions[bot] commented on GitHub (Jun 22, 2026): The root cause is confirmed by the source. The `-webCert`/`-webCertKey` flags are registered on `settingCmd` in `main.go` (lines 543–544), but the `case "setting":` handler never calls `updateCert()`. It only calls `updateSetting()`, which handles port, username, password, webBasePath, listenIP, and resetTwoFactor — cert paths are not wired in. `updateCert()` is invoked exclusively by the separate `case "cert":` branch (line 652 of `main.go`). **Workaround (use this instead):** ```bash x-ui cert -webCert /etc/taoru/ssl/fullchain.pem -webCertKey /etc/taoru/ssl/privkey.pem systemctl restart x-ui ``` This is also the command used internally by `x-ui.sh`'s SSL Certificate Management menu (option 19), at lines 1377, 1401, 1634, and 1853 of that script. A secondary note on your suspected root cause: `saveSetting()` in `internal/web/service/setting.go` (lines 298–311) does a proper UPSERT — it inserts a new row when the key is absent and updates it otherwise. The "UPDATE-only" theory does not hold; once `updateCert()` is actually called, it works correctly on a fresh DB. The bug is that `x-ui setting -webCert/-webCertKey` silently accepts the flags but discards them. The fix would be to add a `updateCert(webCertFile, webKeyFile)` call inside the `case "setting":` block of `main.go` when either flag is non-empty, mirroring the `cert` subcommand. *This reply was generated automatically; a maintainer may follow up.*
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#3830
No description provided.