[PR #5855] [MERGED] fix(clients): parse only settings.clients across protocols #6009

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

📋 Pull Request Information

Original PR: https://github.com/MHSanaei/3x-ui/pull/5855
Author: @n0ctal
Created: 7/8/2026
Status: ✅ Merged
Merged: 7/8/2026
Merged by: @MHSanaei

Base: main ← Head: upstream-c1-limitip


📝 Commits (2)

  • 8ab7d23 fix(clients): parse only settings.clients across protocols
  • 52508dd fix(clients): reject empty inbound settings

📊 Changes

6 files changed (+200 additions, -21 deletions)

View changed files

📝 internal/web/job/check_client_ip_job.go (+4 -6)
📝 internal/web/job/check_client_ip_job_test.go (+37 -0)
📝 internal/web/service/inbound.go (+1 -11)
➕ internal/web/service/inbound_settings_clients.go (+32 -0)
➕ internal/web/service/inbound_settings_clients_test.go (+124 -0)
📝 internal/web/service/inbound_traffic.go (+2 -4)

📄 Description

Summary

Fix the remaining inbound settings readers that decode the whole settings JSON object as map[string][]model.Client.

Real protocol settings include scalar protocol fields next to clients:

  • VLESS: decryption, encryption
  • Hysteria/Hysteria2: version

Those fields are not []model.Client, so decoding the whole object into map[string][]model.Client can fail before callers safely use settings.clients, or leave them relying on decoder side effects.

This PR adds one shared helper that extracts only settings.clients through json.RawMessage, then uses it from:

  • InboundService.GetClients
  • InboundService.SearchClientTraffic
  • IP-limit job fallback/disconnect paths

Why

settings.clients is the only field these paths need. Other protocol settings should not be part of the client-list decode contract.

Without this, valid inbounds with scalar protocol fields can make client lookups fail or behave by accident depending on JSON field ordering and whether the caller ignores the decode error.

Scope

  • Add ParseInboundSettingsClients.
  • Replace the fragile whole-settings client map decode in the remaining read paths.
  • Add regression tests for VLESS and Hysteria settings containing scalar protocol keys.
  • No schema changes.
  • No runtime/protocol generation changes.

Validation

  • go test ./internal/web/job ./internal/web/service -count=1
  • go test -race ./internal/web/job ./internal/web/service -run 'TestParseInboundSettingsClientsIgnoresProtocolScalarFields|TestGetClientsIgnoresProtocolScalarFields|TestSearchClientTrafficIgnoresProtocolScalarFields|TestGetInboundByEmailFallbackIgnoresProtocolScalarFields' -count=1
  • go vet ./internal/web/job ./internal/web/service
  • npm ci && npm run gen && npm run build
  • go build ./...
  • git diff --check

golangci-lint was not available in the local environment.

Risk

Low. For valid settings, callers receive the same clients array. The change only ignores unrelated protocol fields during client-list extraction. Malformed JSON still returns an error to callers that already handle parse failures.


🔄 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/5855 **Author:** [@n0ctal](https://github.com/n0ctal) **Created:** 7/8/2026 **Status:** ✅ Merged **Merged:** 7/8/2026 **Merged by:** [@MHSanaei](https://github.com/MHSanaei) **Base:** `main` ← **Head:** `upstream-c1-limitip` --- ### 📝 Commits (2) - [`8ab7d23`](https://github.com/MHSanaei/3x-ui/commit/8ab7d23f9288a887c3a4bcc9491f4670b78b6f60) fix(clients): parse only settings.clients across protocols - [`52508dd`](https://github.com/MHSanaei/3x-ui/commit/52508dd3263ae160f67848289e75c4d5af10a27b) fix(clients): reject empty inbound settings ### 📊 Changes **6 files changed** (+200 additions, -21 deletions) <details> <summary>View changed files</summary> 📝 `internal/web/job/check_client_ip_job.go` (+4 -6) 📝 `internal/web/job/check_client_ip_job_test.go` (+37 -0) 📝 `internal/web/service/inbound.go` (+1 -11) ➕ `internal/web/service/inbound_settings_clients.go` (+32 -0) ➕ `internal/web/service/inbound_settings_clients_test.go` (+124 -0) 📝 `internal/web/service/inbound_traffic.go` (+2 -4) </details> ### 📄 Description ## Summary Fix the remaining inbound settings readers that decode the whole `settings` JSON object as `map[string][]model.Client`. Real protocol settings include scalar protocol fields next to `clients`: - VLESS: `decryption`, `encryption` - Hysteria/Hysteria2: `version` Those fields are not `[]model.Client`, so decoding the whole object into `map[string][]model.Client` can fail before callers safely use `settings.clients`, or leave them relying on decoder side effects. This PR adds one shared helper that extracts only `settings.clients` through `json.RawMessage`, then uses it from: - `InboundService.GetClients` - `InboundService.SearchClientTraffic` - IP-limit job fallback/disconnect paths ## Why `settings.clients` is the only field these paths need. Other protocol settings should not be part of the client-list decode contract. Without this, valid inbounds with scalar protocol fields can make client lookups fail or behave by accident depending on JSON field ordering and whether the caller ignores the decode error. ## Scope - Add `ParseInboundSettingsClients`. - Replace the fragile whole-settings client map decode in the remaining read paths. - Add regression tests for VLESS and Hysteria settings containing scalar protocol keys. - No schema changes. - No runtime/protocol generation changes. ## Validation - `go test ./internal/web/job ./internal/web/service -count=1` - `go test -race ./internal/web/job ./internal/web/service -run 'TestParseInboundSettingsClientsIgnoresProtocolScalarFields|TestGetClientsIgnoresProtocolScalarFields|TestSearchClientTrafficIgnoresProtocolScalarFields|TestGetInboundByEmailFallbackIgnoresProtocolScalarFields' -count=1` - `go vet ./internal/web/job ./internal/web/service` - `npm ci && npm run gen && npm run build` - `go build ./...` - `git diff --check` `golangci-lint` was not available in the local environment. ## Risk Low. For valid settings, callers receive the same `clients` array. The change only ignores unrelated protocol fields during client-list extraction. Malformed JSON still returns an error to callers that already handle parse failures. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-02 04:05:43 +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#6009
No description provided.