[PR #5149] [MERGED] Chat from other players is validated as vanilla's client does (handleChatMessageError) #6104

Closed
opened 2026-11-03 06:11:41 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/5149
Author: @xFedeT
Created: 10/31/2026
Status: ✅ Merged
Merged: 10/31/2026
Merged by: @ludovic111

Base: main ← Head: fix/chat-validation-error


📝 Commits (3)

  • 7cec464 Chat from other players is validated as vanilla's client does
  • 0a6ecf0 Merge remote-tracking branch 'origin/main' into fix/chat-validation-error
  • 5963751 Merge origin/main: keep both the services-key and own-profile enums in remote.rs

📊 Changes

6 files changed (+487 additions, -10 deletions)

View changed files

📝 crates/horizon-client-render/src/chat.rs (+8 -0)
📝 crates/horizon-client/src/game/remote.rs (+176 -1)
📝 crates/horizon-protocol/src/secure_chat.rs (+294 -0)
📝 tools/port_map/client-002.tsv (+2 -2)
📝 tools/port_map/client-003.tsv (+1 -1)
📝 tools/port_map/rest-011.tsv (+6 -6)

📄 Description

🤖 Opened by xFedeT's AI agent (Claude Code, Claude Sonnet 5.5), not by xFedeT personally.

Refs #3518 (row ChatListener.handleChatMessageError, with ClientPacketListener.initializeChatSession, handlePlayerChat's checks and the KeyBased validator they need).

What and why

A chat packet from another player was shown as it came: no check of the global chat index, of the sender, or of the signature. Vanilla's client (ClientPacketListener.handlePlayerChat) does three things first, and Horizon did none of them:

  1. The global index. Every chat packet carries one; nextChatIndex counts them, and a mismatch disconnects with multiplayer.disconnect.bad_chat_index.
  2. The sender. A player with no list entry is ChatListener.handleChatMessageError.
  3. The sender's SignedMessageValidator (PlayerInfo.messageValidator). Without a chat session it is fallbackMessageValidator(enforcesSecureChat()): ACCEPT_UNSIGNED (the message shows without its signature, so as "Not Secure") or REJECT_ALL when the server enforces secure chat. With a session the services' profile-key keys vouch for (initializeChatSession), it is KeyBased: the key not expired (plus the 8 hour EXPIRY_GRACE_PERIOD), the signature valid over the message, then the chain (the same message again, or a descendant of the last one); after one failure it accepts nothing more.

A message that fails shows the red, italic chat.validation_error in its chat type, tagged GuiMessageTag.chatError.

The change

  • horizon-protocol/secure_chat.rs: MessageValidator (AcceptUnsigned, RejectAll, KeyBased), Incoming, Validated, EXPIRY_GRACE_PERIOD. The signed payload is the existing signed_payload, and the key check the existing RSA verify; nothing new in the crypto.
  • game/remote.rs: the PlayerChat arm (index, sender, validator), Remote::validate_chat / new_chat_validator (the session each INITIALIZE_CHAT entry carries, kept and checked when the player's chat is first read), handle_chat_message_error, and the services' keys, fetched once per connection on a thread with the fetch_profile_key_keys the dedicated server already uses (canValidateProfileKeys() is false without them, as in vanilla).
  • Tag::chat_error (GuiMessageTag.chatError: 0xFF5555, tooltip chat.tag.error) and ChatTrust::Error.
  • Port map: handlePlayerChat, initializeChatSession, handleChatMessageError and the SignedMessageValidator rows.

Vanilla reference

ClientPacketListener.handlePlayerChat (line 1028), initializeChatSession (2062), PlayerInfo.getMessageValidator / fallbackMessageValidator, RemoteChatSession.createMessageValidator, SignedMessageValidator.KeyBased (validate, validateChain, updateAndValidate), SignedMessageLink.isDescendantOf, PlayerChatMessage.verify / removeSignature, ChatListener.handleChatMessageError, GuiMessageTag.chatError. Read before writing; the order of the checks, the grace period and the record PlayerChatMessage.equals compares for "the same message again" follow them.

How it was checked

  • Unit tests (secure_chat::tests), with SHA256withRSA signatures made outside Rust with a 2048-bit key's private half over the payload layout of PlayerChatMessage.updateSignature: a chain in order passes, the same message again passes, a valid signature out of order ends the chain and nothing is accepted after; a changed content, a missing signature and an expired key (and the grace period, to the millisecond) are refused; the fallback accepts unsigned or rejects all.
  • python3 tools/lan_e2e.py --server-thread --check chat --check styles: the host's and the guest's lines still reach each other, with no error line.
  • pr_ready --quick: fmt, clippy, 2196 tests pass; parity harnesses left to CI.

What it depends on

ChatListener.handleChatMessageError also calls markMessageAsProcessed(signature, false) for the acknowledgement the client sends, which needs a LastSeenMessagesTracker; the client has none yet, and neither does the shown-message path (handlePlayerChatMessage calls it too), so no chat message is acknowledged here today: #4375 to #4377 add the tracker and the signing side. The social checks of the same method (a blocked sender, a friends-only restriction) and the narration are separate systems the game does not have yet.

The error path itself is covered by the validator tests, with signatures made outside Rust; I did not run it against a real server that enforces secure chat.

🤖 Generated with Claude Code


🔄 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/horizon-rust/horizon/pull/5149 **Author:** [@xFedeT](https://github.com/xFedeT) **Created:** 10/31/2026 **Status:** ✅ Merged **Merged:** 10/31/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `fix/chat-validation-error` --- ### 📝 Commits (3) - [`7cec464`](https://github.com/horizon-rust/horizon/commit/7cec464d45de322fafe00b01e1d63523b141b889) Chat from other players is validated as vanilla's client does - [`0a6ecf0`](https://github.com/horizon-rust/horizon/commit/0a6ecf023182ea81605c5e3387070b2b1ee2b717) Merge remote-tracking branch 'origin/main' into fix/chat-validation-error - [`5963751`](https://github.com/horizon-rust/horizon/commit/5963751fe904ac0964f38c411fa93b6ddf8af892) Merge origin/main: keep both the services-key and own-profile enums in remote.rs ### 📊 Changes **6 files changed** (+487 additions, -10 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client-render/src/chat.rs` (+8 -0) 📝 `crates/horizon-client/src/game/remote.rs` (+176 -1) 📝 `crates/horizon-protocol/src/secure_chat.rs` (+294 -0) 📝 `tools/port_map/client-002.tsv` (+2 -2) 📝 `tools/port_map/client-003.tsv` (+1 -1) 📝 `tools/port_map/rest-011.tsv` (+6 -6) </details> ### 📄 Description > 🤖 Opened by xFedeT's AI agent (Claude Code, Claude Sonnet 5.5), not by xFedeT personally. Refs #3518 (row `ChatListener.handleChatMessageError`, with `ClientPacketListener.initializeChatSession`, `handlePlayerChat`'s checks and the `KeyBased` validator they need). ## What and why A chat packet from another player was shown as it came: no check of the global chat index, of the sender, or of the signature. Vanilla's client (`ClientPacketListener.handlePlayerChat`) does three things first, and Horizon did none of them: 1. **The global index.** Every chat packet carries one; `nextChatIndex` counts them, and a mismatch disconnects with `multiplayer.disconnect.bad_chat_index`. 2. **The sender.** A player with no list entry is `ChatListener.handleChatMessageError`. 3. **The sender's `SignedMessageValidator`** (`PlayerInfo.messageValidator`). Without a chat session it is `fallbackMessageValidator(enforcesSecureChat())`: `ACCEPT_UNSIGNED` (the message shows without its signature, so as "Not Secure") or `REJECT_ALL` when the server enforces secure chat. With a session the services' profile-key keys vouch for (`initializeChatSession`), it is `KeyBased`: the key not expired (plus the 8 hour `EXPIRY_GRACE_PERIOD`), the signature valid over the message, then the chain (the same message again, or a descendant of the last one); after one failure it accepts nothing more. A message that fails shows the red, italic `chat.validation_error` in its chat type, tagged `GuiMessageTag.chatError`. ## The change - `horizon-protocol/secure_chat.rs`: `MessageValidator` (`AcceptUnsigned`, `RejectAll`, `KeyBased`), `Incoming`, `Validated`, `EXPIRY_GRACE_PERIOD`. The signed payload is the existing `signed_payload`, and the key check the existing RSA `verify`; nothing new in the crypto. - `game/remote.rs`: the `PlayerChat` arm (index, sender, validator), `Remote::validate_chat` / `new_chat_validator` (the session each INITIALIZE_CHAT entry carries, kept and checked when the player's chat is first read), `handle_chat_message_error`, and the services' keys, fetched once per connection on a thread with the `fetch_profile_key_keys` the dedicated server already uses (`canValidateProfileKeys()` is false without them, as in vanilla). - `Tag::chat_error` (`GuiMessageTag.chatError`: 0xFF5555, tooltip `chat.tag.error`) and `ChatTrust::Error`. - Port map: `handlePlayerChat`, `initializeChatSession`, `handleChatMessageError` and the `SignedMessageValidator` rows. ## Vanilla reference `ClientPacketListener.handlePlayerChat` (line 1028), `initializeChatSession` (2062), `PlayerInfo.getMessageValidator` / `fallbackMessageValidator`, `RemoteChatSession.createMessageValidator`, `SignedMessageValidator.KeyBased` (`validate`, `validateChain`, `updateAndValidate`), `SignedMessageLink.isDescendantOf`, `PlayerChatMessage.verify` / `removeSignature`, `ChatListener.handleChatMessageError`, `GuiMessageTag.chatError`. Read before writing; the order of the checks, the grace period and the record `PlayerChatMessage.equals` compares for "the same message again" follow them. ## How it was checked - Unit tests (`secure_chat::tests`), with SHA256withRSA signatures made outside Rust with a 2048-bit key's private half over the payload layout of `PlayerChatMessage.updateSignature`: a chain in order passes, the same message again passes, a valid signature out of order ends the chain and nothing is accepted after; a changed content, a missing signature and an expired key (and the grace period, to the millisecond) are refused; the fallback accepts unsigned or rejects all. - `python3 tools/lan_e2e.py --server-thread --check chat --check styles`: the host's and the guest's lines still reach each other, with no error line. - `pr_ready --quick`: fmt, clippy, 2196 tests pass; parity harnesses left to CI. ## What it depends on `ChatListener.handleChatMessageError` also calls `markMessageAsProcessed(signature, false)` for the acknowledgement the client sends, which needs a `LastSeenMessagesTracker`; the client has none yet, and neither does the shown-message path (`handlePlayerChatMessage` calls it too), so no chat message is acknowledged here today: #4375 to #4377 add the tracker and the signing side. The social checks of the same method (a blocked sender, a friends-only restriction) and the narration are separate systems the game does not have yet. The error path itself is covered by the validator tests, with signatures made outside Rust; I did not run it against a real server that enforces secure chat. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-03 06:11:41 +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
horizon-rust/horizon#6104
No description provided.