Skip to content

fix: use MultiUserServerConfig for SS2022 with empty clients array#2

Draft
Copilot wants to merge 4 commits intomainfrom
copilot/fix-easy-issue-in-fork
Draft

fix: use MultiUserServerConfig for SS2022 with empty clients array#2
Copilot wants to merge 4 commits intomainfrom
copilot/fix-easy-issue-in-fork

Conversation

Copy link

Copilot AI commented Mar 6, 2026

When a Shadowsocks 2022 inbound is configured with "clients": [], buildShadowsocks2022() creates a single-user ServerConfig (no UserManager) instead of MultiUserServerConfig, making it impossible to add users via gRPC API.

Root cause: len(v.Users) == 0 is true for both a nil slice (field omitted) and an empty slice ("clients": []). Go's JSON unmarshaler distinguishes these — omitted yields nil, empty array yields [].

Changes:

  • Changed guard from len(v.Users) == 0 to v.Users == nil so only a truly absent clients field produces single-user ServerConfig
  • Added len(v.Users) == 0 || before v.Users[0].Address == nil to prevent index-out-of-range on empty slice and correctly route to MultiUserServerConfig
// Before: both nil and empty [] hit this branch
if len(v.Users) == 0 {
    config := new(shadowsocks_2022.ServerConfig) // no UserManager

// After: only nil (field omitted) hits single-user path
if v.Users == nil {
    config := new(shadowsocks_2022.ServerConfig)

// Empty [] now falls through to multi-user path
if len(v.Users) == 0 || v.Users[0].Address == nil {
    config := new(shadowsocks_2022.MultiUserServerConfig) // implements UserManager

Added TestShadowsocks2022ServerConfigParsing covering both cases.


🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.

… no routing field

Fixes XTLS#5748. When passing a valid JSON config file with
no "routing" field to `xray api adrules`, `conf.RouterConfig` is nil,
causing a panic on dereference. Added a nil check to exit gracefully
with a descriptive error message instead.

Co-authored-by: odlev <65655276+odlev@users.noreply.github.com>
Copilot stopped work on behalf of odlev due to an error March 6, 2026 10:52
Copilot AI and others added 2 commits March 6, 2026 10:57
Co-authored-by: odlev <65655276+odlev@users.noreply.github.com>
When "clients": [] is explicitly set in Shadowsocks 2022 config,
create MultiUserServerConfig instead of single-user ServerConfig.
This allows users to be added later via the gRPC API.

Previously, both omitting "clients" and setting "clients": [] resulted
in the single-user ServerConfig which doesn't implement UserManager,
making it impossible to add users via gRPC API.

Fixes XTLS#5766

Co-authored-by: odlev <65655276+odlev@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix easy issue in Xray-core fork fix: use MultiUserServerConfig for SS2022 with empty clients array Mar 6, 2026
Copilot finished work on behalf of odlev March 6, 2026 11:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants