Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Post sent to supervisor is invalid (unix2dos not working) #60

Open
mdegat01 opened this issue Aug 3, 2023 · 0 comments
Open

Post sent to supervisor is invalid (unix2dos not working) #60

mdegat01 opened this issue Aug 3, 2023 · 0 comments

Comments

@mdegat01
Copy link

mdegat01 commented Aug 3, 2023

Supervisor received home-assistant/supervisor#4454 from a user of this addon. After some digging the root cause is this bit of code:

nc -i 1 hassio 80 1>/dev/null <<< unix2dos<<EOF
POST /homeassistant/api/states/sensor.argon_one_addon_fan_speed HTTP/1.1
Authorization: Bearer ${SUPERVISOR_TOKEN}
Content-Length: $( echo -ne "${reqBody}" | wc -c )
${reqBody}
EOF

This is not working correctly. It is not actually replacing unix line endings with dos line endings in the HTTP data. I used the following script to confirm this:

#!/bin/bash

cat -e <<< unix2dos<<EOF
GET /world HTTP/1.1
Host: 127.0.0.1

EOF

Here is the result of this script:

# ./test
GET /world HTTP/1.1$
Host: 127.0.0.1$
$

Each line should end with ^M$ instead as is required for a proper HTTP request.

This worked in the past because aiohttp did not require proper line endings and accepted simple carriage returns. As of 3.8.5 of aiohttp this is no longer the case and all requests from this addon result in an error like this in the logs:

23-07-24 02:50:15 ERROR (MainThread) [aiohttp.server] Error handling request
Traceback (most recent call last):
  File "/usr/local/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'Authorization: Bearer *********************************************************************************************************410939e'
                                                                                                                                            ^

Please note that this has nothing to do with the Authorization header, that is simply the first header. The error will show up on whichever header is first regardless of the value.

Supervisor needs to update to aiohttp 3.8.5. I'm going to put the change in dev shortly and expect it to move to beta and stable within the next week or two. You'll have to correct this code or this addon will no longer work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant