mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-03 21:18:19 +07:00
[PR #6175] [MERGED] fix(cli): stop -getApiToken accumulating admin tokens #6137
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#6137
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?
📋 Pull Request Information
Original PR: https://github.com/MHSanaei/3x-ui/pull/6175
Author: @n0ctal
Created: 8/5/2026
Status: ✅ Merged
Merged: 8/14/2026
Merged by: @MHSanaei
Base:
main← Head:upstream-cli-fallback-token-expiry📝 Commits (3)
3346553fix(cli): stop -getApiToken accumulating admin tokens0f401befix(api-token): preserve token on failed replacement20b3bc6Merge branch 'main' into upstream-cli-fallback-token-expiry📊 Changes
3 files changed (+108 additions, -6 deletions)
View changed files
📝
internal/web/service/panel/api_token.go(+24 -0)📝
internal/web/service/panel/api_token_test.go(+76 -1)📝
main.go(+8 -5)📄 Description
Summary
x-ui setting -getApiTokenminted a newcli-fallback-<unix>token on every invocation when tokens already existed. Rotate a singlecli-fallbacktoken instead.Why
The flag reads like a getter, and the surrounding output explains that existing tokens cannot be retrieved because only hashes are stored. It then creates one anyway — a fresh row, enabled, with no expiry, printed once.
An operator who runs the command a few times while debugging leaves several credentials behind. They all carry the same authority, none can be told apart later, and nothing indicates they were created rather than read.
ApiTokenhas no expiry column, so they persist until someone notices and deletes them by hand.I hit this while working on a downstream fork: four invocations left four enabled tokens on a production panel, and they were only spotted during an unrelated audit.
Scope
internal/web/service/panel/api_token.go— newRecreateByName, which deletes any row with that name before callingCreate, so exactly one exists.main.go— the fallback uses the fixed namecli-fallbackviaRecreateByName; the message states the previous token is now invalid. Drops the now-unusedtimeimport.internal/web/service/panel/api_token_test.go—TestRecreateByNameKeepsOneTokenasserts a second call rotates the plaintext and leaves one row.Validation
go test ./internal/web/service/panel/ -count=1green;go build ./...andgo vet ./...clean.a token with that name already exists.Risk
Low. The fallback keeps working; the only behaviour change is that a previously issued CLI fallback token stops working when a new one is printed, which the message now says. Tokens created through the UI are untouched.
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.