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

Aperta Adatta ai principianti
#476 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
76/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
bun, typescript

Direzione di ricerca

Inizia da modules/network/src/server/udp.server.network.ts, intorno alle righe 158–176, e leggi shared/signaling.ts per consultare l'helper parseSignal esistente. Poi esamina i test di signaling in test/server/udp.server.spec.ts e aggiungi un caso con un frame malformato accanto al caso valido. Il lavoro è completato quando i frame non validi non causano più l'arresto anomalo del server e il test verifica che il socket venga chiuso con il codice 1008.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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

Lingua principale
TypeScript
Stelle
7
Fork
2
Merge medio
1g 17h
PR unite (30g)
17

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di NanoForge-dev/Engine

Tutte le issue di NanoForge-dev/Engine

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.