[PR #7823] [MERGED] fix(multiplayer): give each seat a private rejoin key #7949

Closed
opened 2026-10-24 04:09:06 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/7823
Author: @SpicyMarinara
Created: 10/19/2026
Status: ✅ Merged
Merged: 10/19/2026
Merged by: @SpicyMarinara

Base: staging ← Head: fix/harden-multiplayer-rejoin


📝 Commits (1)

  • 2d013d1 fix(multiplayer): give each seat a private rejoin key

📊 Changes

4 files changed (+332 additions, -16 deletions)

View changed files

📝 docs/TROUBLESHOOTING.md (+1 -1)
📝 docs/development/multiplayer.md (+9 -0)
📝 packages/server/src/services/multiplayer/service.ts (+51 -15)
➕ scripts/regressions/multiplayer-seat-key-security.regression.ts (+271 -0)

📄 Description

Important

Contributions target staging. Only SpicyMarinara may promote this repository's staging branch or a same-repository hotfix/* branch to main.
Outside and first-time contributors also require an approving review from SpicyMarinara.

Linked issue

No public issue: this is a hardening follow-up from an internal multiplayer review.

Why this change

  • Returning players were matched to their old seat by display name and persona name. Those names are public within the room, so they are not proof of who holds a seat. A seat carries the player's private whispers, Game sheet and round submissions, so it should only go back to the Engine that held it.

What changed

  • Each guest seat now has a private rejoin key. It is the session token from the admission reply of the join request that first got the seat. The guest Engine remembers it for that room, and when it asks to join the same room again it sends the key as the bearer of the join request.
  • The host keeps only a SHA-256 hash of each seat's key, in memory with the rest of the live room. When the host approves a returning player, the request has to match the names and present that key (checked with timingSafeEqual). Without the key, a request with the same names is refused with the existing name-conflict error, and the real player's sessions are left alone. Kick and Stop drop the seat's key.
  • The key is never sent to other participants, never written to chat metadata, backups or exports, and never logged.
  • The peer protocol does not change. The admission reply already carried a random 32-byte token, and the host listener already accepted an Authorization bearer on every request. Engines from v2.5.0 keep working in both directions:
    • An older guest joining a newer host is admitted as before. It never presents a key, so after leaving it cannot take its old seat back by name. The host can remove the old seat, or the player can choose another persona name.
    • A newer guest joining an older host only sends a bearer that the older host ignores on join, so the old name-based rejoin still applies there.
  • Compatibility rule for seats without a key: every guest seat gets a key when the host first approves it, so a running room has no keyless guest seats (rooms never outlive a host restart). If a seat somehow has no key, nobody can take it by name, and its current session keeps working with its own token. This is the strictest rule that keeps every existing connection working.
  • Behaviour change: the guest keeps its rejoin keys in memory, like every other multiplayer credential. Leave, deleting the joined chat and turning Multiplayer off and on all keep the key. A full guest Engine restart loses it. After a restart, the host has to remove the old seat before that player can use the same persona name again. This is documented in docs/TROUBLESHOOTING.md and docs/development/multiplayer.md.
  • Added the multiplayer-seat-key-security regression. It runs over real TLS between two Engines and covers four cases: a request with copied names and no key is refused and gets no history or whispers; a made-up key is refused; the real player rejoins with the key and gets the same seat and the same whispers; the key and its hash never appear in another player's poll, the host's views or stored chats on either Engine. It fails on staging without this change (Missing expected rejection: copied names do not take Lyra's seat) and passes with it.

Validation

  • pnpm check passes locally
  • Container (Docker / Podman) built and ran without issue
  • Ran the app, clicked through the changes manually
  • Checked edge cases (light + dark mode, mobile viewport, empty states, error paths)
  • Above manual verification completed (describe below)
  • Read and followed CONTRIBUTING.md

Commands run by the agent on this branch:

  • pnpm check: passed (exit 0). ESLint reports one existing react-hooks/exhaustive-deps warning in client code this PR does not touch.
  • pnpm regression:security: 22/24 passed in the suite run, including the new regression. Two files hit the runner's 30-second limit while the machine was under heavy load (load average about 50): encoded-api-path-security passed on its own (10.6 s). multiplayer-control-security passed when run directly (54-59 s); on staging's service.ts under the same load it took 76 s, and it passed in 21.6 s in the earlier multiplayer run. The remaining filters (runtime-integrity, shell-sandbox, extension-ipc, android-local-auth, docker-proxy-auth) all passed.
  • node ./scripts/run-regressions.mjs --filter multiplayer: 14/14 passed (all multiplayer regressions, including the unchanged multiplayer-session-lifecycle returning-player cases)
  • node ./scripts/run-regressions.mjs --filter multiplayer-seat-key on staging's service.ts fails as described above, and passes with this change.

Manual verification notes

  • Manually verify with two Engines (MULTIPLAYER_ENABLED=true, Multiplayer turned on): host a Roleplay room, join as a guest, have the AI whisper to the guest, leave and join again with the same names, and approve the request. Check that the guest gets the same seat and still sees the whisper.
  • Manually verify that a request from a different Engine with the same display name and persona name shows the name-conflict message when approved, and that the original player stays in the room.
  • Manually verify that after a full restart of the guest Engine, approving the same names shows the name-conflict message, and that it works after the host removes the old seat.
  • Manually verify that a guest on v2.5.0 can still join a host running this branch, and that a guest on this branch can still join a v2.5.0 host.

Docs and release impact

  • No docs changes needed
  • Updated docs (README / CONTRIBUTING / android/README) as needed
  • Translated docs on the docs-i18n branch updated to match, or a [docs-i18n] follow-up issue opened (see CONTRIBUTING.md § Translated documentation)
  • Version/release files updated (only if this PR includes a version bump)

English docs changed: docs/TROUBLESHOOTING.md (Disconnected bullet) and docs/development/multiplayer.md (recovery section and verification record). The release translation sweep picks these up.

UI evidence (if applicable)

No UI changes.

Summary by CodeRabbit

  • New Features
    • Returning multiplayer players can reclaim their existing seat by rejoining with their private session credential. Display or persona names alone no longer grant access to a seat.
    • Players who restart their guest session and lose the credential must ask the host to remove their old seat before rejoining with the same persona name.
  • Bug Fixes
    • Seat rejoining now protects existing participants and their private whisper history from requests made with a copied name or an incorrect credential.

🔄 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/Pasta-Devs/Marinara-Engine/pull/7823 **Author:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Created:** 10/19/2026 **Status:** ✅ Merged **Merged:** 10/19/2026 **Merged by:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Base:** `staging` ← **Head:** `fix/harden-multiplayer-rejoin` --- ### 📝 Commits (1) - [`2d013d1`](https://github.com/Pasta-Devs/Marinara-Engine/commit/2d013d19d8b09c8537e238e9effc6cdd6340b3b0) fix(multiplayer): give each seat a private rejoin key ### 📊 Changes **4 files changed** (+332 additions, -16 deletions) <details> <summary>View changed files</summary> 📝 `docs/TROUBLESHOOTING.md` (+1 -1) 📝 `docs/development/multiplayer.md` (+9 -0) 📝 `packages/server/src/services/multiplayer/service.ts` (+51 -15) ➕ `scripts/regressions/multiplayer-seat-key-security.regression.ts` (+271 -0) </details> ### 📄 Description > [!IMPORTANT] > Contributions target `staging`. Only `SpicyMarinara` may promote this repository's `staging` branch or a same-repository `hotfix/*` branch to `main`. > Outside and first-time contributors also require an approving review from `SpicyMarinara`. <!-- See CONTRIBUTING.md § Branches. --> ## Linked issue No public issue: this is a hardening follow-up from an internal multiplayer review. ## Why this change - Returning players were matched to their old seat by display name and persona name. Those names are public within the room, so they are not proof of who holds a seat. A seat carries the player's private whispers, Game sheet and round submissions, so it should only go back to the Engine that held it. ## What changed - Each guest seat now has a private rejoin key. It is the session token from the admission reply of the join request that first got the seat. The guest Engine remembers it for that room, and when it asks to join the same room again it sends the key as the bearer of the join request. - The host keeps only a SHA-256 hash of each seat's key, in memory with the rest of the live room. When the host approves a returning player, the request has to match the names and present that key (checked with `timingSafeEqual`). Without the key, a request with the same names is refused with the existing name-conflict error, and the real player's sessions are left alone. Kick and Stop drop the seat's key. - The key is never sent to other participants, never written to chat metadata, backups or exports, and never logged. - The peer protocol does not change. The admission reply already carried a random 32-byte token, and the host listener already accepted an `Authorization` bearer on every request. Engines from v2.5.0 keep working in both directions: - An older guest joining a newer host is admitted as before. It never presents a key, so after leaving it cannot take its old seat back by name. The host can remove the old seat, or the player can choose another persona name. - A newer guest joining an older host only sends a bearer that the older host ignores on join, so the old name-based rejoin still applies there. - Compatibility rule for seats without a key: every guest seat gets a key when the host first approves it, so a running room has no keyless guest seats (rooms never outlive a host restart). If a seat somehow has no key, nobody can take it by name, and its current session keeps working with its own token. This is the strictest rule that keeps every existing connection working. - Behaviour change: the guest keeps its rejoin keys in memory, like every other multiplayer credential. Leave, deleting the joined chat and turning Multiplayer off and on all keep the key. A full guest Engine restart loses it. After a restart, the host has to remove the old seat before that player can use the same persona name again. This is documented in `docs/TROUBLESHOOTING.md` and `docs/development/multiplayer.md`. - Added the `multiplayer-seat-key-security` regression. It runs over real TLS between two Engines and covers four cases: a request with copied names and no key is refused and gets no history or whispers; a made-up key is refused; the real player rejoins with the key and gets the same seat and the same whispers; the key and its hash never appear in another player's poll, the host's views or stored chats on either Engine. It fails on `staging` without this change (`Missing expected rejection: copied names do not take Lyra's seat`) and passes with it. ## Validation - [ ] `pnpm check` passes locally - [ ] Container (Docker / Podman) built and ran without issue - [ ] Ran the app, clicked through the changes manually - [ ] Checked edge cases (light + dark mode, mobile viewport, empty states, error paths) - [ ] Above manual verification completed (describe below) - [ ] Read and followed `CONTRIBUTING.md` Commands run by the agent on this branch: - `pnpm check`: passed (exit 0). ESLint reports one existing `react-hooks/exhaustive-deps` warning in client code this PR does not touch. - `pnpm regression:security`: 22/24 passed in the suite run, including the new regression. Two files hit the runner's 30-second limit while the machine was under heavy load (load average about 50): `encoded-api-path-security` passed on its own (10.6 s). `multiplayer-control-security` passed when run directly (54-59 s); on `staging`'s `service.ts` under the same load it took 76 s, and it passed in 21.6 s in the earlier multiplayer run. The remaining filters (`runtime-integrity`, `shell-sandbox`, `extension-ipc`, `android-local-auth`, `docker-proxy-auth`) all passed. - `node ./scripts/run-regressions.mjs --filter multiplayer`: 14/14 passed (all multiplayer regressions, including the unchanged `multiplayer-session-lifecycle` returning-player cases) - `node ./scripts/run-regressions.mjs --filter multiplayer-seat-key` on `staging`'s `service.ts` fails as described above, and passes with this change. ### Manual verification notes - [ ] Manually verify with two Engines (`MULTIPLAYER_ENABLED=true`, Multiplayer turned on): host a Roleplay room, join as a guest, have the AI whisper to the guest, leave and join again with the same names, and approve the request. Check that the guest gets the same seat and still sees the whisper. - [ ] Manually verify that a request from a different Engine with the same display name and persona name shows the name-conflict message when approved, and that the original player stays in the room. - [ ] Manually verify that after a full restart of the guest Engine, approving the same names shows the name-conflict message, and that it works after the host removes the old seat. - [ ] Manually verify that a guest on v2.5.0 can still join a host running this branch, and that a guest on this branch can still join a v2.5.0 host. ## Docs and release impact - [ ] No docs changes needed - [ ] Updated docs (README / CONTRIBUTING / android/README) as needed - [ ] Translated docs on the `docs-i18n` branch updated to match, or a `[docs-i18n]` follow-up issue opened (see CONTRIBUTING.md § Translated documentation) - [ ] Version/release files updated (only if this PR includes a version bump) English docs changed: `docs/TROUBLESHOOTING.md` (Disconnected bullet) and `docs/development/multiplayer.md` (recovery section and verification record). The release translation sweep picks these up. ## UI evidence (if applicable) No UI changes. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Returning multiplayer players can reclaim their existing seat by rejoining with their private session credential. Display or persona names alone no longer grant access to a seat. * Players who restart their guest session and lose the credential must ask the host to remove their old seat before rejoining with the same persona name. * **Bug Fixes** * Seat rejoining now protects existing participants and their private whisper history from requests made with a copied name or an incorrect credential. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-24 04:09:06 +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
Pasta-Devs/Marinara-Engine#7949
No description provided.