CVE-2024-30251: Denial of service when trying to parse malformed POST requests in aiohttp
Summary An attacker can send a specially crafted POST (multipart/form-data) request. When the aiohttp server processes it, the server will enter an infinite loop and be unable to process any further requests.
Impact An attacker can stop the application from serving requests after sending a single request.
-------
For anyone needing to patch older versions of aiohttp, the minimum diff needed to resolve the issue is (located in readchunkfromlength()):
diff diff --git a/aiohttp/multipart.py b/aiohttp/multipart.py index 227be605c..71fc2654a 100644 --- a/aiohttp/multipart.py +++ b/aiohttp/multipart.py @@ -338,6 +338,8 @@ class BodyPartReader: assert self.length is not None, "Content-Length required for chunked read" chunksize = min(size, self.length - self.readbytes) chunk = await self.content.read(chunksize) + if self.content.ateof(): + self.ateof = True return chunk async def readchunkfromstream(self, size: int) -> bytes:
This does however introduce some very minor issues with handling form data. So, if possible, it would be recommended to also backport the changes in: https://github.com/aio-libs/aiohttp/commit/cebe526b9c34dc3a3da9140409db63014bc4cf19 https://github.com/aio-libs/aiohttp/commit/7eecdff163ccf029fbb1ddc9de4169d4aaeb6597 https://github.com/aio-libs/aiohttp/commit/f21c6f2ca512a026ce7f0f6c6311f62d6a638866
Other sources
aiohttp is an asynchronous HTTP client/server framework for asyncio and Python. In affected versions an attacker can send a specially crafted POST (multipart/form-data) request. When the aiohttp server processes it, the server will enter an infinite loop and be unable to process any further requests. An attacker can stop the application from serving requests after sending a single request. This issue has been addressed in version 3.9.4. Users are advised to upgrade. Users unable to upgrade may manually apply a patch to their systems. Please see the linked GHSA for instructions.
— NVD
Affected Software
Remediation
Recommended actions to resolve this vulnerability, in priority order.
- Upgrade
Upgrade
pip/aiohttpto a version that resolves this vulnerability.Fixed in 3.9.4 - Upgrade
Upgrade
redhat/aiohttpto a version that resolves this vulnerability.Fixed in 3.9.4 - Upgrade
Upgrade
aiohttpto a version that resolves this vulnerability.Fixed in 3.9.4Patch CVE-2024-30251 - Compensating control
If upgrading is not possible, backport the minimum diff located in `_read_chunk_from_length()` in `aiohttp/multipart.py` to resolve CVE-2024-30251 (DoS via malformed `multipart/form-data`).
Event History
Frequently Asked Questions
What is the severity of CVE-2024-30251?
CVE-2024-30251 is considered to be a critical vulnerability due to its potential to cause denial of service by entering an infinite loop.
How do I fix CVE-2024-30251?
To fix CVE-2024-30251, upgrade aiohttp to version 3.9.4 or later.
What type of attack does CVE-2024-30251 involve?
CVE-2024-30251 involves an attacker sending a specially crafted multipart/form-data POST request to the aiohttp server.
What impact does CVE-2024-30251 have on affected applications?
CVE-2024-30251 can cause an affected application to stop serving requests, leading to service disruption.
Which versions of aiohttp are affected by CVE-2024-30251?
CVE-2024-30251 affects aiohttp versions prior to 3.9.4.