mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-03 21:18:19 +07:00
[GH-ISSUE #5145] [Bug]: -getApiToken does not work as expected #3616
Labels
No labels
backlog
bug
clarification needed
documentation
duplicate
enhancement
github_actions
good first issue
invalid
javascript
New Feature
PR welcomed
pull-request
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
MHSanaei/3x-ui#3616
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @brazhenko on GitHub (Jun 9, 2026).
Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/5145
Describe the bug
When I run
docker exec 3x-ui /app/x-ui setting -getApiTokenI expect to see token as in old version, but seeapiToken:(no token).How to reproduce the problem
root@tw:/opt/3x-ui# docker exec 3x-ui /app/x-ui setting -getApiTokenExpected behavior
I expect either to see token or do not have such option at all.
Actual behavior
No response
Relevant logs
Screenshots
No response
3x-ui version
3.3.0
Xray-core version
No response
How did you install 3x-ui?
Docker / Docker Compose
Operating system
Debian 13
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
@github-actions[bot] commented on GitHub (Jun 9, 2026):
This is a confirmed bug introduced by commit
4813a2fe("hash tokens at rest and show plaintext only once").Root cause
web/service/api_token.go—toView()intentionally omits the token value when building the list response:main.go—GetApiToken()callsList()and then tries to printtokens[0].Token, which is always"":Since tokens are now stored as SHA-256 hashes, the plaintext can never be recovered after creation. The
GetApiTokenfunction was not updated to account for this.The only case where the flag still works is when the
api_tokenstable is completely empty (fresh container, no tokens ever created). In that case the code falls through toCreate("install"), which generates and prints a new plaintext token. If a token named"install"already exists, that path also fails with "a token with that name already exists".Workaround (until this is fixed)
Panel UI — go to Settings → API Tokens, delete the existing token, create a new one, and copy the plaintext shown immediately after creation.
Docker — fresh token via the panel API — if you have temporary access to the panel, create a token through the UI first, then use it for subsequent API calls.
Force-create via CLI — if the
api_tokenstable has no rows (e.g. brand-new container with a blank DB), the flag will create and print one token. You can achieve this by starting with a fresh database volume, running the panel once, and immediately runningdocker exec 3x-ui /app/x-ui setting -getApiTokenbefore any token is created through the UI.Expected fix
GetApiTokenshould detect that existing tokens cannot be retrieved (since only hashes are stored) and either: