mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-03 21:18:19 +07:00
[PR #6489] [MERGED] fix(tgbot): require client ownership for non-admin link callbacks #6301
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#6301
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/6489
Author: @BlindMaster24
Created: 9/12/2026
Status: ✅ Merged
Merged: 9/13/2026
Merged by: @MHSanaei
Base:
main← Head:fix/tgbot-client-links-authz📝 Commits (1)
7a058f9fix(tgbot): require client ownership for non-admin link callbacks📊 Changes
3 files changed (+176 additions, -17 deletions)
View changed files
📝
internal/web/service/tgbot/tgbot_client.go(+15 -0)➕
internal/web/service/tgbot/tgbot_client_links_authz_test.go(+125 -0)📝
internal/web/service/tgbot/tgbot_router.go(+36 -17)📄 Description
Summary
The gate also has to be able to read which client the button names: payloads
past 64 characters arrive as a hash, so the raw callback data is now decoded
before it is judged.
A non-admin could pull any client's subscription links through the bot's link
buttons. The three callbacks that carry an email (
client_sub_links <email>,client_individual_links <email>,client_qr_links <email>) did not re-checkthat the client belongs to the Telegram account pressing the button.
Why
The bot answers callbacks for two audiences: admins (who own every client) and
clients (who must only ever see their own). For the second audience the email in
the callback data was trusted as-is, so the keyboard — not the caller — decided
which client was served. The sibling callback
client_trafficalready does itcorrectly: it resolves the caller's clients from
callbackQuery.From.ID(
getClientUsage->GetClientTrafficTgBot(tgUserID),tgbot_client.go:557),and the guard's own doc comment claimed the same for all of them
(
isClientSelfCallback,tgbot_router.go:1331).The intent was there; only the check was missing.
Why the data cannot authorise itself
An inline keyboard outlives the chat it was sent to, so "the button exists"
is not proof of access:
taps All clients -> inbound -> client. The keyboard is delivered to the
group, so every member can press Subscription links. The callback arrives
with the member's
From.ID,isAdminis false, and before this change themember was served the client's sub URL and then, from that message, the
Individual links / QR code buttons — which contain the
vless:///
trojan://URI with the client's UUID or password.The recipient taps it and receives a working configuration for a client they
were never granted.
tg-user->Remove) is how an operator ends that client's bot access, but the card
already sitting in the client's chat keeps working: nothing on the callback
path re-read the client's
tgId, so the ex-client could keep minting freshlinks and QR codes for the config after being cut off.
Scenario 3 is the one that also matters for an operator who never uses groups:
revocation through the bot did not actually revoke anything that had already
been delivered.
The payload has to be readable before it can be judged
encodeQueryreplaces any callback payload longer than 64 characters with itsMD5 hash, and this gate tested the raw data. For a client whose email is long
enough the gate therefore saw a bare hash:
client_individual_linksis 24 characters, so it hashes from a 41-characteremail
client_sub_linksandclient_qr_linksare 17, so from a 48-character oneThose clients' own link buttons — the ones the bot builds for them — arrived as a
hash, matched nothing, and were dropped in silence: the ownership guard never
ran, and the client pressed a button that did nothing. The raw data is now
decoded before the gate, using the same decode the admin path has always
performed.
Type of change
Areas affected
How was this tested?
internal/web/service/tgbot/tgbot_client_links_authz_test.go, three cases againsta mocked Telegram API and a throwaway SQLite DB seeded with one inbound whose
settings bind
owner@xto Telegram id 4242:TestClientLinkCallbackRefusesForeignClient— the owner's id tapsclient_sub_links someone-else@x. Asserts nosendMessagewas sent andthat the tap was answered exactly once. Without the ownership check the
keyboard is served, so this test fails on the old code.
TestClientLinkCallbackServesOwnClient— the same id taps its own email.Asserts one
sendMessageand no refusal, so the guard cannot pass by simplyblocking everyone.
TestHashedLinkCallbackServesOwnClient— the same seeded client with a54-character address, whose button data
encodeQueryturns into a hash. Theowner taps that hash and must still be served. On the old code the gate never
runs and nothing is sent, so this fails before the fix as well.
I could not build or run the tests on my machine: it has no C compiler at all,
and the CGo SQLite driver (
mattn/go-sqlite3) makes every package that importsinternal/database— including this one — fail to compile without one(
CONTRIBUTING.mdcovers the MinGW-w64 install for Windows).gofmtis clean;CI is the build here.
Screenshots / recordings
N/A — bot callbacks, no UI.
Breaking changes
None for admins. A non-admin who legitimately owns the client is unaffected
(
TestClientLinkCallbackServesOwnClient). A non-admin whose client has noclient_trafficsrow yet is refused by the same lookup the Client usagebutton already relies on.
Checklist
go build ./...and the test suite pass locally. — same reason as above.npm run lint,npm run typecheck, andnpm run buildpass. — no frontend files touched.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.