Skip to content

API parses request bodies up to 32 MB before auth #3831

Done

Description

@Aryainguz

Without a login or API key, anyone can make the API parse a 32 MB body before it answers 401. Four such requests took the API from 58 MB to 1,064 MB of memory.

What happened?

api-app.ts runs express.json / text / urlencoded with limit: '32mb' on every route, before any auth check. So /login/password, /register/password and every protected route read and parse the whole body before rejecting the caller.

Limit 4 × 32 MB, no auth API memory
32mb (today) parsed, then 401 58 → 1,064 MB

Steps to reproduce

On yarn dev, with API set to the API URL:

python3 -c "print('[' + ','.join(['{\"a\":1}'] * 4000000) + ']')" > /tmp/big.json
for i in 1 2 3 4; do
  curl -s -o /dev/null -w '%{http_code}\n' -X POST "$API/dashboards" \
    -H 'content-type: application/json' --data-binary @/tmp/big.json &
done; wait

Each returns 401 after about a second, and the API's memory grows by about 250 MB per request.

Why I don't think it's a P0

It only affects availability. Many deployments sit behind a reverse proxy or ingress that caps bodies at 1 MB by default, so they're safe. The default docker-compose.yml publishes the API port, though, and the app's /api proxy streams bodies through with no limit.

Questions @pulpdrew

  1. Is the 32 MB limit before auth intentional? and did I miss something with this
  2. Does any unauthenticated route need more than 100 KB?
  3. Should the limits be configurable?

Proposed fix

Parse bodies after the session loads. A session, a valid API key or local mode keeps 32mb; everyone else gets 100kb. The caller check runs only when the body could be over 100 KB. I have a branch with tests and can open the PR.

Activity

  1. added
    bug
    Needs Feedback
    on Nov 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Needs Feedbackbugexternal

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions