Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion strix/viewer/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,17 @@ def do_POST(self) -> None:
logger.exception("viewer request failed: POST %s", path)
self._send_json(HTTPStatus.INTERNAL_SERVER_ERROR, {"error": "internal error"})

# Cap on request body size so a client cannot force unbounded
# memory allocation by sending a huge Content-Length.
_MAX_BODY_BYTES = 2 * 1024 * 1024 # 2 MiB

def _read_body(self) -> dict[str, Any]:
length = int(self.headers.get("Content-Length") or 0)
try:
length = int(self.headers.get("Content-Length") or 0)
except (ValueError, OverflowError):
return {}
if length < 0 or length > self._MAX_BODY_BYTES:
return {}
raw = self.rfile.read(length) if length else b""
try:
body = json.loads(raw or b"{}")
Expand Down