Skip to content

Commit

Permalink
fixed trusted host parsing for always trust case
Browse files Browse the repository at this point in the history
  • Loading branch information
theyashl committed Oct 2, 2024
1 parent 6ffaaf7 commit b89353b
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
2 changes: 1 addition & 1 deletion tests/middleware/test_proxy_headers.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def make_httpx_client(
"::11.22.33.44", # This is a dual address
]
_TRUSTED_IPv6_NETWORKS = "2001:db8:abcd:0012::0/64"
_TRUSTED_LITERALS = "some-literal , unix:///foo/bar , /foo/bar"
_TRUSTED_LITERALS = "some-literal , unix:///foo/bar , /foo/bar, garba*gewith*"


@pytest.mark.parametrize(
Expand Down
3 changes: 2 additions & 1 deletion uvicorn/middleware/proxy_headers.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ class _TrustedHosts:
"""Container for trusted hosts and networks"""

def __init__(self, trusted_hosts: list[str] | str) -> None:
self.always_trust: bool = trusted_hosts == "*"
# gunicorn sends trusted hosts as a parsed list of strings while uvicorn forwards as is provided by input
self.always_trust: bool = trusted_hosts in ("*", ["*"])

self.trusted_literals: set[str] = set()
self.trusted_hosts: set[ipaddress.IPv4Address | ipaddress.IPv6Address] = set()
Expand Down

0 comments on commit b89353b

Please sign in to comment.