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

Ensure hassio does not do blocking I/O to get forwarded host #126885

Draft
wants to merge 2 commits into
base: dev
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions homeassistant/components/hassio/ingress.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,15 +253,17 @@ def _init_header(request: web.Request, token: str) -> CIMultiDict | dict[str, st
headers[hdrs.X_FORWARDED_FOR] = _forwarded_for_header(forward_for, peername[0])

# Set X-Forwarded-Host
if not (forward_host := request.headers.get(hdrs.X_FORWARDED_HOST)):
forward_host = request.host
headers[hdrs.X_FORWARDED_HOST] = forward_host
# Avoid calling request.host as it can fallback to doing blocking DNS lookups
# https://github.com/aio-libs/aiohttp/issues/9308
if forward_host := request.headers.get(
hdrs.X_FORWARDED_HOST
) or request.headers.get(hdrs.HOST):
headers[hdrs.X_FORWARDED_HOST] = forward_host
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we raise here if forward_host is None?

Can that ever happen


# Set X-Forwarded-Proto
forward_proto = request.headers.get(hdrs.X_FORWARDED_PROTO)
if not forward_proto:
forward_proto = request.scheme
headers[hdrs.X_FORWARDED_PROTO] = forward_proto
headers[hdrs.X_FORWARDED_PROTO] = (
request.headers.get(hdrs.X_FORWARDED_PROTO) or request.scheme
)

return headers

Expand Down