[PR #5182] [CLOSED] fix: deduplicate clients in subscription links (#5134) #5808

Closed
opened 2026-11-02 04:04:13 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/MHSanaei/3x-ui/pull/5182
Author: @rqzbeh
Created: 6/10/2026
Status: ❌ Closed

Base: main ← Head: fix/duplicate-sub-links


📝 Commits (1)

  • f61d5a4 fix: deduplicate clients in subscription links (#5134)

📊 Changes

3 files changed (+21 additions, -0 deletions)

View changed files

📝 internal/sub/clash_service.go (+7 -0)
📝 internal/sub/json_service.go (+7 -0)
📝 internal/sub/service.go (+7 -0)

📄 Description

Fixes #5134.

Summary

This PR deduplicates clients by email when building subscription links, JSON, and Clash configs.

Why

Closes #5134

When generating subscription data (\GetSubs, \GetJson, \GetClash), the code iterated over the legacy \settings.clients\ array of an inbound without guarding against duplicates. If a remote node's DB (or legacy state) contained duplicate client objects for the same \subId, the subscription builder emitted duplicate links or proxy objects. This fix explicitly deduplicates clients by their unique email per inbound before appending them to the output, ensuring clean subscriptions regardless of dirty DB state.

Type of change

  • Bug fix
  • New feature
  • Refactoring (no behavior change)
  • Documentation
  • Tests only
  • Build / CI / tooling
  • Other

Areas affected

  • Frontend (UI / panel pages)
  • Backend (API endpoints, login, settings)
  • Xray config generation
  • Subscription (share links / Clash / JSON)
  • Statistics / traffic counters
  • Database / migrations
  • Install / upgrade script
  • Docker image
  • Multi-node (sub-nodes)
  • Telegram bot

How was this tested?

  1. Duplicated a client in the DB manually or setup a client that replicates dirty state in \settings.clients.
  2. Evaluated the output of /sub/, /json/\ and /clash/\ before the fix to verify duplicate subscriptions were returned.
  3. Evaluated the output after applying the fix to verify that deduplication now yields only a single entry per inbound, per client email.

Screenshots / recordings

N/A

Breaking changes

None.

Checklist

  • I tested the change locally and confirmed the described behavior.
  • I added or updated tests for the new behavior (when applicable).
  • \go build ./...\ and the test suite pass locally.
  • For frontend changes:
    pm run lint,
    pm run typecheck, and
    pm run build\ pass.
  • I updated the Wiki / README / API docs if user-facing behavior changed.
  • My commits follow the project's existing message style.
  • I have no unrelated changes mixed into this PR.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/MHSanaei/3x-ui/pull/5182 **Author:** [@rqzbeh](https://github.com/rqzbeh) **Created:** 6/10/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `fix/duplicate-sub-links` --- ### 📝 Commits (1) - [`f61d5a4`](https://github.com/MHSanaei/3x-ui/commit/f61d5a4e692b4e3473e83b3579bf2594eb60ad0f) fix: deduplicate clients in subscription links (#5134) ### 📊 Changes **3 files changed** (+21 additions, -0 deletions) <details> <summary>View changed files</summary> 📝 `internal/sub/clash_service.go` (+7 -0) 📝 `internal/sub/json_service.go` (+7 -0) 📝 `internal/sub/service.go` (+7 -0) </details> ### 📄 Description Fixes #5134. ## Summary This PR deduplicates clients by email when building subscription links, JSON, and Clash configs. ## Why Closes #5134 When generating subscription data (\GetSubs\, \GetJson\, \GetClash\), the code iterated over the legacy \settings.clients\ array of an inbound without guarding against duplicates. If a remote node's DB (or legacy state) contained duplicate client objects for the same \subId\, the subscription builder emitted duplicate links or proxy objects. This fix explicitly deduplicates clients by their unique email per inbound before appending them to the output, ensuring clean subscriptions regardless of dirty DB state. ## Type of change - [x] Bug fix - [ ] New feature - [ ] Refactoring (no behavior change) - [ ] Documentation - [ ] Tests only - [ ] Build / CI / tooling - [ ] Other ## Areas affected - [ ] Frontend (UI / panel pages) - [ ] Backend (API endpoints, login, settings) - [ ] Xray config generation - [x] Subscription (share links / Clash / JSON) - [ ] Statistics / traffic counters - [ ] Database / migrations - [ ] Install / upgrade script - [ ] Docker image - [ ] Multi-node (sub-nodes) - [ ] Telegram bot ## How was this tested? 1. Duplicated a client in the DB manually or setup a client that replicates dirty state in \settings.clients\. 2. Evaluated the output of \/sub/\, \/json/\ and \/clash/\ before the fix to verify duplicate subscriptions were returned. 3. Evaluated the output after applying the fix to verify that deduplication now yields only a single entry per inbound, per client email. ## Screenshots / recordings N/A ## Breaking changes None. ## Checklist - [x] I tested the change locally and confirmed the described behavior. - [ ] I added or updated tests for the new behavior (when applicable). - [x] \go build ./...\ and the test suite pass locally. - [ ] For frontend changes: \ pm run lint\, \ pm run typecheck\, and \ pm run build\ pass. - [ ] I updated the Wiki / README / API docs if user-facing behavior changed. - [x] My commits follow the project's existing message style. - [x] I have no unrelated changes mixed into this PR. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-02 04:04:13 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
MHSanaei/3x-ui#5808
No description provided.