fix(network): one malformed signaling frame crashes the UDP game server

オープン 初心者向け
#476 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
76/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
bun, typescript

調査の方向性

modules/network/src/server/udp.server.network.tsの158~176行あたりから始め、既存のparseSignalヘルパーを確認するためにshared/signaling.tsを読みます。次に、test/server/udp.server.spec.tsのシグナリングテストを調べ、正常系の隣に不正なフレームのケースを追加します。不正なフレームでサーバーがクラッシュしなくなり、ソケットがコード1008で閉じられることをテストで確認できれば完了です。

索引モデルが issue の本文から書いたものです。

説明

bug modules:network
Which package is this bug report for?

network

Issue description

The async message handler of the UDP signaling WebSocket calls JSON.parse on raw input and then awaits setRemoteDescription / addIceCandidate with unvalidated data, with no try/catch. Neither the engine nor the loader installs an unhandled-rejection handler, so the rejection is unhandled and the Bun process exits. Any client that connects over TCP gets the session token this socket needs, so any player can stop the game server with a single frame. A null payload also throws on data.type, and pendingCandidates grows without limit.

Where:

Evidence:

message: async (webSocket, message) => {
  ...
  const data = JSON.parse(typeof message === "string" ? message : new TextDecoder().decode(message));
  if (data.type === "offer") { await this.receiveClientOffer(peerConnection, data.offer, webSocket); }

Reproduced with the same handler shape on Bun 1.3.14: ws.send("{") → SyntaxError: JSON Parse error: Expected '}' → process exits with code 1.

Suggested fix: Parse with the existing parseSignal (shared/signaling.ts), check the types of type / offer / candidate, wrap the body in try/catch and close the socket with 1008 on failure. Add a malformed-frame test next to the "signaling" happy path in test/server/udp.server.spec.ts.

Found during a code audit of main at be72076.

Code sample
// Same handler shape as UDPServer's signaling socket
const server = Bun.serve({
  port: 0,
  fetch: (req, srv) => (srv.upgrade(req) ? undefined : new Response("no")),
  websocket: { message: async (_ws, m) => { const d = JSON.parse(String(m)); console.log(d.type); } },
});
const ws = new WebSocket(`ws://localhost:${server.port}`);
ws.onopen = () => ws.send("{");
// → SyntaxError: JSON Parse error, process exits with code 1
Versions
  • Engine main at be72076
  • pnpm 12.0.0, Node.js 26, Bun 1.3.14
Issue priority

High (immediate attention needed)

I have tested this issue on a development release

be72076

主要言語
TypeScript
スター
7
フォーク
2
平均マージ
1日 17時間
マージ済み PR(30日)
17

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

NanoForge-dev/Engine のほかの issue

NanoForge-dev/Engine の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。