Skip to content

fix(api): enforce payload size limits in the shared readers - #8324

Closed
ha-am-dev wants to merge 1 commit into
modrinth:mainfrom
ha-am-dev:fix/shared-payload-size-limits
Closed

ha-am-dev wants to merge 1 commit into
modrinth:mainfrom
ha-am-dev:fix/shared-payload-size-limits

Conversation

@ha-am-dev

Copy link
Copy Markdown

fix(api): enforce payload size limits in the shared readers

What

Two related bugs in apps/labrinth/src/util/routes.rs:

  1. read_limited_from_payload checked bytes.len() >= cap before appending the
    next chunk, so the last chunk could take the body past the cap by up to one chunk
    (an image upload capped at 1 MiB could land above 1 MiB).
  2. read_typed_from_payload had no cap at all. It buffered the entire request body
    into BytesMut before deserialising, and POST /v3/report is the caller, so a
    report body was read without any size limit.

Change

  • read_limited_from_payload now measures bytes.len().saturating_add(item.len())
    before extending.
  • read_typed_from_payload takes a cap and an error message and delegates to
    read_limited_from_payload.
  • The report route passes 256 * 1024.
-        if bytes.len() >= cap {
+        if bytes.len().saturating_add(item.len()) > cap {

Notes for reviewers

  • 256 KiB is a proposal. Report bodies are markdown with image ids, so this should be
    generous, but pick whatever matches how the endpoint is used in practice.
  • read_from_field (the multipart helper in the same module) already does the
    saturating_add comparison and did not need changing.

Testing

  • Unit test: feed read_limited_from_payload a 9-byte chunk followed by a 2-byte
    chunk with cap = 10; the call must now fail instead of returning 11 bytes.
  • Integration: POST /v3/report with a body just under and just over 256 KiB and
    check the status codes.

@github-actions

Copy link
Copy Markdown
Contributor

Pull request changelog

App

Added

Changed

Deprecated

Removed

Fixed

Security

Website

Added

Changed

Deprecated

Removed

Fixed

Security

Hosting

Added

Changed

Deprecated

Removed

Fixed

Security

@mergify

mergify Bot commented Nov 14, 2026 •

Copy link
Copy Markdown

This pull request is closed, so it cannot be queued. Reopen it to get the box back.

@Prospector Prospector closed this Nov 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants