3x-ui/internal
ilyusha 05a083eaef
fix(api-token): keep a token's scope when -getApiToken regenerates it, add -tokenScope (#6700)
* fix(api-token): keep a token's scope when the CLI regenerates it

RecreateByName deleted the named row and created a new one without a Scope,
so the insert took the column default of admin. Since -tokenName lets the CLI
regenerate any token, rotating a monitor or node-sync token silently turned it
into a full-access one.

The replacement now takes the scope of the row it replaces, and a new name
still gets admin as before. A stored scope this build does not know, as after
a downgrade, fails the rotation and leaves the row alone instead of guessing.

Assisted-by: Claude Code:claude-opus-5-5 (mostly)

* feat(cli): let -getApiToken choose the scope of the token it issues

-tokenScope sets the scope on both branches of -getApiToken: the token minted
on a fresh panel and the one regenerated on a populated panel. Without the flag
a regenerated token keeps its scope and a new one gets admin, so every existing
invocation, install.sh included, behaves as before.

An unknown scope is refused before anything is deleted, so a typo cannot
revoke the token it meant to rotate.

Assisted-by: Claude Code:claude-opus-5-5 (mostly)

* fix(api-token): keep a token's expiry when the CLI regenerates it

RecreateByName built the replacement row with ExpiresAt 0, so running
`x-ui setting -getApiToken -tokenName <name>` on a token issued through
the API with a deadline handed back one that never expires, and said
nothing about it - the same silent widening this branch fixed for scope.

The replacement now carries the replaced row's ExpiresAt. A token whose
deadline has already passed is refused instead of rotated, since keeping
the deadline would mint a dead token and dropping it would revive an
expired credential without limit; the expired row is left untouched.

---------

Co-authored-by: Sanaei <ho3ein.sanaei@gmail.com>
2026-10-02 19:05:27 +02:00
..
amneziawg fix(amneziawg): bound S1-S3 by the receive buffer, reject overlapping H (#6642) 2026-09-26 22:02:49 +02:00
amneziawgnet feat(panel): let a sponsor slot start at a scheduled time 2026-09-27 16:32:45 +02:00
config v3.8.5 2026-09-16 02:08:08 +02:00
crypto/nodetoken fix(nodetoken): stop refusing every node-token key file on Windows 2026-09-27 15:55:42 +02:00
database feat(xray): update xray-core to v26.9.30 and adapt panel 2026-10-02 13:54:39 +02:00
eventbus chore: refresh dependencies, fix Linux tool tasks, modernize Go idioms 2026-07-25 16:08:09 +02:00
logger fix(logger): reuse the open log rotator when InitLogger runs again 2026-09-27 15:32:20 +02:00
mtproto fix(mtproto): synchronize child-process lifecycle (#6141) 2026-07-29 20:56:26 +02:00
pia chore(build): bump Go toolchain to 1.27.0 2026-08-23 21:57:03 +02:00
sub Fix fragment exports for older Xray clients (#6702) 2026-10-02 17:38:44 +02:00
testpg test(database): give each package its own schema when tests run on PostgreSQL (#6594) 2026-09-26 21:13:42 +02:00
tuic fix(tuic): evict the oldest relay flow instead of refusing new clients 2026-09-12 10:40:41 +02:00
tunnelmonitor style: adopt golangci-lint v2 and resolve all findings 2026-06-27 15:42:22 +02:00
util fix(sub): carry REALITY ML-KEM hint in VLESS links (#6712) 2026-10-02 15:44:41 +02:00
web fix(api-token): keep a token's scope when -getApiToken regenerates it, add -tokenScope (#6700) 2026-10-02 19:05:27 +02:00
xray feat(xray): update xray-core to v26.9.30 and adapt panel 2026-10-02 13:54:39 +02:00