fix(gameserver): discard a malformed client frame instead of dropping the session #95

Merged
marco merged 1 commit from fix/graceful-malformed-message into main 2026-07-19 13:33:49 +02:00
Owner

Code-review finding SEC-2 (+ T3 coverage).

A ClientMessage with an unknown type discriminator or an out-of-range enum makes ProtocolJson.Deserialize throw JsonException. That wasn't in the receive loop's catch filter (only WebSocketException/OperationCanceledException), so it bubbled up unhandled and force-closed the connection — bypassing the author's intended graceful default: path.

Catch JsonException in the receive loop, log at debug, and skip the frame (it was fully read, so the next receive starts clean). The session survives a modified client's garbage.

Integration test: a {"type":"bogus"} frame followed by a valid MoveRequest still applies the move (a dropped session would time out).

Definition of Done

  • A malformed frame is discarded and the connection stays open + processes subsequent valid messages.
  • Suite green, zero warnings.
Code-review finding **SEC-2** (+ **T3** coverage). A `ClientMessage` with an unknown `type` discriminator or an out-of-range enum makes `ProtocolJson.Deserialize` throw `JsonException`. That wasn't in the receive loop's catch filter (only `WebSocketException`/`OperationCanceledException`), so it bubbled up **unhandled** and force-closed the connection — bypassing the author's intended graceful `default:` path. Catch `JsonException` in the receive loop, log at debug, and **skip the frame** (it was fully read, so the next receive starts clean). The session survives a modified client's garbage. Integration test: a `{"type":"bogus"}` frame followed by a valid `MoveRequest` still applies the move (a dropped session would time out). ## Definition of Done - [ ] A malformed frame is discarded and the connection stays open + processes subsequent valid messages. - [ ] Suite green, zero warnings.
fix(gameserver): discard a malformed client frame instead of dropping the session
All checks were successful
ci / Lint & Test (pull_request) Successful in 2m5s
530e0d1c3b
A ClientMessage with an unknown `type` discriminator or an out-of-range enum makes
ProtocolJson.Deserialize throw JsonException; that wasn't in the receive loop's catch
filter, so it bubbled up unhandled and force-closed the connection (bypassing the
intended graceful 'Unhandled message' path). Catch JsonException in the receive loop,
log at debug, and skip the frame — the session survives. Integration test: a garbage
frame followed by a valid move still applies the move.

Review finding SEC-2 (+ T3 coverage).
marco merged commit 19ce758b70 into main 2026-07-19 13:33:49 +02:00
marco deleted branch fix/graceful-malformed-message 2026-07-19 13:33:49 +02:00
Sign in to join this conversation.
No reviewers
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
marco/IsoMmo!95
No description provided.