P4: Standalone web API can read past its request buffer on a large request body

Aperta Adatta ai principianti
#7,965 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@dustinspace217 ci sta già lavorando.

Dal 31/10/2026.

  • #7975 di @dustinspace217 — aperta

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
65/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
cpp
Ambito
backend, security

Direzione di ricerca

Inizia esaminando code/network/stand_gui-unix.cpp intorno alle righe 650–656, dove mg_read riempie entityBuffer e json_loads lo analizza. Verifica come utilizzare il numero di byte restituito per mantenere l’analisi entro i limiti del buffer e come gestire i corpi troppo grandi. Il lavoro è completato quando un corpo della richiesta di almeno 1.024 byte non può far leggere all’analizzatore oltre il buffer e il server lo gestisce in modo sicuro.

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

Descrizione

Low priority: it needs the web panel login, only affects Linux and Mac dedicated servers, and I found it by reading the code, not by running it.

Problem

On a Linux or Mac dedicated server, the web API reads a request body into a 1,024-byte buffer and then parses it as text. When the body is 1,024 bytes or longer, the buffer is filled completely and has no zero byte at the end, so the parser keeps reading past the buffer until it happens to hit one. That can produce garbage input or crash the server.

The code is in code/network/stand_gui-unix.cpp on master (8afa31842), lines 650-656: mg_read fills entityBuffer with up to sizeof(entityBuffer) bytes, then json_loads reads it as a zero-terminated string. The byte count mg_read returns is commented out and unused.

Steps to reproduce (not run; from reading the code)

  1. Start a dedicated server on Linux: fs2_open -standalone with any mod, so the web panel starts on its port (8080 by default).
  2. Send an authenticated PUT /api/1/server or POST /api/1/chat with a body of 1,024 bytes or more.
  3. The JSON parser reads past the end of the 1,024-byte buffer.

Expected vs. actual behavior

Expected: an oversized body is cut off or rejected, and the server keeps running.
Actual (from the code): the parser reads memory past the buffer, which may give a parse error, wrong input, or a crash.

Proposed fixes

  1. Read one byte less so the zero byte from the memset always stays at the end: mg_read(conn, entityBuffer, sizeof(entityBuffer) - 1).
  2. Keep the byte count mg_read returns and parse with json_loadb, which takes a length and never looks for a zero byte.
  3. Read the whole body (up to a sane cap) into an SCP_string and reply with an error when it is too large, so long chat messages are not silently cut off either.
Lingua principale
C++
Stelle
488
Fork
184
Merge medio
1g 23h
PR unite (30g)
28

Preparare l'ambiente

Non abbiamo ancora controllato i file di configurazione di questo progetto. Parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

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 scp-fs2open/fs2open.github.com

Tutte le issue di scp-fs2open/fs2open.github.com

Issue simili

Altre issue su C++

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.