XMC finalmask: move every disconnect reason onto vanilla translation keys, and add a UUID allow list for Yggdrasil mode / XMC finalmask:踢出信息统一走原版翻译键,并为 Yggdrasil 模式补 UUID 白名单

Open
#7,493 2 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
35/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Active
Tech stack
go
Domain
networking

Research direction

Start with transport/internet/finalmask/xmc/server.go, especially the login flow and the Yggdrasil verification path, then inspect the related configuration and UUID parsing code. The issue is a discussion proposing two changes and leaves configuration shape, allow-list semantics, and several disconnect reasons undecided. First agree on those choices with maintainers; done means the selected behavior is implemented and the login disconnect reasons match the agreed vanilla translation keys.

Written by the indexing model from the issue text.

Description

XMC finalmask:踢出信息统一走原版翻译键,并为 Yggdrasil 模式补 UUID 白名单

类型:讨论 / proposal(先定方向,再动手)
基线:feat/xmc-config-clients-servers @ 536a075f
相关提交:35387572 (#6210 引入 XMC)、6ab123bf (#6487 引入那句硬编码文案)、5225121a (#7416 Yggdrasil)、84c2b8a0/50ac1fe5/536a075f(登录流程与单账号登录串行化)


摘要 / TL;DR

两个提案,目标都是「login 阶段的行为、文案、拒绝理由和原版 26.3 服务器无法区分」,顺带补一个真实的安全缺口:

A. 踢出信息(Login Disconnect 的 reason)

  1. 模块里现在有 6 个踢出点,其中 5 个已经用 {"translate": ...},只有 legacy 密码模式的「不在白名单」用的是 {"text":"You are not white-listed on this server!"} 硬编码英文。原版在 login / configuration 阶段从不发 literal 文本组件,这里必须改成 multiplayer.disconnect.not_whitelisted——显示文本一模一样,但会跟随客户端语言本地化(zh_CN → 你不在此服务器的白名单中!)。
  2. 顺手把 6 个 reason 逐个和原版 26.3 反编译源码对齐:3 个已一致,踢出点 4 需要拆分,踢出点 5 / 6 建议改,另有 1 类「静默断开」需要讨论。

B. Yggdrasil 模式没有 UUID 白名单

  1. 现状:Yggdrasil 模式只做 hasJoined 验证(外加 UUID/名字一致性检查),配置里的 profiles 完全不参与校验。任何能在该 API 完成认证并 /join 的账号都能建立隧道。
  2. 建议:照原版 whitelist.json 的原理给 yggdrasil 增加 allow 列表(按 UUID 匹配),拒绝时用和原版白名单完全相同的 reason:multiplayer.disconnect.not_whitelisted。
  3. 附带修一个安全 footgun:从 legacy 模式迁移到 Yggdrasil 的用户会以为 profiles 仍然是白名单,实际上两端都静默忽略它。建议在配置构建期给出警告。

背景:XMC 的「踢出」是什么

XMC 自己是「假装成在线模式 Minecraft 服务器」的 TCP finalmask,所以「踢出」只有一个实现:在 login 阶段写一个 clientboundLoginDisconnect 包(reason 是 JSON 文本组件),然后关连接。入口是 writeDisconnectPacket()(transport/internet/finalmask/xmc/protocol.go:469),触发点在 server.go,客户端侧只是把 reason 原样塞进 error(client.go:241-249、packet_stream.go:243-246)。

进入 configuration(隧道)之后服务端不再主动踢人;畸形包、padding 校验失败等路径直接 close,不发 disconnect。

现状:6 个踢出点
# 触发条件 位置 当前 reason 组件类型
1 握手 nextState=3(TRANSFER) server.go:162 multiplayer.disconnect.transfers_disabled translate
2 协议号不在 767–777 表内 server.go:175 + protocol_table.go:201 outdated_client(<754)/ incompatible,with:["26.3"] translate
3 Yggdrasil:10 s 内 hasJoined 查不到 server.go:296 multiplayer.disconnect.unverified_username translate
4 Yggdrasil:API 故障 / UUID 或名字不匹配 server.go:298 multiplayer.disconnect.authservers_down translate
5 legacy:预共享密码错误 server.go:310 multiplayer.disconnect.authservers_down translate
6 legacy:密码正确但 profile 不在 profiles 里 server.go:314 {"text":"You are not white-listed on this server!"} text(硬编码)

提案 A:所有踢出信息改用原版翻译键

A.1 原版 26.3 login / configuration 阶段会发的所有踢出理由

(来源:官方 26.3 server jar 反编译 + minecraft-data 的 language.json 交叉核对)

阶段 原版 reason 参数 原版出处
handshake multiplayer.disconnect.transfers_disabled — ServerHandshakePacketListenerImpl.handleIntention TRANSFER 分支
handshake multiplayer.disconnect.outdated_client 版本名 beginLogin,protocolVersion < 754
handshake multiplayer.disconnect.incompatible 版本名 beginLogin,其余版本
login multiplayer.disconnect.unverified_username — ServerLoginPacketListenerImpl,hasJoined 返回空
login multiplayer.disconnect.authservers_down — 同上,AuthenticationUnavailableException
login multiplayer.disconnect.slow_login — 同上,if (this.tick++ == 600)(≈30 s)
login multiplayer.disconnect.banned.reason (+.expiration) 理由/时间 PlayerList.canPlayerLogin
login multiplayer.disconnect.not_whitelisted — PlayerList.canPlayerLogin
login multiplayer.disconnect.banned_ip.reason (+.expiration) 理由/时间 PlayerList.canPlayerLogin
login multiplayer.disconnect.server_full — PlayerList.canPlayerLogin
login multiplayer.disconnect.duplicate_login — PlayerList.disconnectAllPlayersWithProfile
config multiplayer.disconnect.unexpected_query_response — ServerCommonPacketListenerImpl(DISCONNECT_UNEXPECTED_QUERY)
config multiplayer.disconnect.invalid_player_data — ServerConfigurationPacketListenerImpl(放置玩家失败)
config multiplayer.disconnect.configuration_error — 同上(配置任务异常)
config multiplayer.disconnect.duplicate_login — 同上(世界里已有同 UUID 玩家)
any disconnect.timeout — Connection.exceptionCaught / keep-alive 超时
any disconnect.genericReason "Internal Exception: " + cause Connection.exceptionCaught(解码/IO 异常)
any multiplayer.disconnect.server_shutdown — Connection.channelRead0(RejectedExecutionException)
any multiplayer.disconnect.invalid_packet — 仅 ClassCastException 路径
在线踢 multiplayer.disconnect.not_whitelisted — MinecraftServer.kickUnlistedPlayers(/whitelist on 后复查在线玩家)
Play multiplayer.disconnect.kicked — /kick 未给理由时

要点:原版在 login / configuration 阶段只用 translate 组件;唯一可能出现 literal 顶层组件的是 Play 阶段的 /kick <player> <reason>:自定义理由经 MessageArgument.getMessage 解析后原样发给客户端,那是玩家自己填的自由文本,不是我们要模仿的部分。

另外三个「看着像踢出、其实不能拿来做踢出文案」的键:

  • multiplayer.disconnect.generic:只作为服务端 handleDisconnection 记录日志时的兜底(Component.translatable("multiplayer.disconnect.generic")),不会发给客户端;
  • disconnect.endOfStream:Connection.channelInactive 里连接被动断开时记录的本地 reason,只进 onDisconnect/日志,不上线;
  • disconnect.loginFailedInfo.*:客户端自己 /join 失败时在本地展示的文案,不是服务端踢出。

(顺带一个容易忽略的实现细节:26.3 的 Connection.disconnect(reason) 只关 channel、不发包,真正的「踢出」都是调用方先 send(new ClientboundLoginDisconnectPacket(reason)) 再断开。)

A.2 建议改动
# 改动 理由
A-1 踢出点 6:{"text":"You are not white-listed on this server!"} → {"translate":"multiplayer.disconnect.not_whitelisted"} 原版就是发这个 translate 键;显示文本一致,但会随客户端语言变化
A-2 新增:Yggdrasil allow 列表拒绝 → multiplayer.disconnect.not_whitelisted 见提案 B;语义与原版白名单完全一致
A-3 踢出点 4 拆分:hasJoined 成功但 UUID/名字不匹配 → unverified_username;仅 API/传输错误保留 authservers_down 现在的实现把「验证失败」和「认证服务器挂了」混在一起,客户端看到的提示会误导;原版对「验证不上」发 unverified_username
A-4 踢出点 5(legacy 密码错误)→ 建议 unverified_username(待议) legacy 模式没有原版对应物;unverified_username 是「这台机器无法验证你」的最接近表达,且和 vanilla「session 校验失败」的出口一致。现状 authservers_down 会让玩家以为认证服务器宕机
A-5 待议:协议错误 / 畸形包是否要发 disconnect 现状静默 close;原版在 Connection.exceptionCaught 里会发 disconnect.genericReason(参数是 "Internal Exception: " + Java 异常)。Go 写不出可信的 Java 异常串,照抄反而是指纹,见 A.4

A-1 / A-2 我建议无条件做;A-3 / A-4 / A-5 需要维护者拍板。

A.3 为什么必须用翻译键(而不是 {"text": ...})
  1. 原版没有 text 组件踢出:login/config 阶段全部是 Component.translatable(...)。一个能读 raw packet 的客户端/插件(很多反作弊、客户端 mod、抓包对照)能直接看出组件类型不同。

  2. 本地化差异是玩家可见的:同一个客户端,其它 5 个踢出都是中文,白名单踢出却是英文——这就是「一眼假」。

    实测 zh_cn.json(1.21.1 / 26.1 / 26.3 三个版本):

    客户端语言 当前 {"text": ...} 改成 {"translate":"multiplayer.disconnect.not_whitelisted"}
    en_US You are not white-listed on this server! You are not white-listed on this server!
    zh_CN You are not white-listed on this server!(英文原样) 你不在此服务器的白名单中!

    同理 transfers_disabled 的英文文案在 1.21.1 和 26.1 之间也改过(Server does not accept transfers → This server does not accept transfers),中文翻译同步从「服务器不接受转移」变成「此服务器不接受转移」——翻译键自动跟着客户端版本走,硬编码不会。

  3. 维护性:现在 6 个 reason 里 5 个是字面量散落在 server.go,第 6 个是硬编码文案。建议顺手收拢成常量(见 A.5),避免以后再加一个踢出点时又写错形式。

A.4 「不能用翻译」的例外(结论:都不影响本次改动)
例外 能不能用翻译键 处理建议
with 参数的值(版本名 26.3) 参数值是数据,不是文案,本身不需要翻译 保持现状
disconnect.genericReason 的参数 键本身是 translate("%s"),但参数是 Java 异常字符串 若要模仿,只能发 {"translate":"disconnect.genericReason","with":["Internal Exception: java.lang.IllegalStateException: Protocol error"]} 这类「像但不对」的串;Go 侧无法生成真实异常类名,建议不做,维持静默 close(协议错误本来就是探针行为,静默断开更像被防火墙丢弃)
multiplayer.disconnect.generic 键存在,但原版只用于日志、不发给客户端 不使用
自定义踢出理由(/kick <reason>) 原版在这里用 literal,因为理由是自由文本 不涉及(XMC 不模拟 Play 阶段)

也就是说:本次想改的所有踢出点都有原版翻译键可用,没有一处「必须写死文本」。

A.5 建议的代码形状(可选的小重构)
// transport/internet/finalmask/xmc/kick.go(新文件;把散落的 reason 收进来)
const (
    disconnectTransfersDisabled = `{"translate":"multiplayer.disconnect.transfers_disabled"}`
    disconnectUnverified        = `{"translate":"multiplayer.disconnect.unverified_username"}`
    disconnectAuthServersDown   = `{"translate":"multiplayer.disconnect.authservers_down"}`
    disconnectNotWhitelisted    = `{"translate":"multiplayer.disconnect.not_whitelisted"}`
)

配合一个 func (c *serverConn) kickLogin(reason string) error 统一「写包 + 返回错误」,避免各处 _ = 与错误处理不一致(现在只有 Yggdrasil 那处检查写错误)。


提案 B:Yggdrasil 模式补 UUID 白名单

B.1 现状:Yggdrasil 模式下没有任何白名单
// server.go:215
profile, found := findProfile(c.profiles, string(username), uuid)   // ← 只在 legacy 分支被使用

// server.go:286
if c.yggdrasil != nil {
    ...
    profile, err = c.verifyYggdrasilLogin(string(username), uuid, serverID)  // ← 覆盖 profile,found 再没被读过
} else {
    ...
    if !found { /* 唯一的白名单检查,legacy 专属 */ }
}

verifyYggdrasilLogin 只做三件事:10 s 内轮询 hasJoined、UUID 必须等于 Login Start 声明的 UUID、名字必须一致。

结论:任何能在该 Yggdrasil API 认证成功的账号都能进。对 Blessing Skin 这类可自建/可开放注册的 API,等于「开放注册 = 开放隧道」。配置里写了 profiles 也不会生效(WrapConnServer 允许 profiles 为空,且 Yggdrasil 分支不读 found)。

B.2 原版白名单机制(26.3 实测,作为设计参照)
// PlayerList.canPlayerLogin —— 顺序:封禁 → 白名单 → IP 封禁 → 满员
} else if (!this.isWhiteListed(nameAndId)) {
    return Component.translatable("multiplayer.disconnect.not_whitelisted");

// PlayerList.isWhiteListed
return !this.isUsingWhitelist() || this.ops.contains(nameAndId) || this.whitelist.contains(nameAndId);

// UserWhiteList:whitelist.json 的每一条是 {uuid, name},匹配键是 UUID
protected String getKeyForUser(final NameAndId user) { return user.id().toString(); }

// ServerLoginPacketListenerImpl.verifyLoginAndFinishConnectionSetup
Component error = playerList.canPlayerLogin(this.connection.getRemoteAddress(), new NameAndId(profile));
if (error != null) this.disconnect(error);
...
this.finishLoginAndWaitForClient(profile);   // 只有通过 canPlayerLogin 才会写 Login Finished

拆解成可抄的四条:

  1. 位置:session 验证(hasJoined)之后、Login Finished 之前——所以不在白名单的人无法试探「这个服开了白名单没有」,必须先过认证;
  2. 匹配键:UUID(NameAndId.id()),name 只用于展示/日志(26.3 的 ops/bans 也统一改成按 UUID 存);
  3. 开关语义:white-list=false → 全部放行;white-list=true + 空列表 → 谁都不放行;
  4. 踢出文案:multiplayer.disconnect.not_whitelisted,无参数;/whitelist on 后复查在线玩家(kickUnlistedPlayers)用的也是同一个键。
B.3 建议设计
配置形态(二选一,需要定)

方案 A(推荐,最简):UUID 字符串数组

(以下只是 yggdrasil 这一块,实际位于 finalmask TCP 的 settings 下。)

{
  "yggdrasil": {
    "api": "https://skin.example.com/api/yggdrasil",
    "allow": [
      "0123456789abcdef0123456789abcdef",
      "fedcba98-7654-3210-fedc-ba9876543210"
    ]
  }
}

方案 B(与 whitelist.json 同构):{uuid, name} 对象数组

{
  "yggdrasil": {
    "api": "https://skin.example.com/api/yggdrasil",
    "allow": [
      { "uuid": "01234567-89ab-cdef-0123-456789abcdef", "name": "TestUser" }
    ]
  }
}

方案 B 可以直接从原版 whitelist.json 抄过来,name 只用于日志/可读性;代价是 protobuf 多一个 message。方案 A 更符合 Xray 现有配置风格(profiles 之外的列表都是标量数组),推荐先做 A,将来需要再加可选的 name。

语义(二选一,需要定)
方案 语义 优点 缺点
S1(推荐) allow 缺省或为空 → 不启用过滤;非空 → 严格白名单 简单、向后兼容、不引入开关字段、proto3 repeated 天然表达 无法表达「启用白名单但当前一个人都不许进」(原版的空列表语义)
S2 缺省 → 不过滤;显式 [] → 启用但空列表 = 全部拒绝(对齐原版 white-list=true) 与原版语义 1:1 JSON 层能区分 nil/empty,但 proto3 的 repeated 不行,需要在 proto 里额外加一个 bool(参考现有的 no_padding,就是为了表达「显式空数组」才加的)
匹配细节
  • 配置解析时用与 XMCProfile.Build 相同的 googleuuid.Parse 归一化为 16 字节,内部按 [16]byte(现有 UUID 类型)比较;
  • 接受带连字符 / 不带连字符 / 大写;重复项去重;非法 UUID 在配置构建期报错;
  • hasJoined 返回的 ID 是不带连字符的 32 hex,用现有 normalizeMinecraftUUID 处理后再比较,不要比字符串。
插入位置

server.go 的 Yggdrasil 分支里,verifyYggdrasilLogin 成功之后、writeLoginFinished 之前:

profile, err = c.verifyYggdrasilLogin(string(username), uuid, serverID)
if err != nil { /* 现有逻辑 */ }

// 对应原版 PlayerList.canPlayerLogin:会话已验证,再查白名单
if !c.allowsYggdrasilProfile(profile.UUID) {
    _ = writeDisconnectPacket(c.writer, c.protocol.login.clientboundLoginDisconnect, disconnectNotWhitelisted)
    return fmt.Errorf("player %s (%s) is not in the yggdrasil allow list", profile.Username, profile.UUID)
}

日志建议:服务端 info/warning 记录「玩家名 + UUID + not in allow list」,与原版踢出时打日志的行为一致(原版 PlayerList 侧也有日志),便于用户排查。

与 profiles 的关系(重要 footgun)

现状:

  • yggdrasil + profiles 同时配置时,两端都静默忽略 profiles(客户端用 Yggdrasil 账号,服务端只看 hasJoined);
  • 从 legacy 迁移过来的人很容易以为 profiles 还在当白名单用——实际等于全开。

建议:配置构建期在 yggdrasil != nil && len(profiles) > 0 时打一条 warning(和现在「password 在 Yggdrasil 模式下被忽略」的 warning 同一个风格,infra/conf/transport_finalmask.go 里已有先例),并在文档/注释里写明 profiles 是 legacy 专用。

不做 op 豁免

原版 isWhiteListed 里 ops.contains(...) 让 OP 绕过白名单。XMC 没有在线的权限系统,不做;如果将来需要「管理员豁免」,可以再加一个 bypass 列表,但不在这个提案里。

B.4 测试计划

go test ./transport/internet/finalmask/xmc/ ./infra/conf/

  1. reasons 钉死:一张表把 6 个 reason 的字面量全部断言,防止以后又漂回 text 组件;顺带断言每个 key 在 minecraft-data 的语言表里存在(可做成离线表对比,或只在注释里标版本);
  2. legacy 白名单踢出:未知 profile → 收到 {"translate":"multiplayer.disconnect.not_whitelisted"},且 Login Finished 不出现;
  3. Yggdrasil 白名单:复用 yggdrasil_test.go 的 newFakeYggdrasilServer,让 hasJoined 返回一个不在 allow 的玩家 → 期望上面那条 disconnect、无 Login Finished;命中则正常跑通;
  4. UUID 归一化:allow 里写带连字符/UUID 大小写/32 hex,hasJoined 返回不带连字符,均能命中;
  5. 配置:allow 合法/非法/重复项;S1/S2 语义(若选 S2,还要测 JSON 缺省 vs []);
  6. 配置警告:yggdrasil + profiles 同时配置时产生 warning(看现有 warning 的测试方式);
  7. (若做 A-3/A-4)增加「UUID 不匹配」「密码错误」两条 case,分别断言 unverified_username。
B.5 兼容性
  • 线上协议:不新增/不改变任何包布局,只有踢出点 6 的组件类型变化(text → translate);
  • 配置:yggdrasil.allow 是新增字段(Yggdrasil message 的 5 号),旧配置缺省 = 不过滤,行为不变;
  • 配对:新老 peer 互配不受影响;
  • 如果最终选 S2,需要额外一个 bool 字段,且「显式空数组」的语义是行为变化(旧配置里没人会写空数组,实际影响为零)。

待讨论的问题

  1. A-1 文字改动:{"text": ...} → {"translate":"multiplayer.disconnect.not_whitelisted"} 是否同意?(我建议直接做)
  2. A-3/A-4:authservers_down 是否应该拆分/替换成 unverified_username?还是保持「所有验证失败都不可区分」的现状?
  3. A-5:协议错误要不要发 disconnect.genericReason?(我倾向于保持静默 close:Go 生成不了可信的 Java 异常串)
  4. B-1 配置形态:allow 用 UUID 字符串数组(A)还是 {uuid, name} 对象(B)?
  5. B-2 语义:S1(空 = 不过滤)还是 S2(空 = 拒绝所有人,对齐原版)?
  6. B-3:要不要顺带做 yggdrasil + profiles 的配置期警告?
  7. 附带:duplicate_login 要不要做?原版 PlayerList 会踢掉同 UUID 的旧连接(You logged in from another location)。XMC 目前没有任何玩家注册表;如果白名单模式下同一账号被两个人共用,原版行为是后来的踢掉先来的。这可以作为后续独立提案。
  8. 附带:客户端 /join 时序。原版客户端是先 /join 再发 Encryption Response(ClientHandshakePacketListenerImpl.authenticateServer 在 setEncryption 之前),所以服务端 hasJoined 永远不会「还没注册」;XMC 客户端是先发 Encryption Response 再 /join,这正是服务端要轮询 10 s 的原因。如果客户端改成原版顺序,服务端可以只查一次 hasJoined(少一个 10 s 窗口、少一类可观测的重复轮询),这算另一个独立优化。

涉及文件

  • transport/internet/finalmask/xmc/server.go(踢出点、Yggdrasil 分支、白名单检查)
  • transport/internet/finalmask/xmc/protocol.go(writeDisconnectPacket)
  • transport/internet/finalmask/xmc/config.proto / config.pb.go(Yggdrasil.allow)
  • transport/internet/finalmask/xmc/yggdrasil.go(yggdrasilVerifier、UUID 归一化)
  • infra/conf/transport_finalmask.go(XMCYggdrasil 反序列化 + 配置警告)
  • 测试:transport/internet/finalmask/xmc/yggdrasil_test.go、login_flow_test.go、infra/conf/transport_finalmask_xmc_test.go

参考

  • Minecraft 26.3 官方 jar 反编译:ServerHandshakePacketListenerImpl、ServerLoginPacketListenerImpl、PlayerList、UserWhiteList、NameAndId、ServerCommonPacketListenerImpl、ServerConfigurationPacketListenerImpl、Connection、MinecraftServer、ClientHandshakePacketListenerImpl
  • 文案表:minecraft-data/data/pc/<version>/language.json(767–775),官方 zh_cn.json(1.21.1 / 26.1 / 26.3)
  • 现有实现:35387572(XMC 初始)、6ab123bf(引入那句硬编码文案)、5225121a(Yggdrasil 登录)、84c2b8a0(强制在线模式登录)、536a075f(同账号登录串行化)

XMC finalmask: move every disconnect reason onto vanilla translation keys, and add a UUID allow list for Yggdrasil mode

English version

Type: discussion / proposal (agree on the direction first)
Base: feat/xmc-config-clients-servers @ 536a075f
Related commits: 35387572 (#6210, XMC introduced), 6ab123bf (#6487, where the hardcoded string came from), 5225121a (#7416, Yggdrasil), 84c2b8a0 / 50ac1fe5 / 536a075f (login flow and per-account login serialisation)

TL;DR

Two proposals. Both aim at "the login phase is indistinguishable from a vanilla 26.3 server", and one of them also closes a real security gap.

A. Disconnect reasons (the reason of Login Disconnect)

  1. The module has six kick sites. Five already send {"translate": ...}; only the legacy-password-mode whitelist rejection sends {"text":"You are not white-listed on this server!"}. Vanilla never sends a literal component during login or configuration, so it must become multiplayer.disconnect.not_whitelisted — the displayed text is identical, but it is localised by the client (zh_CN → 你不在此服务器的白名单中!).
  2. I checked all six against the decompiled 26.3 server: three already match, site 4 needs splitting, sites 5 and 6 should change, and one class ("silent close") needs a decision.

B. Yggdrasil mode has no UUID allow list

  1. Today the Yggdrasil path only verifies through hasJoined (plus a UUID/name consistency check). The configured profiles never take part. Any account that can authenticate against that API and /join the session gets a tunnel.
  2. Proposal: add an allow list under yggdrasil, following the principle of vanilla's whitelist.json (matched by UUID), and reject with exactly the vanilla whitelist reason: multiplayer.disconnect.not_whitelisted.
  3. Fix a related footgun: users migrating from legacy mode keep their profiles list and assume it still gates access — it does not, on either end. The config build step should warn.

Background: what "kick" means in XMC

XMC is a TCP finalmask that pretends to be an online-mode Minecraft server, so there is exactly one kick implementation: write clientboundLoginDisconnect (reason = a JSON text component) during login, then close. The entry point is writeDisconnectPacket() (transport/internet/finalmask/xmc/protocol.go:469), the call sites live in server.go, and the client side just turns the reason into an error (client.go:241-249, packet_stream.go:243-246).

After the configuration state starts (the tunnel), the server never kicks; malformed packets and failed padding checks close the connection without a disconnect.

Current kick sites
# Trigger Location Current reason Component
1 handshake nextState=3 (TRANSFER) server.go:162 multiplayer.disconnect.transfers_disabled translate
2 protocol number outside 767–777 server.go:175 + protocol_table.go:201 outdated_client (<754) / incompatible, with:["26.3"] translate
3 Yggdrasil: hasJoined never answers within 10 s server.go:296 multiplayer.disconnect.unverified_username translate
4 Yggdrasil: API failure / UUID or name mismatch server.go:298 multiplayer.disconnect.authservers_down translate
5 legacy: wrong pre-shared password server.go:310 multiplayer.disconnect.authservers_down translate
6 legacy: password correct, profile not in profiles server.go:314 {"text":"You are not white-listed on this server!"} text (hardcoded)

Proposal A: every disconnect reason becomes a vanilla translation key

A.1 Every reason vanilla 26.3 sends during login / configuration

(Decompiled official 26.3 server jar, cross-checked against minecraft-data's language.json.)

Phase Vanilla reason Args Vanilla source
handshake multiplayer.disconnect.transfers_disabled — ServerHandshakePacketListenerImpl.handleIntention, TRANSFER
handshake multiplayer.disconnect.outdated_client version name beginLogin, protocolVersion < 754
handshake multiplayer.disconnect.incompatible version name beginLogin, everything else
login multiplayer.disconnect.unverified_username — ServerLoginPacketListenerImpl, hasJoined returned nothing
login multiplayer.disconnect.authservers_down — same, AuthenticationUnavailableException
login multiplayer.disconnect.slow_login — same, if (this.tick++ == 600) (≈30 s)
login multiplayer.disconnect.banned.reason (+.expiration) reason/date PlayerList.canPlayerLogin
login multiplayer.disconnect.not_whitelisted — PlayerList.canPlayerLogin
login multiplayer.disconnect.banned_ip.reason (+.expiration) reason/date PlayerList.canPlayerLogin
login multiplayer.disconnect.server_full — PlayerList.canPlayerLogin
login multiplayer.disconnect.duplicate_login — PlayerList.disconnectAllPlayersWithProfile
config multiplayer.disconnect.unexpected_query_response — ServerCommonPacketListenerImpl (DISCONNECT_UNEXPECTED_QUERY)
config multiplayer.disconnect.invalid_player_data — ServerConfigurationPacketListenerImpl (spawn failure)
config multiplayer.disconnect.configuration_error — same (configuration task fault)
config multiplayer.disconnect.duplicate_login — same (same UUID already in the world)
any disconnect.timeout — Connection.exceptionCaught / keep-alive timeout
any disconnect.genericReason "Internal Exception: " + cause Connection.exceptionCaught (decode/IO fault)
any multiplayer.disconnect.server_shutdown — Connection.channelRead0 (RejectedExecutionException)
any multiplayer.disconnect.invalid_packet — ClassCastException path only
online multiplayer.disconnect.not_whitelisted — MinecraftServer.kickUnlistedPlayers (after /whitelist on)
Play multiplayer.disconnect.kicked — /kick without a reason

Key point: vanilla only uses translatable components during login and configuration. The only place a literal top-level component can appear is the free-form reason of /kick <player> <reason> in the Play state, which the command parses with MessageArgument.getMessage and sends as-is; that is user input, not something to imitate.

Three keys that look like kicks but must not be used as one:

  • multiplayer.disconnect.generic is only the fallback used when the server logs a disconnection without a recorded reason (Component.translatable("multiplayer.disconnect.generic") in handleDisconnection); it is never sent to the client;
  • disconnect.endOfStream is the local reason recorded by Connection.channelInactive when the channel dies on its own; it goes into onDisconnect/logs and never on the wire;
  • disconnect.loginFailedInfo.* are displayed by the client when its own /join fails; they are not server kicks.

(One implementation detail worth noting: 26.3's Connection.disconnect(reason) only closes the channel and sends nothing — every real kick first calls send(new ClientboundLoginDisconnectPacket(reason)) and then disconnects.)

A.2 Proposed changes
# Change Why
A-1 Kick site 6: {"text":"You are not white-listed on this server!"} → {"translate":"multiplayer.disconnect.not_whitelisted"} This is what vanilla sends; identical text, but localised by the client
A-2 New: Yggdrasil allow list rejection → multiplayer.disconnect.not_whitelisted See proposal B; semantically identical to the vanilla whitelist
A-3 Split kick site 4: hasJoined succeeded but UUID/name mismatch → unverified_username; keep authservers_down for real API/transport failures Today the two are conflated and the client shows a misleading "auth servers are down"; vanilla's failure exit is unverified_username
A-4 Kick site 5 (legacy wrong password) → unverified_username (to be decided) Legacy mode has no vanilla equivalent; unverified_username is the closest "this server could not verify you" and matches vanilla's session-check failure exit. The current authservers_down tells the player the auth servers are down, which is a lie
A-5 To be decided: should protocol faults send a disconnect at all? Today the connection is closed silently; vanilla's Connection.exceptionCaught sends disconnect.genericReason with "Internal Exception: " + <Java exception>. Go cannot produce a believable Java exception string, so copying it is itself a fingerprint, see A.4

A-1 and A-2 I would do unconditionally; A-3 / A-4 / A-5 need a maintainer decision.

A.3 Why translation keys are mandatory
  1. Vanilla has no literal-component kicks. Everything in login/configuration is Component.translatable(...). A client, a mod or a plugin that can read raw packets sees the component type differ.

  2. The localisation difference is user-visible. On the same client, the other five kicks are translated and the whitelist kick is English — that is an obvious tell.

    Measured against zh_cn.json (1.21.1 / 26.1 / 26.3):

    Client language Current {"text": ...} With {"translate":"multiplayer.disconnect.not_whitelisted"}
    en_US You are not white-listed on this server! You are not white-listed on this server!
    zh_CN You are not white-listed on this server! (English as-is) 你不在此服务器的白名单中!

    The same argument applies to every other reason: even the English text upstream changes between releases (transfers_disabled went from Server does not accept transfers in 1.21.1 to This server does not accept transfers in 26.1), the zh_CN wording changed with it (服务器不接受转移 → 此服务器不接受转移), and a translation key follows the client for free while a hardcoded string cannot.

  3. Maintenance: five of the six reasons are literals scattered through server.go and the sixth is hardcoded prose. Collecting them into one place (A.5) prevents the next kick site from picking the wrong form again.

A.4 The "cannot be translated" exceptions (none of them blocks this change)
Exception Can a translation key be used? Handling
The with argument values (version name 26.3) The value is data, not prose Leave as-is
The argument of disconnect.genericReason The key is translatable ("%s"), but the argument is a Java exception string Copying means sending something like {"translate":"disconnect.genericReason","with":["Internal Exception: java.lang.IllegalStateException: Protocol error"]} — plausible-looking but not real, and Go cannot name a real Java exception class. Recommend not doing it; keep the silent close (protocol faults are probe traffic anyway, and a silent close looks more like a firewall drop)
multiplayer.disconnect.generic The key exists, but vanilla uses it for logging only, never on the wire Do not use
Custom kick reasons (/kick <reason>) Vanilla uses a literal here because the reason is free text Not applicable (XMC does not emulate the Play state)

In other words: every kick site we want to change has a vanilla translation key; not one of them requires hardcoded text.

A.5 Suggested shape (small optional refactor)
// transport/internet/finalmask/xmc/kick.go (new; collects the scattered reasons)
const (
    disconnectTransfersDisabled = `{"translate":"multiplayer.disconnect.transfers_disabled"}`
    disconnectUnverified        = `{"translate":"multiplayer.disconnect.unverified_username"}`
    disconnectAuthServersDown   = `{"translate":"multiplayer.disconnect.authservers_down"}`
    disconnectNotWhitelisted    = `{"translate":"multiplayer.disconnect.not_whitelisted"}`
)

With a func (c *serverConn) kickLogin(reason string) error that writes the packet and returns the error, so write-error handling stops differing between sites (today only the Yggdrasil site checks it).

Proposal B: a UUID allow list for Yggdrasil mode

B.1 Today there is none
// server.go:215
profile, found := findProfile(c.profiles, string(username), uuid)   // only read by the legacy branch

// server.go:286
if c.yggdrasil != nil {
    ...
    profile, err = c.verifyYggdrasilLogin(string(username), uuid, serverID)  // overwrites profile; found is never read again
} else {
    ...
    if !found { /* the only allow-list check, legacy only */ }
}

verifyYggdrasilLogin only does three things: poll hasJoined for 10 s, require the returned UUID to equal the one from Login Start, require the names to match.

So: any account that can authenticate against that Yggdrasil API gets in. For a self-hosted API such as Blessing Skin that allows registration, "open registration" becomes "open tunnel". A configured profiles list has no effect either (WrapConnServer permits an empty profiles, and the Yggdrasil branch never reads found).

B.2 How vanilla does it (26.3, for reference)
// PlayerList.canPlayerLogin — order: ban → whitelist → IP ban → full
} else if (!this.isWhiteListed(nameAndId)) {
    return Component.translatable("multiplayer.disconnect.not_whitelisted");

// PlayerList.isWhiteListed
return !this.isUsingWhitelist() || this.ops.contains(nameAndId) || this.whitelist.contains(nameAndId);

// UserWhiteList: whitelist.json entries are {uuid, name}, the matching key is the UUID
protected String getKeyForUser(final NameAndId user) { return user.id().toString(); }

// ServerLoginPacketListenerImpl.verifyLoginAndFinishConnectionSetup
Component error = playerList.canPlayerLogin(this.connection.getRemoteAddress(), new NameAndId(profile));
if (error != null) this.disconnect(error);
...
this.finishLoginAndWaitForClient(profile);   // Login Finished is only written after canPlayerLogin passes

Four things worth copying:

  1. Position: after session verification (hasJoined) and before Login Finished, so an unauthenticated peer cannot probe whether a whitelist exists;
  2. Matching key: the UUID (NameAndId.id()); the name is display/log only (26.3 keyed ops and bans by UUID as well);
  3. Switch semantics: white-list=false → everyone; white-list=true with an empty list → nobody;
  4. Reason: multiplayer.disconnect.not_whitelisted, no arguments; /whitelist on re-checks online players (kickUnlistedPlayers) with the same key.
B.3 Proposed design
Config shape (pick one)

Option A (recommended, simplest): array of UUID strings

(The snippets below show only the yggdrasil block; it lives under the finalmask TCP settings.)

{
  "yggdrasil": {
    "api": "https://skin.example.com/api/yggdrasil",
    "allow": [
      "0123456789abcdef0123456789abcdef",
      "fedcba98-7654-3210-fedc-ba9876543210"
    ]
  }
}

Option B (same shape as whitelist.json): array of {uuid, name}

{
  "yggdrasil": {
    "api": "https://skin.example.com/api/yggdrasil",
    "allow": [
      { "uuid": "01234567-89ab-cdef-0123-456789abcdef", "name": "TestUser" }
    ]
  }
}

Option B lets people paste a vanilla whitelist.json; the name is log/readability only and costs one protobuf message. Option A matches the existing Xray config style. I would ship A first and add an optional name later.

Semantics (pick one)
Option Meaning Pros Cons
S1 (recommended) allow absent or empty → no filtering; non-empty → strict Simple, backwards compatible, no extra flag, expressible with a proto3 repeated field Cannot express "whitelist enabled but currently empty" (vanilla's empty-list semantics)
S2 absent → no filtering; explicit [] → enabled with an empty list = deny everyone (vanilla's white-list=true semantics) 1:1 with vanilla JSON can distinguish nil from empty, proto3 cannot, so the proto needs an extra bool (the same reason no_padding exists today)
Matching details
  • Parse entries with the same googleuuid.Parse used by XMCProfile.Build and normalise to 16 bytes; compare as [16]byte (the existing UUID type);
  • Accept dashed, dashless and upper-case input; deduplicate; reject invalid UUIDs at config build time;
  • hasJoined returns a dashless 32-hex id: normalise it with the existing normalizeMinecraftUUID and compare values, never strings.
Where to insert

In the Yggdrasil branch of server.go, after verifyYggdrasilLogin and before writeLoginFinished:

profile, err = c.verifyYggdrasilLogin(string(username), uuid, serverID)
if err != nil { /* existing handling */ }

// Mirrors PlayerList.canPlayerLogin: session verified, now check the allow list
if !c.allowsYggdrasilProfile(profile.UUID) {
    _ = writeDisconnectPacket(c.writer, c.protocol.login.clientboundLoginDisconnect, disconnectNotWhitelisted)
    return fmt.Errorf("player %s (%s) is not in the yggdrasil allow list", profile.Username, profile.UUID)
}

Log the player name, UUID and the reason at info/warning, like vanilla does when it rejects someone, so operators can tell a wrong list entry from a broken API.

Relationship with profiles (important footgun)

Today, when both yggdrasil and profiles are configured, both ends silently ignore profiles (the client authenticates through the Yggdrasil account, the server only checks hasJoined). Someone migrating from legacy mode will assume profiles still acts as the allow list and end up fully open.

Suggestion: emit a config-build warning when yggdrasil != nil && len(profiles) > 0, in the same style as the existing "password is ignored in Yggdrasil mode" warning in infra/conf/transport_finalmask.go, and document that profiles is legacy-only.

No operator bypass

Vanilla lets ops bypass the whitelist (ops.contains(...)). XMC has no online permission system, so this proposal does not either; an optional bypass list can come later if needed.

B.4 Test plan

go test ./transport/internet/finalmask/xmc/ ./infra/conf/

  1. Pin the reasons: one table asserting all six reason literals, so nobody drifts back to a literal component; optionally assert each key exists in a vendored minecraft-data snapshot;
  2. Legacy allow-list kick: unknown profile → exactly {"translate":"multiplayer.disconnect.not_whitelisted"}, and no Login Finished;
  3. Yggdrasil allow list: reuse newFakeYggdrasilServer with a player outside allow → the disconnect above and no Login Finished; a listed player completes the login;
  4. UUID normalisation: dashed / upper-case / dashless forms in allow all match the dashless id from hasJoined;
  5. Config: valid, invalid and duplicate entries; S1/S2 semantics (if S2, also the absent-vs-[] distinction);
  6. Config warning: yggdrasil + profiles produces the warning (follow the existing warning tests);
  7. (If A-3/A-4 happen) add cases for UUID mismatch and wrong password, asserting unverified_username.
B.5 Compatibility
  • Wire: no packet layout changes; only kick site 6 changes component type (text → translate);
  • Config: yggdrasil.allow is a new field (tag 5 in the Yggdrasil message); absent = no filtering, so old configs behave exactly as before;
  • Peering: old and new peers keep pairing;
  • With S2 an extra bool field is needed, and "explicit empty array" becomes a behaviour change (no existing config can write an empty array, so the practical impact is zero).

Open questions

  1. A-1: do we agree on {"text": ...} → {"translate":"multiplayer.disconnect.not_whitelisted"}? (I would just do it)
  2. A-3/A-4: should authservers_down be split/replaced by unverified_username, or should every verification failure stay indistinguishable as it is today?
  3. A-5: should protocol faults send disconnect.genericReason? (I lean towards keeping the silent close: Go cannot produce a believable Java exception string)
  4. B-1: allow as UUID strings (A) or {uuid, name} objects (B)?
  5. B-2: S1 (empty = no filtering) or S2 (empty = deny everyone, vanilla parity)?
  6. B-3: should the yggdrasil + profiles config warning land with this change?
  7. Related: should we implement duplicate_login? Vanilla's PlayerList kicks the old connection of the same UUID (You logged in from another location). XMC has no player registry; in allow-list mode, if one account is shared by two people, vanilla behaviour is that the newcomer kicks the incumbent. Could be a separate proposal.
  8. Related: client /join ordering. The vanilla client calls /join before sending the Encryption Response (ClientHandshakePacketListenerImpl.authenticateServer runs before setEncryption), so the server's hasJoined can never race. The XMC client writes the Encryption Response first and joins afterwards, which is exactly why the server has to poll for up to 10 s. Aligning the client with vanilla would let the server do a single hasJoined (one 10 s window and one observable polling pattern removed) — a separate optimisation.

Files

  • transport/internet/finalmask/xmc/server.go (kick sites, Yggdrasil branch, allow-list check)
  • transport/internet/finalmask/xmc/protocol.go (writeDisconnectPacket)
  • transport/internet/finalmask/xmc/config.proto / config.pb.go (Yggdrasil.allow)
  • transport/internet/finalmask/xmc/yggdrasil.go (yggdrasilVerifier, UUID normalisation)
  • infra/conf/transport_finalmask.go (XMCYggdrasil unmarshalling, config warning)
  • Tests: transport/internet/finalmask/xmc/yggdrasil_test.go, login_flow_test.go, infra/conf/transport_finalmask_xmc_test.go

References

  • Decompiled 26.3 jar: ServerHandshakePacketListenerImpl, ServerLoginPacketListenerImpl, PlayerList, UserWhiteList, NameAndId, ServerCommonPacketListenerImpl, ServerConfigurationPacketListenerImpl, Connection, MinecraftServer, ClientHandshakePacketListenerImpl
  • Strings: minecraft-data/data/pc/<version>/language.json (767–775) and the official zh_cn.json (1.21.1 / 26.1 / 26.3)
  • History: 35387572 (XMC introduced), 6ab123bf (the hardcoded string), 5225121a (Yggdrasil login), 84c2b8a0 (require the online-mode login), 536a075f (per-account login serialisation)
Dominant language
Go
Stars
43.3k
Forks
6.2k
Avg merge
2d 11h
Merged PRs (30d)
55

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from XTLS/Xray-core

All issues in XTLS/Xray-core

Similar issues

More Go issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.