Skip to content

HTTPS requests received on HTTP port show generic BadStatusLine exception #8065

@codyc1515

Description

@codyc1515

Describe the bug

When an HTTPS request is sent to the HTTP server port, a generic exception is thrown aiohttp.http_exceptions.BadStatusLine: 400, message: Invalid method encountered.

This has caused confusion for some Home Assistant users with a misconfigured reverse-proxy set-up. With this message, it is not always clear where the issue is. Example.

To Reproduce

Send a HTTPS request on the HTTP port.

Expected behavior

b'\x16\x03' appears to be a known HTTPS connection message. Given that we know this, a more descriptive error message (in lieu of Invalid method encountered) could be provided, such as Received HTTPS traffic on HTTP port.

Logs/tracebacks

Logger: aiohttp.server
Source: /usr/local/lib/python3.11/site-packages/aiohttp/web_protocol.py:421
First occurred: 8:32:09 AM (12 occurrences)
Last logged: 8:32:10 AM

Error handling request
Traceback (most recent call last):
  File "/usr/local/lib/python3.11/site-packages/aiohttp/web_protocol.py", line 350, 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.BadStatusLine: 400, message:
  Invalid method encountered:

    b'\x16\x03\x03\x01F\x01'
      ^

Python Version

3.11.6

aiohttp Version

3.9.1

multidict Version

6.0.4

yarl Version

1.9.4

OS

Home Assistant OS 11.4

Related component

Server

Additional context

No response

Code of Conduct

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions