[GH-ISSUE #6232] [Bug]: Hysteria2 clients whose auth value is empty in the database fail authentication #4229

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

Originally created by @koi-lee on GitHub (Aug 17, 2026).
Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/6232

Bug Description

When creating or editing a Hysteria2 client in the 3X-UI panel, the password is stored in the password field in the SQLite database. However, xray-core's Hysteria2 implementation only reads the auth field for authentication. This results in the auth field being empty, causing 404 authentication failed errors when clients try to connect.

Environment

  • 3X-UI version: v3.6.0
  • Protocol: Hysteria2 (Inbound)
  • OS: Ubuntu 24.04.4 LTS (x86_64)
  • xray-core version: (bundled with 3X-UI v3.6.0)

Steps to Reproduce

  1. Install 3X-UI v3.6.0
  2. Create a new Hysteria2 inbound (any port, UDP)
  3. Add a client with a password via the panel
  4. Attempt to connect using a Hysteria2 client (e.g., Clash Verge Rev / mihomo) with the password
  5. Connection fails with: authentication failed / 404

Root Cause

The panel stores the password in the password column of the clients table in x-ui.db, but leaves the auth column empty.

xray-core's Hysteria2 implementation reads the auth field for authentication, not password. Since auth is empty, all authentication attempts fail.

Database Evidence

sqlite3 /etc/x-ui/x-ui.db "SELECT id, email, password, auth FROM clients WHERE protocol IS NULL OR protocol='';"

Result shows password has the value but auth is empty for all Hysteria2 clients.

Expected Behavior

When a Hysteria2 client's password is set or changed in the panel, the auth field should be automatically populated with the same value.

Current Workaround

Manual SQL fix:

UPDATE clients SET auth = password WHERE auth = '' AND password != '';

This can be run as a cron job every minute to keep auth in sync:

#!/usr/bin/env python3
# /usr/local/bin/fix-hy2-auth.py
import sqlite3
db = sqlite3.connect('/etc/x-ui/x-ui.db')
db.execute("UPDATE clients SET auth=password WHERE auth='' AND password!=''")
db.commit()
db.close()
# /etc/cron.d/fix-hy2-auth
* * * * * root /usr/bin/python3 /usr/local/bin/fix-hy2-auth.py

Additional Notes

  • This affects all Hysteria2 clients created or edited through the panel
  • The fix-hy2-auth.py cron workaround has been running stably, but a proper fix in the panel code would be much better
  • The bug may also affect the subId / subscription link generation if the auth field is used there
Originally created by @koi-lee on GitHub (Aug 17, 2026). Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/6232 ## Bug Description When creating or editing a Hysteria2 client in the 3X-UI panel, the password is stored in the `password` field in the SQLite database. However, xray-core's Hysteria2 implementation only reads the `auth` field for authentication. This results in the `auth` field being empty, causing `404 authentication failed` errors when clients try to connect. ## Environment - **3X-UI version**: v3.6.0 - **Protocol**: Hysteria2 (Inbound) - **OS**: Ubuntu 24.04.4 LTS (x86_64) - **xray-core version**: (bundled with 3X-UI v3.6.0) ## Steps to Reproduce 1. Install 3X-UI v3.6.0 2. Create a new Hysteria2 inbound (any port, UDP) 3. Add a client with a password via the panel 4. Attempt to connect using a Hysteria2 client (e.g., Clash Verge Rev / mihomo) with the password 5. Connection fails with: `authentication failed` / `404` ## Root Cause The panel stores the password in the `password` column of the `clients` table in `x-ui.db`, but leaves the `auth` column empty. xray-core's Hysteria2 implementation reads the `auth` field for authentication, not `password`. Since `auth` is empty, all authentication attempts fail. ### Database Evidence ```sql sqlite3 /etc/x-ui/x-ui.db "SELECT id, email, password, auth FROM clients WHERE protocol IS NULL OR protocol='';" ``` Result shows `password` has the value but `auth` is empty for all Hysteria2 clients. ## Expected Behavior When a Hysteria2 client's password is set or changed in the panel, the `auth` field should be automatically populated with the same value. ## Current Workaround Manual SQL fix: ```sql UPDATE clients SET auth = password WHERE auth = '' AND password != ''; ``` This can be run as a cron job every minute to keep `auth` in sync: ```python #!/usr/bin/env python3 # /usr/local/bin/fix-hy2-auth.py import sqlite3 db = sqlite3.connect('/etc/x-ui/x-ui.db') db.execute("UPDATE clients SET auth=password WHERE auth='' AND password!=''") db.commit() db.close() ``` ``` # /etc/cron.d/fix-hy2-auth * * * * * root /usr/bin/python3 /usr/local/bin/fix-hy2-auth.py ``` ## Additional Notes - This affects all Hysteria2 clients created or edited through the panel - The `fix-hy2-auth.py` cron workaround has been running stably, but a proper fix in the panel code would be much better - The bug may also affect the `subId` / subscription link generation if the `auth` field is used there
bsakaguchi 2026-10-31 20:38:08 +07:00
Author
Owner

@github-actions[bot] commented on GitHub (Aug 17, 2026):

Thank you for the detailed report. The symptom you describe is real, but the stated root cause is not what the code does: password and auth are two separate credentials by design, and the panel does not use password for Hysteria at all.

What I confirmed in the source:

  • For a Hysteria inbound, the generated Xray config emits only the auth key, and only when it is non-empty — internal/web/service/xray.go:240-243. The client list for that config is read from the clients table (ListForInbound, internal/web/service/xray.go:181), which is why a row with an empty auth produces a Hysteria user with no credential at all, and why your UPDATE has an effect.
  • password is consumed only by Trojan and Shadowsocks (internal/web/service/xray.go:229-239). The client form states this in the field tooltips: "Only used by Trojan and Shadowsocks clients; ignored for VLESS, VMess, Hysteria, and WireGuard" and "Credential used only by Hysteria clients" (internal/web/translation/en-US.json:732 and :827). Copying password into auth is therefore not a correct fix — it would overwrite the Hysteria credential of every client that legitimately has both set to different values.
  • Subscription and share links already read auth, not password (internal/sub/service.go:1006, internal/sub/json_service.go:515, internal/sub/clash_service.go:310), so a link generated by the panel is consistent with the config.

Recommended fix on your side, instead of the cron job:

  1. Open each affected client in the panel, go to the Credentials tab, and set or regenerate the Hysteria Auth field, then save.
  2. Distribute the panel-generated subscription/share link rather than a hand-typed password.
  3. Remove /etc/cron.d/fix-hy2-auth. As written, that statement also sets auth to the Trojan/Shadowsocks password for every non-Hysteria client that has one. If such a client is later attached to a Hysteria inbound, fillProtocolDefaults (internal/web/service/client_crud.go:164-167) only mints an auth when the field is empty, so the client would silently keep the Trojan password as its Hysteria credential. A direct DB write also does not reach the running Xray until the config is regenerated.

Two things I could not resolve, hence the request for information below:

  • On current code every panel write path fills auth for a Hysteria inbound: fillProtocolDefaults (internal/web/service/client_crud.go:149-172) is called on create, update, attach and bulk-attach, and AddInbound / addInboundClient reject a Hysteria client with an empty auth with empty client ID (internal/web/service/inbound.go:1008-1011, internal/web/service/client_inbound_apply.go:379-382). I could not find a panel UI path in v3.6.0 that leaves auth empty. The one gap I did find is that UpdateInbound (internal/web/service/inbound.go:1398) has no equivalent credential validation, so an inbound update sent through the REST API can persist Hysteria clients without auth; the protocol selector is disabled for existing inbounds in the UI (frontend/src/pages/inbounds/form/InboundFormModal.tsx:591), but the API accepts a protocol change. My confidence that this is what happened on your panel is low without more detail.
  • The clients table has no protocol column — see ClientRecord in internal/database/model/model.go:901-934 (TableName() == "clients"); protocol is a column on inbounds. The query you pasted should therefore fail with no such column: protocol, so it is not the query that produced your evidence.

To move this forward, please provide:

  1. How these Hysteria clients were created: panel Clients page, panel inbound form, REST API, a third-party bot/script, or a database restored from an older version.
  2. The panel version in use when those clients were created (you are on v3.6.0 now).
  3. The output of this query, which reflects the actual schema:
sqlite3 /etc/x-ui/x-ui.db "SELECT c.email, c.password <> '' AS has_password, c.auth <> '' AS has_auth FROM clients c JOIN client_inbounds ci ON ci.client_id = c.id JOIN inbounds i ON i.id = ci.inbound_id WHERE i.protocol = 'hysteria';"
  1. Whether the affected inbound was ever created as a different protocol and later changed to Hysteria.

For visibility on the missing validation in UpdateInbound:

Title: UpdateInbound does not validate per-protocol client credentials, so a Hysteria client can be persisted with an empty auth
Severity: Medium
Category: Correctness
Why this matters: AddInbound rejects a Hysteria client with an empty auth (internal/web/service/inbound.go:1008-1011), but UpdateInbound performs no such check. A client persisted that way is written to the clients table by SyncInbound and then rendered into the Xray config as a user object with only email (internal/web/service/xray.go:240-243), which can never authenticate, with no error surfaced in the panel.
Recommendation: Apply the same per-protocol credential validation in UpdateInbound that AddInbound already performs, or fill the missing credential via fillProtocolDefaults before persisting.

@MHSanaei for a decision on whether the validation gap is worth closing.

I also edited the title for accuracy; it previously read: "[Bug] Hysteria2 client "auth" field not synced with "password" field — causes authentication failure".

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

<!-- gh-comment-id:5310464650 --> @github-actions[bot] commented on GitHub (Aug 17, 2026): Thank you for the detailed report. The symptom you describe is real, but the stated root cause is not what the code does: `password` and `auth` are two separate credentials by design, and the panel does not use `password` for Hysteria at all. What I confirmed in the source: - For a Hysteria inbound, the generated Xray config emits only the `auth` key, and only when it is non-empty — `internal/web/service/xray.go:240-243`. The client list for that config is read from the `clients` table (`ListForInbound`, `internal/web/service/xray.go:181`), which is why a row with an empty `auth` produces a Hysteria user with no credential at all, and why your `UPDATE` has an effect. - `password` is consumed only by Trojan and Shadowsocks (`internal/web/service/xray.go:229-239`). The client form states this in the field tooltips: "Only used by Trojan and Shadowsocks clients; ignored for VLESS, VMess, Hysteria, and WireGuard" and "Credential used only by Hysteria clients" (`internal/web/translation/en-US.json:732` and `:827`). Copying `password` into `auth` is therefore not a correct fix — it would overwrite the Hysteria credential of every client that legitimately has both set to different values. - Subscription and share links already read `auth`, not `password` (`internal/sub/service.go:1006`, `internal/sub/json_service.go:515`, `internal/sub/clash_service.go:310`), so a link generated by the panel is consistent with the config. Recommended fix on your side, instead of the cron job: 1. Open each affected client in the panel, go to the `Credentials` tab, and set or regenerate the `Hysteria Auth` field, then save. 2. Distribute the panel-generated subscription/share link rather than a hand-typed password. 3. Remove `/etc/cron.d/fix-hy2-auth`. As written, that statement also sets `auth` to the Trojan/Shadowsocks password for every non-Hysteria client that has one. If such a client is later attached to a Hysteria inbound, `fillProtocolDefaults` (`internal/web/service/client_crud.go:164-167`) only mints an auth when the field is empty, so the client would silently keep the Trojan password as its Hysteria credential. A direct DB write also does not reach the running Xray until the config is regenerated. Two things I could not resolve, hence the request for information below: - On current code every panel write path fills `auth` for a Hysteria inbound: `fillProtocolDefaults` (`internal/web/service/client_crud.go:149-172`) is called on create, update, attach and bulk-attach, and `AddInbound` / `addInboundClient` reject a Hysteria client with an empty auth with `empty client ID` (`internal/web/service/inbound.go:1008-1011`, `internal/web/service/client_inbound_apply.go:379-382`). I could not find a panel UI path in v3.6.0 that leaves `auth` empty. The one gap I did find is that `UpdateInbound` (`internal/web/service/inbound.go:1398`) has no equivalent credential validation, so an inbound update sent through the REST API can persist Hysteria clients without `auth`; the protocol selector is disabled for existing inbounds in the UI (`frontend/src/pages/inbounds/form/InboundFormModal.tsx:591`), but the API accepts a protocol change. My confidence that this is what happened on your panel is low without more detail. - The `clients` table has no `protocol` column — see `ClientRecord` in `internal/database/model/model.go:901-934` (`TableName() == "clients"`); `protocol` is a column on `inbounds`. The query you pasted should therefore fail with `no such column: protocol`, so it is not the query that produced your evidence. To move this forward, please provide: 1. How these Hysteria clients were created: panel Clients page, panel inbound form, REST API, a third-party bot/script, or a database restored from an older version. 2. The panel version in use when those clients were created (you are on v3.6.0 now). 3. The output of this query, which reflects the actual schema: ``` sqlite3 /etc/x-ui/x-ui.db "SELECT c.email, c.password <> '' AS has_password, c.auth <> '' AS has_auth FROM clients c JOIN client_inbounds ci ON ci.client_id = c.id JOIN inbounds i ON i.id = ci.inbound_id WHERE i.protocol = 'hysteria';" ``` 4. Whether the affected inbound was ever created as a different protocol and later changed to Hysteria. For visibility on the missing validation in `UpdateInbound`: Title: `UpdateInbound` does not validate per-protocol client credentials, so a Hysteria client can be persisted with an empty `auth` Severity: Medium Category: Correctness Why this matters: `AddInbound` rejects a Hysteria client with an empty `auth` (`internal/web/service/inbound.go:1008-1011`), but `UpdateInbound` performs no such check. A client persisted that way is written to the `clients` table by `SyncInbound` and then rendered into the Xray config as a user object with only `email` (`internal/web/service/xray.go:240-243`), which can never authenticate, with no error surfaced in the panel. Recommendation: Apply the same per-protocol credential validation in `UpdateInbound` that `AddInbound` already performs, or fill the missing credential via `fillProtocolDefaults` before persisting. @MHSanaei for a decision on whether the validation gap is worth closing. I also edited the title for accuracy; it previously read: "[Bug] Hysteria2 client "auth" field not synced with "password" field — causes authentication failure". *This reply was generated automatically; a maintainer may follow up.*
Author
Owner

@mvanhorn commented on GitHub (Aug 19, 2026):

Implemented in https://github.com/MHSanaei/3x-ui/pull/6268.

<!-- gh-comment-id:5349037225 --> @mvanhorn commented on GitHub (Aug 19, 2026): Implemented in https://github.com/MHSanaei/3x-ui/pull/6268.
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#4229
No description provided.