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

BaseRequest.url passes the host and port to URL.build when the port is included in the host header (non-default port) -- fixed in 3.10.7 #9307

Closed
bdraco opened this issue Sep 27, 2024 · 8 comments · Fixed by #9309
Labels

Comments

@bdraco
Copy link
Member

bdraco commented Sep 27, 2024

request.host can be 127.0.0.1:8123

url = URL.build(scheme=self.scheme, host=self.host)

yarl 1.13.0+ caught this because host is now validated via aio-libs/yarl#954

Pinning yarl to < 1.13.0 will also prevent the issue since the validation doesn't happen until that version.

@bdraco bdraco added the bug label Sep 27, 2024
@bdraco
Copy link
Member Author

bdraco commented Sep 27, 2024

Fix for Home Assistant is home-assistant/core#126882

@bdraco
Copy link
Member Author

bdraco commented Sep 27, 2024

This is messy because downstream expects the port in a lot of places to get the host

tests/components/http/test_forwarded.py:        assert request.host == f"{url.host}:{url.port}"
tests/components/http/test_forwarded.py:        assert request.host == f"{url.host}:{url.port}"
tests/components/http/test_forwarded.py:        assert request.host == f"{url.host}:{url.port}"
tests/components/http/test_forwarded.py:        assert request.host == f"{url.host}:{url.port}"
tests/components/http/test_forwarded.py:        assert request.host == f"{url.host}:{url.port}"
tests/components/http/test_forwarded.py:        assert request.host == f"{url.host}:{url.port}"
tests/components/http/test_forwarded.py:        assert request.host == "example.com"
tests/components/http/test_forwarded.py:        assert request.host == f"{url.host}:{url.port}"

Its also used for X-Forwarded-Host which is also a bit up for debate if it should include the port akka/akka-http#2191 details the struggle

@ffissore
Copy link

ffissore commented Sep 27, 2024

@Dreamsorcerer
Copy link
Member

I can't imagine we'll make another release without solving the issue, so updating the pin is not going to help.

@ffissore
Copy link

The problem is that, being yarl specified as a range, even those that don't update aiohttp will be affected.
I'm the last one demanding open source devs to "fix this now!", hence my suggestion to pin yarl to buy you time.

@bdraco
Copy link
Member Author

bdraco commented Sep 27, 2024

I think we’ll do a new release as soon as we can fix this one. I expect I’ll have time this weekend to make that happen.

@bdraco
Copy link
Member Author

bdraco commented Sep 27, 2024

#9318 will fix it for 3.10

The caveat emptor is the fix makes the url call a lot slower so if it matters for you when we ship the fix I'd update yarl to 1.13.1 once its available as it will shave off most of the performance slowdown , however if you aren't fetching the url on every request you'll probably never notice.

At this point everything is worked out and the hold up is waiting on GitHub CI runners

bdraco pushed a commit that referenced this issue Sep 27, 2024
…t when the host contains a port or IPv6 address (#9319)

Co-authored-by: J. Nick Koston <[email protected]>
fixes #9307
bdraco pushed a commit that referenced this issue Sep 27, 2024
…t when the host contains a port or IPv6 address (#9318)

Co-authored-by: J. Nick Koston <[email protected]>
fixes #9307
This was referenced Sep 27, 2024
@bdraco
Copy link
Member Author

bdraco commented Sep 27, 2024

I was hoping to release this fix today in 3.10.7 but docker registry is down so the release won't publish

https://www.dockerstatus.com/

@bdraco bdraco changed the title BaseRequest.url passes the host and port to URL.build when the port is included in the host header (non-default port) BaseRequest.url passes the host and port to URL.build when the port is included in the host header (non-default port) -- fixed in 3.10.7 Sep 27, 2024
@bdraco bdraco pinned this issue Sep 27, 2024
Javinator9889 added a commit to Javinator9889/pycones-discord-bot that referenced this issue Sep 28, 2024
@bdraco bdraco unpinned this issue Oct 2, 2024
thearperson added a commit to cloud-zeta/zeta-comfy that referenced this issue Oct 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants