{"id":1737,"cve":"CVE-2026-34519","cve_url":"https:\/\/www.cvedetails.com\/cve\/CVE-2026-34519\/","cwe":"CWE-113","cwe_number":113,"cwe_url":"https:\/\/cwe.mitre.org\/data\/definitions\/113","cvss_score":2.7,"published":"2026-04-01","owasp":"A03 Injection","odc":"Checking","cdc":"Missing Check","category":"Input Validation and Sanitization","subcategory":"Command Injection","scope":"Remote","impact":"Unauthorized Access","summary":"AIOHTTP allows header injection via the Response `reason` parameter.","permalink":"https:\/\/netpack.pt\/vaitp\/vulnerability\/CVE-2026-34519\/","description":"AIOHTTP is an asynchronous HTTP client\/server framework for asyncio and Python. Prior to version 3.13.4, an attacker who controls the reason parameter when creating a Response may be able to inject extra headers or similar exploits. This issue has been patched in version 3.13.4.","solution":"Upgrade AIOHTTP to version 3.13.4 or later.","affected_component":"AIOHTTP","fixed_by_upgrading":true,"vulnerable_code":"from aiohttp import web\n\nasync def vulnerable_handler(request):\n    # In a vulnerable version, the 'reason' parameter is not sanitized.\n    # An attacker can provide a value like \"OK\\r\\nInjected-Header: value\"\n    # through the 'reason_payload' query parameter to inject a header.\n    reason_payload = request.query.get(\"reason_payload\", \"OK\")\n\n    return web.Response(\n        status=200,\n        reason=reason_payload,\n        text=\"This is the response body.\"\n    )\n\napp = web.Application()\napp.add_routes([web.get(\"\/\", vulnerable_handler)])\n\nif __name__ == \"__main__\":\n    web.run_app(app, port=8080)","patched_code":"import asyncio\nfrom aiohttp import web\n\n# The fictional CVE-2026-34519 describes a real vulnerability type:\n# HTTP Header Injection via the 'reason' phrase.\n# The actual, similar vulnerability was CVE-2023-47627, fixed in aiohttp 3.9.0.\n#\n# This code demonstrates the logic of the fix. The fix involves validating\n# the 'reason' string to ensure it does not contain carriage return (CR) or\n# line feed (LF) characters, which could be used to inject new lines and headers.\n\ndef represents_patched_response_creation(status, reason, text):\n    \"\"\"\n    This function simulates the creation of an HTTP response in a patched\n    version of aiohttp. It includes the crucial validation step on the 'reason' phrase.\n    \"\"\"\n    # --- THE FIX ---\n    # Before using the reason phrase, validate it to prevent CRLF injection.\n    # If a forbidden character is found, an exception is raised.\n    if '\\r' in reason or '\\n' in reason:\n        raise ValueError(\"Invalid characters in reason phrase (CR\/LF detected)\")\n    # --- END OF FIX ---\n\n    # If validation passes, construct the response as usual.\n    # The actual aiohttp.web.Response object handles this internally.\n    return web.Response(status=status, reason=reason, text=text)\n\n\nasync def handle_request(request):\n    \"\"\"\n    A web handler to demonstrate the effect of the fix.\n    It takes a 'reason' from the query parameters to simulate user-controlled input.\n    \"\"\"\n    # Simulate an attacker providing a malicious reason phrase via a query parameter.\n    user_provided_reason = request.query.get(\"reason\", \"OK\")\n\n    print(f\"\\nAttempting to create response with reason: '{user_provided_reason!r}'\")\n\n    try:\n        # Use the patched creation logic, which contains the security check.\n        response = represents_patched_response_creation(\n            status=200,\n            reason=user_provided_reason,\n            text=\"Response created successfully.\"\n        )\n        print(\"SUCCESS: Response created safely.\")\n        return response\n    except ValueError as e:\n        # The malicious attempt is caught, and an error response is returned.\n        error_message = f\"FAILURE: Vulnerability prevented. {e}\"\n        print(error_message)\n        return web.Response(status=400, text=error_message)\n\n\nasync def main():\n    \"\"\"Sets up and runs the web server.\"\"\"\n    app = web.Application()\n    app.add_routes([web.get('\/', handle_request)])\n    runner = web.AppRunner(app)\n    await runner.setup()\n    site = web.TCPSite(runner, 'localhost', 8080)\n    await site.start()\n\n    print(\"=\" * 60)\n    print(\"Server started on http:\/\/localhost:8080\")\n    print(\"This code demonstrates the fix for a header injection vulnerability.\")\n    print(\"\\nTo test, use a client like curl in separate terminal windows:\")\n    print(\"\\n1. Test a valid request (no injection):\")\n    print(\"   curl -i http:\/\/localhost:8080?reason=All-Good\")\n    print(\"\\n2. Test a malicious request (attempts injection):\")\n    print(\"   curl -i \\\"http:\/\/localhost:8080?reason=OK%0d%0aInjected-Header:%20evil\\\"\")\n    print(\"=\" * 60)\n\n    # Keep server running to allow for testing.\n    await asyncio.Event().wait()\n\n\nif __name__ == \"__main__\":\n    try:\n        asyncio.run(main())\n    except KeyboardInterrupt:\n        print(\"\\nServer shutting down.\")","payload_needed":true,"payload":"```python\n\"OK\\r\\nX-Injected-Header: vulnerable\"\n```","payload_status":"available","published_fix":[{"repository":"aio-libs\/aiohttp","commit_url":"https:\/\/github.com\/aio-libs\/aiohttp\/commit\/53b35a2f8869c37a133e60bf1a82a1c01642ba2b","commit_subject":"Restrict reason (#12209) (#12212)","units":[{"file":"aiohttp\/http_writer.py","function":"_py_serialize_headers"},{"file":"aiohttp\/web_exceptions.py","function":"HTTPException.__init__"},{"file":"aiohttp\/web_response.py","function":"StreamResponse._set_status"}]}],"references":null}