Summary
NiceGUI's media streaming routes app.add_media_file() and app.add_media_files() accept a user-controlled query parameter that directly influences how files are read and served.
Because this parameter is not validated, an attacker can bypass chunked streaming and force the server to load entire files into memory, potentially causing excessive memory usage, performance degradation, or denial of service when large files and concurrent requests are involved.
Affected context
This vulnerability affects applications built with NiceGUI that:
- Use app.add_media_file() or app.add_media_files() to serve media content
- Allow user-supplied query parameters to control media streaming behavior
- Host large media files or operate in environments where resource limits are tight
The risk is higher when the application serves many concurrent clients or when large files (e.g., videos, high-resolution images, large audio files) are accessible through these routes.
Exploit preconditions
- Attack surface: Public or internal HTTP endpoints exposing NiceGUI media routes.
- Required access: Ability to send HTTP requests to the affected media endpoints (typically anonymous or low-privilege).
- Trigger point: Supplying crafted query parameters that manipulate the range-response handling so that the server reads full files into memory instead of streaming in chunks.
- Why exploitation is possible: The media-related query parameter is accepted without adequate validation or bounds checking, allowing clients to influence how much data is loaded into memory per request, leading to uncontrolled resource usage when repeated or parallelized.
Why this happens
The core issue stems from improper input validation (CWE-20) combined with uncontrolled resource consumption (CWE-770).
NiceGUI's media routes pass a user-controlled query parameter directly into the range-response implementation, which controls file reading behavior.
Without validating or constraining this input, the application can be coerced into bypassing efficient chunked streaming and instead loading entire media files into memory.
This design implicitly trusts client-controlled values to dictate server-side resource usage, enabling an attacker to scale their impact with file size and concurrency.
Potential impact
- Server memory exhaustion, which can lead to process crashes or restarts
- Significant performance degradation for legitimate users due to resource contention
- Temporary denial of service for the affected NiceGUI application or hosting environment
- Increased infrastructure costs or instability under load in shared hosting or containerized environments
General mitigation guidance
Effective mitigation focuses on constraining how client input can influence resource-intensive operations and enforcing defensive resource management patterns:
- Validate and sanitize query parameters affecting media streaming, allowing only known-safe values and ranges.
- Enforce chunked, bounded file streaming on the server side, independent of client-controlled parameters.
- Impose maximum file size and response size limits, refusing or degrading service for requests that exceed safe thresholds.
- Apply server-side timeouts, rate limits, and per-client connection limits for media endpoints to reduce abuse potential.
- Use operating system or runtime-level resource constraints (e.g., memory limits, container quotas) so that individual services cannot exhaust host resources.
How teams detect issues like this
Detection can rely on both code-centric and operational signals:
- Static analysis: Flag code paths where user-controlled query parameters are passed directly into file I/O or range/streaming logic without validation or bounds checking.
- Code review: Look for media or file-serving routes that trust client input to choose buffer sizes, byte ranges, or streaming modes; verify that strict validation and sensible defaults are in place.
- Runtime monitoring: Track memory usage, request rates, and error spikes on media endpoints; alert on patterns of repeated large-range or anomalous streaming requests from the same sources.
- Log analysis: Inspect access logs for requests that systematically target large media files with unusual or repetitive query parameters that correlate with resource spikes.

