You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Optional max_response_bytes cap on Comlink responses #240
_send in both clients reads the whole response body into memory (r.content) before decoding it, with no upper limit. A misbehaving or compromised Comlink, or a proxy in front of it, can exhaust memory. That matters on small hosts such as a Raspberry Pi.
Proposed Solution
Add a keyword-only max_response_bytes: int | None = None to both client constructors.
With the default None, behaviour is exactly as today.
When set, send the request with client.stream(...):
Reject at once if Content-Length is over the limit. That header gives the compressed size, so it only allows an early exit.
Count the decompressed bytes from iter_bytes() and abort with SwgohComlinkValueError once the count passes the limit. This is the real guard, and it also stops gzip bombs.
On error statuses, read the body, up to the limit, before calling SwgohComlinkHTTPError.from_response.
/data responses are far larger than any other endpoint's. A cap low enough to protect other calls would break get_game_data, the same reason /data already has its own timeout (GAME_DATA_TIMEOUT). Give get_game_data a separate, larger limit, or document the size that full game data needs.
Acceptance
Default behaviour and existing tests are unchanged.
A mocked oversized response raises with the limit set, in both sync and async.
A Content-Length over the limit fails before the body is read.
A body that starts with a UTF-8 BOM still raises SwgohComlinkDecodeError (regression guard).
Alternatives Considered
A default-on limit. Rejected: it changes default behaviour, and a sensible value depends on the endpoint and the host's memory.
Activity
github-actions commentedon Nov 7, 2026
Addressed by #258, which is now merged into
develop. This issue will close automatically when that change is released tomain.