P4: Standalone web API can read past its request buffer on a large request body
Maintainers usually reply within 1 day
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 65/100
Research direction
Start by inspecting code/network/stand_gui-unix.cpp around lines 650–656, where mg_read fills entityBuffer and json_loads parses it. Check how the returned byte count can be used to keep parsing within the buffer, and how oversized bodies should be handled. Done when a request body at or above 1,024 bytes cannot make the parser read past the buffer and the server handles it safely.
Written by the indexing model from the issue text.
Description
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)
- Start a dedicated server on Linux:
fs2_open -standalonewith any mod, so the web panel starts on its port (8080 by default). - Send an authenticated
PUT /api/1/serverorPOST /api/1/chatwith a body of 1,024 bytes or more. - 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
- Read one byte less so the zero byte from the
memsetalways stays at the end:mg_read(conn, entityBuffer, sizeof(entityBuffer) - 1). - Keep the byte count
mg_readreturns and parse withjson_loadb, which takes a length and never looks for a zero byte. - Read the whole body (up to a sane cap) into an
SCP_stringand reply with an error when it is too large, so long chat messages are not silently cut off either.
- Dominant language
- C++
- Stars
- 488
- Forks
- 184
- Avg merge
- 1d 19h
- Merged PRs (30d)
- 32
Getting set up
We have not checked this project's setup files yet. Start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from scp-fs2open/fs2open.github.com
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
scp-fs2open/fs2open.github.com#7956 ·
Maintainers usually reply within 1 day
-
bug HUD LLM-suggested
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
scp-fs2open/fs2open.github.com#7953 ·
Maintainers usually reply within 1 day
-
bug controls LLM-suggested
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
scp-fs2open/fs2open.github.com#7946 · 3 comments ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 Half a day Newbie friendliness 66/100
scp-fs2open/fs2open.github.com#7932 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
scp-fs2open/fs2open.github.com#7924 ·
Maintainers usually reply within 1 day
All issues in scp-fs2open/fs2open.github.com
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 66/100
godotengine/godot#125035 ·
Maintainers usually reply within 1 day
-
agent:WSL bug LOW security
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
mgradwohl/tasksmack#3290 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
mw00/project-maya#743 ·
Maintainers usually reply within 1 day
-
ENABLE_CUTE_DSL=OFF does not compile: runPadding stub does not match its declarationPossibly taken @akhil9tiet claimed this today. Openbug
Difficulty 1/5 Under an hour Newbie friendliness 82/100
NVIDIA/TensorRT-Edge-LLM#268 · 2 comments ·
Maintainers usually reply within 3 days
-
Bug
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 1 day