mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-03 21:18:19 +07:00
[GH-ISSUE #5951] [Bug]: Duplicate client created when changing email case (case-only edit) #4125
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#4125
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 @parsa-fathi on GitHub (Jul 14, 2026).
Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/5951
Describe the bug
Description
After the latest update, editing a client's email by changing only its letter casing (for example,
test→Test) no longer works correctly.Steps to Reproduce
Create a client with the email:
Edit the same client.
Change the email to:
Save the changes.
Expected Behavior
The existing client should be updated successfully, preserving the same record while only changing the email's letter casing. This was the behavior before the latest update.
Actual Behavior
The panel first returns the following error:
Despite the error, a new client is created with the updated email (
Test), while the original client (test) remains.As a result, two separate clients end up existing with what should effectively be the same email, differing only by letter casing.
Additional Information
This issue did not exist before the latest update. Previously, changing only the capitalization of an existing client's email worked correctly without triggering a uniqueness error or creating a duplicate client.
How to reproduce the problem
Create a client with the email:
Edit the same client.
Change the email to:
Save the changes.
Expected behavior
No response
Actual behavior
No response
Relevant logs
Screenshots
No response
3x-ui version
3.5.0
Xray-core version
No response
How did you install 3x-ui?
install.sh script
Operating system
Ubuntu 26
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 (Jul 14, 2026):
Confirmed as a genuine bug; root cause traced end-to-end through the update path used by the panel edit-client action (
POST /panel/api/clients/update/:email->ClientController.updateininternal/web/controller/client.go:159->ClientService.UpdateByEmail/Updateininternal/web/service/client_crud.go).Title: Case-only email edits are inconsistently treated as "unchanged" vs "changed" across three call sites, which desyncs the
clientstable row from the inbound settings JSON and produces an orphaned duplicate plus a rawUNIQUE constraint failed: clients.emailerror.Severity: High
Category: Correctness
Why this matters:
Editing a client email is a common action, and a same-inbound, single-client edit is enough to trigger this - no multi-inbound setup needed. The panel ends up with two
clientsrows for what the admin intends as one identity: the original row (still holding the old-cased email) becomes an orphan detached from every inbound, while a new row is created under the new casing and keeps the live traffic/expiry/subscription state going forward. That silently splits client history and quota tracking across two records, and surfaces a raw SQL error to the admin instead of a clean validation message.Trace of what happens for
testtoTest(client attached to one inbound):ClientService.Update(internal/web/service/client_crud.go:366) comparesupdated.Email != existing.Emailwith a case-sensitive Go!=, sees a change, and pre-checks for collisions excluding the record itself - passes, since no other row is namedTestyet.UpdateInboundClient(internal/web/service/client_inbound_apply.go:525) witholdEmail="test"and the new settings JSON already containingTest. That function persists the inbound settings JSON with the new casing (tx.Save(oldInbound), line 805), then reaches the rename gate for the client record at line 810:strings.EqualFold("test", "Test")istrue, so!EqualFold(...)isfalseand this block is skipped - the existingclientsrow keepsemail = "test".SyncInboundruns (internal/web/service/client_link.go:12) with the client list re-read from the just-saved settings (email now"Test"). Its existing-record lookup is case-sensitive SQL: This does not find the"test"row under the key"Test"(internal/web/service/client_link.go:59-66), so it falls into the create-new-record branch and inserts a newClientRecordwithemail="Test". The link for the old"test"row inclient_inboundswas already deleted at the top ofSyncInbound(line 17) and is never recreated, so that row becomes an orphan. This transaction commits successfully - the duplicate now exists.ClientService.Update, after the inbound loop, the fallback rename for records with no inbound left runs unconditionally on the same case-sensitive check: This targets the original row (id from step 1, stillemail="test") and tries to rename it to"Test"too - but that value is now taken by the row created in step 3, so this rawUPDATEhits theuniqueIndexonClientRecord.Email(internal/database/model/model.go:828) and returns the raw SQLite errorUNIQUE constraint failed: clients.email, which the controller reports as "Something went wrong". By this point the duplicate from step 3 is already committed, matching the reported symptom exactly.No
COLLATE NOCASE/citext is used anywhere on this column (confirmed via repo-wide search), so both SQLite and Postgres compareemailcase-sensitively by default - consistent with the duplicate actually being created in step 3 rather than failing immediately.The existing regression test
TestUpdateInboundClientRenameDoesNotDuplicateRecord(internal/web/service/client_update_rename_test.go:19) only covers a full rename (old@xtonew@x), so it does not exercise the case-only path and would not have caught this.Recommendation: Pick one consistent case-sensitivity policy for "did the email change" and apply it at all three decision points, instead of mixing
strings.EqualFold(steps 2/3) with a raw Go!=(steps 1/4) and a case-sensitive SQL lookup (SyncInboundemail IN ?). In particular, the existing-record lookup ininternal/web/service/client_link.goneeds to find the current row for a case-only rename (for example, match case-insensitively there too, or have the rename gate inclient_inbound_apply.go:810fire on any byte-level difference so the row is renamed beforeSyncInboundruns and its case-sensitive lookup then matches by construction). The fallback rename inclient_crud.go:428should use the same comparison as the gate it backstops. A regression test with a case-only email edit (mirroringTestUpdateInboundClientRenameDoesNotDuplicateRecordbutold@xtoOld@x) would catch this going forward.Confidence: High - traced through the actual source for the exact request path the panel UI uses, with no assumptions about code not shown above.
@MHSanaei for a decision on the fix (per repo policy, changes are made only when requested via @claude).
This analysis was generated automatically; a maintainer may follow up.