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

Aberta Para iniciantes
#476 0 comentários 0 reações 0 responsáveis Ver no GitHub

Mantenedores costumam responder em até 1 dia

Ninguém assumiu esta issue ainda.

Avaliação

Dificuldade
2/5
Tempo estimado
1-3 horas
Facilidade para iniciantes
76/100
Tipo de issue
Bug
Clareza
Claramente especificada
Status de atividade
Ativa
Stack de tecnologia
bun, typescript
Domínio
networking, security

Direção de pesquisa

Comece em modules/network/src/server/udp.server.network.ts, por volta das linhas 158–176, e leia shared/signaling.ts para consultar o helper parseSignal existente. Em seguida, examine os testes de signaling em test/server/udp.server.spec.ts e adicione um caso de frame malformado ao lado do caso de sucesso. O trabalho estará concluído quando frames inválidos não fizerem mais o servidor travar e o teste verificar que o socket é fechado com o código 1008.

Escrita pelo modelo de indexação a partir do texto da issue.

Descrição

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

Linguagem predominante
TypeScript
Estrelas
7
Forks
2
Merge médio
1d 17h
PRs com merge (30d)
17

Preparar o ambiente

Primeiros passos

  1. Leia a issue inteira e depois o guia de contribuição do projeto.
  2. Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
  3. Faça um fork do repositório e trabalhe em uma branch.
  4. Abra um pull request que referencie o número da issue.

Mais de NanoForge-dev/Engine

Todas as issues de NanoForge-dev/Engine

Issues semelhantes

Mais issues de TypeScript

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.