[GH-ISSUE #5591] [Bug]: 🚨 API Keys Not Working in v3.4.1 #3908

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

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

Describe the bug

Since updating to v3.4.1, the API keys are not working, and I can no longer connect to the panel via the API. Could you please look into this issue? My work has been blocked since yesterday.
Thank you.

How to reproduce the problem

  1. Update the panel to v3.4.1.
  2. Try to authenticate using an existing API key.
  3. The API connection fails.

Expected behavior

The API key should authenticate successfully and allow access to the panel.

Actual behavior

The API key is rejected, and I cannot connect to the panel via the API.

Relevant logs

This issue started immediately after updating to v3.4.1. My work has been blocked since yesterday because of this problem.

Screenshots

This issue started immediately after updating to v3.4.1. My work has been blocked since yesterday because of this problem.

3x-ui version

3.4.1

Xray-core version

No response

How did you install 3x-ui?

install.sh script

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?

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 @skyboy610 on GitHub (Jun 26, 2026). Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/5591 ### Describe the bug Since updating to v3.4.1, the API keys are not working, and I can no longer connect to the panel via the API. Could you please look into this issue? My work has been blocked since yesterday. Thank you. ### How to reproduce the problem 1. Update the panel to v3.4.1. 2. Try to authenticate using an existing API key. 3. The API connection fails. ### Expected behavior The API key should authenticate successfully and allow access to the panel. ### Actual behavior The API key is rejected, and I cannot connect to the panel via the API. ### Relevant logs ```shell This issue started immediately after updating to v3.4.1. My work has been blocked since yesterday because of this problem. ``` ### Screenshots This issue started immediately after updating to v3.4.1. My work has been blocked since yesterday because of this problem. ### 3x-ui version 3.4.1 ### Xray-core version _No response_ ### How did you install 3x-ui? install.sh script ### 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? 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:35:48 +07:00
Author
Owner

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

The report does not include enough detail to confirm a bug, but some background on how API token authentication works may help resolve this immediately.

How authentication works in the current code

Tokens are stored as SHA-256 hashes; the plaintext is returned exactly once when the token is created and is never retrievable again (confirmed in internal/web/service/panel/api_token.go and the UI string in internal/web/translation/en-US.json: "Copy this token now. For security it is not stored in readable form and will not be shown again.").

Authentication requires the original plaintext value in an Authorization header:

Authorization: Bearer <plaintext-token-copied-at-creation>

The check is in internal/web/controller/api.go (checkAPIAuth): the panel hashes what is presented and compares it to the stored hash. If the stored token is a valid hash and the correct plaintext is presented, it matches. If the presented string is wrong (e.g., a hash digest instead of the original plaintext, or the wrong token value), it will not match.

What changed in v3.4.1

The v3.4.1 changelog contains no changes to API token storage, the checkAPIAuth middleware, or the Match function. The token-hashing migration was introduced in v3.2.7 (fix(api-token): hash tokens at rest and show plaintext only once), and a database seeder (hashExistingApiTokens, in internal/database/db.go) runs on startup to hash any plaintext tokens that pre-date that release. Nothing in v3.4.1 touches this path.

Most likely causes

  1. The plaintext token value was not saved at creation time and has since been lost. Because the hash is irreversible, the only remedy is to delete the existing token in Settings → Authentication → API Token and create a new one, copying the plaintext immediately.
  2. The token is being sent in a format other than Authorization: Bearer <token> (e.g., as a query parameter, in a different header, or with a Token prefix instead of Bearer ).
  3. The token row is disabled. Check Settings → Authentication → API Token and confirm the toggle is on.

To confirm and resolve

  1. In Settings → Authentication → API Token, verify at least one token is enabled.
  2. If the plaintext is unavailable, delete the existing token(s) and create a new one. Save the displayed value immediately.
  3. Test with a minimal curl request to confirm the format:
    curl -s -o /dev/null -w "%{http_code}" \
      -H "Authorization: Bearer <your-plaintext-token>" \
      https://<your-panel>/panel/api/inbounds/list
    
    A 200 response means authentication is working. A 401 or 404 means the token or header format is wrong.

Information needed to investigate further

If the above does not resolve the issue, please provide:

  1. The panel version you upgraded from (not just the current version).
  2. The exact HTTP call being made (tool, headers, endpoint — with sensitive values redacted).
  3. The HTTP status code returned (401, 404, or other).
  4. Panel logs from around the time of the failed request:
    journalctl -u x-ui --since "1 hour ago" -n 200
    

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

<!-- gh-comment-id:4811746592 --> @github-actions[bot] commented on GitHub (Jun 26, 2026): The report does not include enough detail to confirm a bug, but some background on how API token authentication works may help resolve this immediately. **How authentication works in the current code** Tokens are stored as SHA-256 hashes; the plaintext is returned exactly once when the token is created and is never retrievable again (confirmed in `internal/web/service/panel/api_token.go` and the UI string in `internal/web/translation/en-US.json`: *"Copy this token now. For security it is not stored in readable form and will not be shown again."*). Authentication requires the original plaintext value in an `Authorization` header: ``` Authorization: Bearer <plaintext-token-copied-at-creation> ``` The check is in `internal/web/controller/api.go` (`checkAPIAuth`): the panel hashes what is presented and compares it to the stored hash. If the stored token is a valid hash and the correct plaintext is presented, it matches. If the presented string is wrong (e.g., a hash digest instead of the original plaintext, or the wrong token value), it will not match. **What changed in v3.4.1** The v3.4.1 changelog contains no changes to API token storage, the `checkAPIAuth` middleware, or the `Match` function. The token-hashing migration was introduced in v3.2.7 (`fix(api-token): hash tokens at rest and show plaintext only once`), and a database seeder (`hashExistingApiTokens`, in `internal/database/db.go`) runs on startup to hash any plaintext tokens that pre-date that release. Nothing in v3.4.1 touches this path. **Most likely causes** 1. The plaintext token value was not saved at creation time and has since been lost. Because the hash is irreversible, the only remedy is to delete the existing token in **Settings → Authentication → API Token** and create a new one, copying the plaintext immediately. 2. The token is being sent in a format other than `Authorization: Bearer <token>` (e.g., as a query parameter, in a different header, or with a `Token ` prefix instead of `Bearer `). 3. The token row is disabled. Check Settings → Authentication → API Token and confirm the toggle is on. **To confirm and resolve** 1. In **Settings → Authentication → API Token**, verify at least one token is enabled. 2. If the plaintext is unavailable, delete the existing token(s) and create a new one. Save the displayed value immediately. 3. Test with a minimal curl request to confirm the format: ```bash curl -s -o /dev/null -w "%{http_code}" \ -H "Authorization: Bearer <your-plaintext-token>" \ https://<your-panel>/panel/api/inbounds/list ``` A `200` response means authentication is working. A `401` or `404` means the token or header format is wrong. **Information needed to investigate further** If the above does not resolve the issue, please provide: 1. The panel version you upgraded **from** (not just the current version). 2. The exact HTTP call being made (tool, headers, endpoint — with sensitive values redacted). 3. The HTTP status code returned (`401`, `404`, or other). 4. Panel logs from around the time of the failed request: ```bash journalctl -u x-ui --since "1 hour ago" -n 200 ``` *This reply was generated automatically; a maintainer may follow up.*
Author
Owner

@MHSanaei commented on GitHub (Jun 26, 2026):

Everything works

<!-- gh-comment-id:4812258440 --> @MHSanaei commented on GitHub (Jun 26, 2026): Everything works
Author
Owner

@hellousersxx commented on GitHub (Jun 27, 2026):

If you fixed the problem, how did you do it? Let me know if you got it fixed.

<!-- gh-comment-id:4822544780 --> @hellousersxx commented on GitHub (Jun 27, 2026): If you fixed the problem, how did you do it? Let me know if you got it fixed.
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#3908
No description provided.