mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-03 19:11:53 +07:00
[GH-ISSUE #6478] [Bug]: Portable client import forces enable=true, reactivating disabled clients #4372
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#4372
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 @mrchatam on GitHub (Sep 11, 2026).
Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/6478
Describe the bug
ExportAllserializes each client's realenableflag viaClientRecord.ToClient(). On import, both paths that recreate clients unconditionally forceenableto true:ImportClients→BulkCreate(internal/web/service/client_bulk.go):ImportClientsorphan loop (internal/web/service/client_portable.go): same pattern.Because a Go
boolcannot distinguish "omitted" fromfalseafter JSON unmarshal, this is equivalent to always writingEnable: true. A round-trip of a disabled client therefore reactivates it and (for attached imports) pushes it back into Xray as enabled.This is adjacent to the portable traffic-preserve work (#5858 / #6469) but is a separate correctness hole: even after traffic counters round-trip, disabled clients still come back enabled.
How to reproduce the problem
enable: false), confirm it is disabled in the Clients list and absent/disabled in Xray.ExportAll).Expected behavior
Portable import preserves
enablefrom the export payload. Disabled clients stay disabled; enabled clients stay enabled. (APIBulkCreateused as a plain "create many" may still choose to default omitted enable to true — but an explicitenable: falsefrom an export must not be overwritten.)Actual behavior
Every imported client is created with
enable: true, including ones that were disabled at export time.File pointers
internal/web/service/client_portable.go— orphan branch (if !client.Enable { client.Enable = true })internal/web/service/client_bulk.go—BulkCreate(same force)ClientRecord.ToClient()copiesEnablecorrectly; the loss is on import only3x-ui version
main (current default branch)
Suggested fix size
Small-to-medium: preserve
enableon the ImportClients path (orphans + attached). IfBulkCreatemust keep "default to enabled" for the create API, use a pointer/*boolor a separate import entrypoint so export's explicitfalsesurvives.@github-actions[bot] commented on GitHub (Sep 11, 2026):
Thanks — this is a real bug, but you already filed it as #6475 one minute earlier, and that issue has the full analysis. I'm closing this one as a duplicate so the discussion stays in one place; #6475 remains open and is the tracked report.
I did not take that on faith — I re-derived the root cause here before closing, and the two reports land on the same two lines.
The shared root cause
Export preserves the flag.
ClientRecord.ToClient()copies it verbatim (internal/database/model/model.go:1207):and
model.Client.Enablecarries noomitempty(internal/database/model/model.go:901), so a disabled client is serialized as an explicit"enable": false:Import then discards it, in both branches, exactly as you described:
BulkCreate,internal/web/service/client_bulk.go:1313-1315ImportClientsorphan loop,internal/web/service/client_portable.go:158-160both being the identical:
On the attached path the forced
truealso reaches the running Xray, becauseAddInboundClienthas a guard that would have skipped a disabled client (internal/web/service/client_inbound_apply.go:572-574):That guard never fires, because
BulkCreatehas already flipped the flag beforeAddInboundClientsees the client.Worth noting for context: the same force-enable also sits in the single-client create path (
internal/web/service/client_crud.go:157-159), so "a create starts enabled" is a deliberate panel-wide default thatImportClientssimply inherited — which is why the fix belongs on the import path rather than in the shared create code, as you suggested.Workaround until it is fixed
Re-disable the affected clients in one call after importing.
BulkSetEnablehandles orphans too — with no inbound mappings they fall straight through the fan-out intosuccessEmailsand get theirclient_records/client_trafficsrows updated (internal/web/service/client_bulk.go:1616-1640):Feed it the emails whose export entries carry
"enable": false. The same action is available in the UI as the bulk Disable button on the Clients page.Verdict: Duplicate
Severity: High
Confidence: High
Root cause:
if !client.Enable { client.Enable = true }on the import path, in two places —ClientService.BulkCreate(internal/web/service/client_bulk.go:1313-1315) for items carryinginboundIds, and the orphan loop inClientService.ImportClients(internal/web/service/client_portable.go:158-160) for items without. Triggers for every payload item whoseenableisfalse, whichExportAllalways emits explicitly for a disabled client. The orphan-path force arrived with0b0b6250feat(clients): orphan cleanup + export/import via CodeMirror modals (2026-06-21), the commit that addedImportClients; v3.4.0 (2026-06-23) is the first release carrying it.Already fixed: Still present on the default branch at
0a2cd789.git log -S 'if !client.Enable {'over both files returns only0b0b6250and the41645255file-move refactor — nothing since changes either line.Duplicate of: #6475 — same two force-enable sites discarding the exported
enableflag; same author, filed one minute earlier, and already analysed thereEvidence:
internal/database/model/model.go:901(Enable boolwith json tagenable, noomitempty);internal/database/model/model.go:1207(Enable: r.EnableinToClient);internal/web/service/client_bulk.go:1313-1315;internal/web/service/client_portable.go:158-160;internal/web/service/client_inbound_apply.go:572-574(theif !client.Enable { continue }guard the forced flag defeats);internal/web/service/client_crud.go:157-159(the same default on single create);internal/web/service/client_bulk.go:1616-1640(BulkSetEnablecovers orphans);frontend/src/pages/api-docs/endpoints.ts:1312(thebulkDisableroute used in the workaround); introducing commit0b0b6250. No test in the repo pins the current force-enable behaviour, so nothing asserts it is intended.Not determined: Whether
POST /panel/api/clients/bulkCreateshould also honour an explicit"enable": falsefrom an ordinary API caller. That is a public-API contract decision the source does not settle, and it changes the shape of the fix — it is called out on #6475 and is a maintainer call.This reply was generated automatically; a maintainer may follow up.