Skip to content

MEDIUM: Audio transcription endpoint has no upload size limit — DoS via memory exhaustion #193

Description

@raullenchai

Severity: MEDIUM

Description

The /v1/audio/transcriptions endpoint at routes/audio.py:49-51 reads the entire uploaded file into memory with no size limit:

with tempfile.NamedTemporaryFile(delete=False, suffix=".wav") as tmp:
    content = await file.read()  # No size limit!
    tmp.write(content)
    tmp_path = tmp.name

Additionally:

  1. No content-type validation is performed on the uploaded file
  2. The file is written to disk with a .wav suffix regardless of actual content
  3. No max_length or size check is applied

Impact

A malicious client can upload a multi-gigabyte file to exhaust server memory, causing:

  • OOM kill of the server process
  • macOS memory pressure causing system-wide slowdown
  • Potential crash of the MLX inference engine (GPU state corruption)

Reproduction

# Create a 2GB file
dd if=/dev/zero of=/tmp/large.wav bs=1M count=2048

# Upload to server — reads 2GB into memory
curl -X POST http://localhost:8000/v1/audio/transcriptions \
  -H "Authorization: Bearer test123" \
  -F "file=@/tmp/large.wav" \
  -F "model=whisper-small"

Clean up:

rm /tmp/large.wav

Fix

Add size validation before reading the file body:

MAX_AUDIO_SIZE = 25 * 1024 * 1024  # 25 MB

# Read in chunks to check size
content = b""
async for chunk in file.stream():
    content += chunk
    if len(content) > MAX_AUDIO_SIZE:
        raise HTTPException(status_code=413, detail="File too large")

Or use FastAPI's File() with max_length parameter, or check Content-Length header before reading.

File

vllm_mlx/routes/audio.py:49-51

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingsecuritySecurity vulnerability or hardening

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions