Skip to content

Backwards incompatibility with header parsing from 3.8.4 to 3.8.5 #7468

Closed
@mdegat01

Description

Describe the bug

I received home-assistant/supervisor#4454 in my project and the root cause turned out to be the update of aiohttp from 3.8.4 to 3.8.5. I was able to clearly reproduce it in a vanilla aiohttp server set up from the example here and having a script make a call providing a Host header. The same script works when the server is running on 3.8.4 and fails if I update to 3.8.5.

To Reproduce

  1. Install aiohttp 3.8.4 and run the demo server shown here
  2. Use the following script to make a call to it and receive the hello world response as expected
#!/bin/bash

SERVER=127.0.0.1
nc -i 1 ${SERVER} 8080 <<EOF
GET /world HTTP/1.1
Host: 127.0.0.1

EOF
  1. Stop the server, update to 3.8.5 and start it again
  2. Run the same script and receive this response instead:
HTTP/1.0 400 Bad Request
Content-Type: text/plain; charset=utf-8
Content-Length: 69
Date: Wed, 02 Aug 2023 19:28:52 GMT
Server: Python/3.11 aiohttp/3.8.5

Invalid header value char:

  b'Host: 127.0.0.1'
                   ^

Expected behavior

The same script should work on 3.8.4 and 3.8.5

Logs/tracebacks

Error handling request
Traceback (most recent call last):
  File "/Users/degam/.pyenv/versions/3.11.2/lib/python3.11/site-packages/aiohttp/web_protocol.py", line 332, in data_received
    messages, upgraded, tail = self._request_parser.feed_data(data)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "aiohttp/_http_parser.pyx", line 557, in aiohttp._http_parser.HttpParser.feed_data
aiohttp.http_exceptions.BadHttpMessage: 400, message:
  Invalid header value char:

    b'Host: 127.0.0.1'
                     ^

Python Version

$ python --version
Python 3.11.2

aiohttp Version

$ python -m pip show aiohttp
Name: aiohttp
Version: 3.8.5
Summary: Async http client/server framework (asyncio)
Home-page: https://github.com/aio-libs/aiohttp
Author:
Author-email:
License: Apache 2
Location: /Users/degam/.pyenv/versions/3.11.2/lib/python3.11/site-packages
Requires: aiosignal, async-timeout, attrs, charset-normalizer, frozenlist, multidict, yarl
Required-by:

multidict Version

$ python -m pip show multidict
Name: multidict
Version: 6.0.4
Summary: multidict implementation
Home-page: https://github.com/aio-libs/multidict
Author: Andrew Svetlov
Author-email: andrew.svetlov@gmail.com
License: Apache 2
Location: /Users/degam/.pyenv/versions/3.11.2/lib/python3.11/site-packages
Requires:
Required-by: aiohttp, yarl

yarl Version

$ python -m pip show yarl
Name: yarl
Version: 1.9.2
Summary: Yet another URL library
Home-page: https://github.com/aio-libs/yarl/
Author: Andrew Svetlov
Author-email: andrew.svetlov@gmail.com
License: Apache-2.0
Location: /Users/degam/.pyenv/versions/3.11.2/lib/python3.11/site-packages
Requires: idna, multidict
Required-by: aiohttp

OS

macOS

Also have been able to reproduce it on a variety of systems running the Home Assistant software which depends on aiohttp, as described in the issue I linked at the top.

Related component

Server

Additional context

No response

Code of Conduct

  • I agree to follow the aio-libs Code of Conduct

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions