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

Abierto Apto para principiantes
#476 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
2/5
Tiempo estimado
1-3 horas
Aptitud para principiantes
76/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
bun, typescript

Línea de trabajo

Empieza en modules/network/src/server/udp.server.network.ts, alrededor de las líneas 158–176, y lee shared/signaling.ts para consultar el helper parseSignal existente. Después, revisa las pruebas de señalización en test/server/udp.server.spec.ts y añade un caso con un frame malformado junto al caso correcto. La tarea está terminada cuando los frames no válidos ya no provocan que el servidor se bloquee y la prueba verifica que el socket se cierra con el código 1008.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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

Lenguaje dominante
TypeScript
Estrellas
7
Forks
2
Merge medio
1 d 17 h
PR fusionados (30 d)
17

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de NanoForge-dev/Engine

Todos los issues de NanoForge-dev/Engine

Issues similares

Más issues de TypeScript

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.