Skip to content

Commit 6870201

Browse files
committed
fix(headers): enhance error handling for invalid Host header
1 parent ec33744 commit 6870201

2 files changed

Lines changed: 5 additions & 1 deletion

File tree

httoop/header/messaging.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,10 @@ def ip4address(self) -> str | None:
325325

326326
def sanitize(self) -> None:
327327
self.value = self.value.lower()
328-
self.host, self.port = self.HOSTPORT.match(self.value).groups()
328+
match = self.HOSTPORT.match(self.value)
329+
if not match:
330+
raise InvalidHeader(_('Invalid Host header: %s'), self.value)
331+
self.host, self.port = match.groups()
329332
if self.host.endswith(']') and self.host.startswith('['):
330333
self.host = self.host[1:-1]
331334
if self.port:

tests/headers/test_host_header.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ def _test_iter(header, host, port, headers):
5757

5858
@pytest.mark.parametrize('invalid', list(
5959
list((set('\x7F()<>@,;:/\\[\\]={} \t\\\\^"\'') | set(map(chr, range(0x1F)))) - set(';\n\x00')) + [
60+
', ',
6061
pytest.param(';', marks=pytest.mark.xfail), # FIXME
6162
pytest.param('\n', marks=pytest.mark.xfail), # FIXME
6263
pytest.param('\x00', marks=pytest.mark.xfail), # FIXME

0 commit comments

Comments
 (0)