Skip to content

[Bug]: multer.memoryStorage() for 15MB PDF uploads causes Memory Exhaustion and DoS #1549

Description

@Dev1822

Bug Description

The uploadNotes middleware is configured to use multer.memoryStorage() with a file size limit of 15MB. Memory storage buffers the entire file in RAM before passing it to the controller. An attacker can send multiple concurrent requests containing 15MB payloads. Since Node.js has a default heap limit of ~1.4GB, just 100 concurrent requests will consume 1.5GB of RAM, immediately crashing the server with an Out-of-Memory (OOM) error.

Steps to Reproduce

  1. Write a script to send 100 concurrent POST requests to /api/notes-summary/save or any PDF upload route.
  2. Attach a 15MB dummy PDF to each request.
  3. Observe the Node.js server crashing with a FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory.

Expected Behavior

File uploads should be streamed directly to disk using multer.diskStorage() or processed via a streaming parser (like busboy) to maintain a low and predictable memory footprint.

Actual Behavior

The entire file is buffered into RAM concurrently, making the server highly vulnerable to Denial of Service (DoS) attacks.

Severity

Critical

Screenshots / Screen Recording

No response

Browser

No response

Operating System

No response

Additional Context

Located in backend/middlewares/uploadMiddleware.js.

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingclaimedThis issue has been claimed by a contributor

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions