The vulnerability is a Denial of Service (DoS) caused by an infinite loop when processing multipart POST requests in aiohttp. The root cause is the use of assert statements for critical validation within the multipart parsing logic. When a Python application is run in an optimized mode (with the -O flag or PYTHONOPTIMIZE=1), these assert statements are compiled out and ignored.
An attacker can exploit this by sending a specially crafted multipart POST request that violates the assumptions enforced by the asserts. Specifically:
- In
aiohttp.web_request.Request.post, an assert checked that each multipart field had a name. Without this check, the loop processing fields could misbehave.
- In
aiohttp.multipart.BodyPartReader.read_chunk, an assert validated the CRLF at the end of a part. Bypassing this allows the parser to enter an invalid state.
- In
aiohttp.multipart.BodyPartReader._read_chunk_from_stream, an assert prevented reading past the end of the stream, which could also lead to an infinite loop.
The combination of these bypassed checks allows the while loop in Request.post to continue indefinitely, consuming CPU and rendering the service unresponsive. The patch rectifies this by replacing the assert statements with explicit ValueError exceptions, which are not removed during optimization, thus ensuring the validation logic is always executed.